foreach thoughts

Jakob Ovrum jakobovrum at gmail.com
Tue Jan 14 01:06:08 PST 2014


On Tuesday, 14 January 2014 at 08:43:37 UTC, Ola Fosheim Grøstad 
wrote:
> On Tuesday, 14 January 2014 at 08:36:53 UTC, Jakob Ovrum wrote:
>> You'll have to get used to the exclamation mark, otherwise 
>> you'll never be able to fully appreciate D's generic 
>> programming. I quite like it - I don't think there's anything 
>> objectively ugly about it.
>
> You subjectively think that there is nothing objectively ugly 
> about it? :-) It is objectively ugly because "!" implies a 
> boolean expression, but that is off-topic.

This argument is stupid. It's the same argument as the famous 
"Yeah, well, that's just, like, your opinion, man", or the 
"please put `I think...` in front of all your sentences!" 
argument.

The burden of proof is on the person who first claims it's 
deficient. Saying that I can't think of anything objectively 
wrong with it serves the purpose of inviting Manu to provide some 
kind of argument, as I can't think of anything *obviously* wrong 
about it that goes unsaid.

It's common to overload tokens in programming languages, and it's 
usually only a problem for beginners who aren't used to the 
particular language's choice of overloads yet (Ruby is good 
example of a language with rather extreme token reuse) - humans 
are pretty good at context-sensitive parsing. From a 
character-by-character perspective it's particularly common, with 
the bitwise shift operators having nothing to do with 
comparisons, bitwise xor having nothing to do with exponents etc.

Regardless of whether binary ! is "ugly" or not, it's still 
better than introducing language features left and right to avoid 
templates, and it's still better than C++'s template 
instantiation syntax :)

> I agree that chaining of filters and sorting rules is a good 
> solution, provided that you have a high level optimizer capable 
> of transforming the chain into something optimal. You basically 
> need some sort of term-rewriting.

LDC and GDC are capable of unravelling the (fairly thin) 
abstraction. All it requires is the ability to inline direct 
function calls to small functions - the aforementioned compilers 
always have this capability for templated functions.

DMD is hit and miss, but I think there was a recent improvement 
to its inliner... luckily this is still the domain of 
micro-optimization.


More information about the Digitalmars-d mailing list