Why D is not popular enough?

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 30 07:05:07 PDT 2016


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.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20160830/21ea3cc3/attachment.sig>


More information about the Digitalmars-d mailing list