toString ugliness

bearophile bearophileHUGS at lycos.com
Sun Dec 7 14:49:22 PST 2008


Nick Sabalausky:
> I kind of like Ruby's requirement that accessing "this.whatever" *must* be 
> done like "@whatever" (with the "this." part not being needed). Omitting the 
> @ means you're talking about either a local identifier or a global one. I 
> don't know if that stuff applies to member functions as well or if it's just 
> member vars, but if it did apply to member funcs then that would certainly 
> solve the "finding the correct toString" issue. Of course, that would 
> probably be way too big of a syntax change for D, though.

In Ruby you also use @@ for class variables (similar to static attributes of classes in D).
I have often seen C++ code where the name of instance attributes are prefixed by "m_".
In D now and then I use "this.somename" to avoid name clashes (for example with argument variables) or to make more explicit that a variable isn't local.
Using a default prefix, like @ or $ to instance attributes in D2 code will make such code look a little ugly, but probably also more explicit too. (It's also short, shorter than "m_" and shorter than "this."). So I may end liking this syntax change.

Bye,
bearophile



More information about the Digitalmars-d mailing list