Associative Array - where's my error?

Jesse Phillips jessekphillips+D at gmail.com
Thu Apr 28 05:02:21 PDT 2011


bearophile Wrote:

> You have written a nice explanation of the situation, and indeed if you take care of using casts correctly, this situation is not bad. But in practice I think people will not use casts so carefully. This is why I have suggested a different design, essentially: the by line dups on default and doesn't do it on request (this difference is expressed with two different function names or a template argument boolean, etc). So when you don't know what you are doing the code works correctly.
> 
> Bye,
> bearophile

Thank you.

I think this just hides the issue. To fix the issue you would need byLine to return a string, since user code my still save and modify the returned value and store it in an AA.

Even then this is "fixing" one small area in Phobos. To really make this better you would need to change the semantics of cast to be what new users would "expect." However cast is supposed to be a very blunt tool, Java and C# have gone with changing the semantics and adding new features to provide some of the behavior. My friend recently discovered the 'as' keyword in C#. It was great because he could check for null instead of catching cast exceptions. D on the other hand left cast as a "dangerous" language feature and provided a "safe" library function.

So yes new users will get it wrong. I believe the correct solution is to educate at emphasize to!() over cast in examples.


More information about the Digitalmars-d-learn mailing list