Safer casts

Yigal Chripun yigal100 at gmail.com
Sun May 11 05:55:03 PDT 2008


you miss the point. it's not just a matter of syntax it's a matter of
better design strategy. yes, the syntax is a personal preference, but
that preference is used to emphasize the design goal of proper
encapsulation. Also, the template solution has the same power and all
those examples you gave can be accomplished in both ways. nothing stops
me from using:
array.sort(SwapStrategy.stable, dg);

also you can use functions instead of delegates too (although, I really
don't see what's the point of that besides maybe some questionable
performance issues)

D already has a feature to allow me to define a free function that takes
an array as first parameter, and use it as array.Fn(other params);
this notion will extended in D2. so the issue here is hardy the syntax
itself (as the two forms are interchangeable).

Also I do realize that since arrays are builtins they cannot implement
interfaces. IMO, the best solution is to make all type behave like
objects via syntax sugar. D is already half way there, since you can do
int.max and such.
My point is that I separate the interface exposed to the user ( the
syntax of D) from the implementation. in order to make "hello world" or
34 behave like objects you don't have to add overhead. 34 can remain the
same int it is in C. you just need to add to the compiler the ability to
treat those as objects, that's the whole beauty of a compiled language,
you can perform some transformations by the compiler so that numbers and
strings and other builtins will behave like objects without the added
cost you get in a language like Ruby for that functionality.

My mantra is: use the right tool for the job. That means that although
templates are a useful tool, I don't think it's the only tool D provides
that should be used to solve all problems.
IMO, this problem is better solved with polymorphism and proper
encapsulation.

--Yigal



More information about the Digitalmars-d mailing list