Case Range Statement ..
bearophile
bearophileHUGS at lycos.com
Tue Jul 7 15:26:08 PDT 2009
Per: NG D
Soggetto: Re: Case Range Statement ..
Andrei Alexandrescu Wrote:
> That would be a fish. We want to learn fishing.
Tuples (as the tuples of Python, but represented with a different literal syntax, please) can be useful in really many situations, so hard-coding them in a language can be acceptable (that's why D has built-in dynamic arrays and associative arrays, for example).
Currently the tuples (the Record/record of my dlibs) of Phobos doesn't support "necessary" usages like:
for x,y in [(1,2), (3,4)]: ...
x, y, z = (1, 2, 3)
Or even, from Python 3+:
x, y, *z = (1, 2, 3, 4)
So it's a matter of balance, sometimes you need the flexibility (to learn fishing) and sometimes a handy and hard-coded solution is fine (because you need to eat a bowl of rice every day). You can add some built-in "defaults" too, with a nice short syntax for the programmer and a semantic that allows the compiler to digest them well (because very general features are often more hard for the compiler to compile them well, and require a more complex compiler. If you want a simple example, in D even foreach() is slower than for() when compiled with DMD, so I usually avoid foreach in the inner loops).
Regarding the "learn fishing", for example recently I have discussed about adding an OpBool to structs and classes, to allow to use if(x) when x is a BigInt (in the meantime I have found C# has such thing, even if they allow to define both true() and false(), I don't know why). There are other similar things that can be done in such regard.
Too much hard-coding leads to languages like Java, and too much flexibility leads to languages like Lisp where you can do anything, and where essentially every programmer does thigns in a different way, and this leads to the mess that's now Lisp. Python is less flexible than Lisp, you can't metaprogram it much, and both the semantic, the syntax and even the way people write source code is hard-coded and standard, the result is that today you can find a Python module to do anything, because re-using modules written by other people is easy, and it's easy to understand what's inside such modules. Here too you can see that's it's better to find a compromise between having a fish and learning fishing.
Bye,
bearophile
More information about the Digitalmars-d
mailing list