On Mon, 15 Nov 2010 13:15:50 +0100 Per Ångström <d-n...@autark.se> wrote:
> On 2010-11-07 22:29, Tomek Sowiński wrote: > > This wraps up a thread from a few days ago. Pascal featured my D > > examples on his Scriptometer site. > > > > http://rigaux.org/language-study/scripting-language/ > > > > D comes 17th out of 28, so it's so-so for scripting. > > > I'm wondering whether the issue of D's or-expression, compared to that > of languages such as Perl and Ruby, has been discussed and dismissed. > > Personally, I was a bit disappointed to learn that D had such a > traditional or-expression, seeing how much it is willing to improve over > C/C++ in other areas. > > I think the following code summarizes the issue. I'm not a language > lawyer, so maybe the rules could be described more succinctly, but I > think you'll get my drift. I'm aware that with D being a typed and > compiled language, there has to a be a restriction that both > sub-expressions must be convertible to a common type, but I'm sure that > can be worked out somehow. > > string func(string s) > { > /++ > // A handy feature of many scripting languages, but not in D > // (in D, the type of the or-expression is bool): > // The type of the or-expression is the type of the first > // sub-expression that evaluates to true. > return s || "default"; > +/ > // The D equivalent, arguably more readable but also more verbose: > return s ? s : "default"; > } More verbose? Real programmers *want* to type 3 more characters when this makes code clearer! ;-) I read once that professional programmers produce about one dozen lines of effective code per day. Let us say they actually write three times more, by editing and/or recoding. How much time & effort is typing 36 lines of code? Maybe it's just me: I find nearly all complains about verbosity simply ridiculous. Programmers spend 49% of their time thinking about the model, 49% controlling their code, the rest typing. I *want* my language of choice to let me write clear code -- this is by far the most important task of a language designer, and cost in terms of number of characters is hardly even a side-issue. All major problems around software come from the extreme difficulty of understanding. Also: that logical expressions do not return logical values (read: bools) is arguably semantic mismatch (that necessarily hurts newcomers). I even find Lua's if x then doSomethingWith(x) borderline (here "x" is shortcut for "x != nil"). Denis -- -- -- -- -- -- -- vit esse estrany ☣ spir.wikidot.com