x.sizeof vs typeid(x)

Matti Niemenmaa see_signature at for.real.address
Wed Feb 6 12:14:21 PST 2008


bearophile wrote:
> In this regard, one of the things I don't like of D syntax is that it allows
> to call functions without the final () if they take no arguments. It may be
> useful for properties, but when you see something like:
> 
> foo = bar;
> 
> Is it a function call? I am learning to always put the () there to be
> explicit:
> 
> foo = bar();
> 
> To improve code readability I think it may be better to remove this feature
> from the language (and later that may be used to simplify the object
> instantiation syntax).

The point is that it shouldn't matter. If you want to change it later to a 
function, you have to change all the points where you use it as well.

Canonical example with classes:

class Vector { Point a, b; double distance; this(...) {...} }

Now, if you want to save memory by changing distance to a method instead:

class Vector { Point a, b; this(...) {...} double distance() {...} }

You would have to change all uses of distance, whether inside or outside the 
class, to be distance() instead of distance.

Except that D does give us the ability to always use just distance and not care 
about whether it's a function or not.

-- 
E-mail address: matti.niemenmaa+news, domain is iki (DOT) fi



More information about the Digitalmars-d mailing list