On 08/30/2016 01:50 PM, John Burrton wrote: > This is why the example on the front page put me off for a long time :- > > stdin > .byLineCopy > .array > .sort!((a, b) => a > b) // descending order > .each!writeln; > > It makes the language look like some weird high level functional > language where you don't ask how it works and you shouldn't care how it > maps to the machine instructions and memory.
On a related point I think it is important to emphasize that such pipelines are cool not because they look high-level but also because with decent inlinining compiler (LDC/GDC) they generate as efficient code as for hand written C style implementation based on loop. There are plenty of languages that allow similar kind of high level programming but it usually comes with considerable overhead, contrary to D. Though this specific is not very good as it requires lot of allocation by the algorithm used. My favorite short snippet I commonly use when evangelizing D is splitting stdin by whitespaces: void main ( ) { import std.stdio, std.algorithm, std.uni; stdin .byLine // note that no byLineCopy is needed here .map!(line => line.splitter!isWhite) .joiner .each!writeln; } It is 100% Unicode correct, does not allocate any memory garbage and does exactly what told to do while being orders of magnitude more readable than any C style loop version one can come up with.
signature.asc
Description: OpenPGP digital signature