dlang.org redesign -- a better code sample for landing page

aldanor via Digitalmars-d digitalmars-d at puremagic.com
Fri Jan 23 05:55:03 PST 2015


On Friday, 23 January 2015 at 13:34:36 UTC, aldanor wrote:
> Does anyone find the example on the landing page particularly 
> exciting? (aside from it using an rdmd shebang) Anything that 
> makes you, as a programmer, think -- huh, that's interesting, 
> I'll need to check that out.
>
> It would be nice if it showcases more of D's strong parts, e.g. 
> type inference -- so an "auto" declaration could be used, maybe 
> assoc arrays or range stuff. Maybe even a little bit of 
> templating seeing how that's an integral part of D and how much 
> more natural meta code looks like as compared to many other 
> languages.
>
> This is a very important snippet of code as it serves as the 
> face of the front page of the language, I suggest we put some 
> thought into it and make it more interesting and elegant. Any 
> objections? Any takers?
>
> Another option is to have multiple code samples and rotate them 
> -- that's what Ruby does.

In fact, the current example (which is not the greatest of all) 
is essentially a one/two-liner, something along the lines of:

     auto lines = stdin.byLine.map!(line => line.length);
     writefln("Average line length: %.4f.", 1.0 * lines.sum / 
lines.array.length);

Ofc this is not the greatest piece of code ever and it's not 
lazy, but at the very least it showcases an auto declaration, a 
lambda, a formatted print, a template invocation and UFCS syntax, 
you get the point... oh wait, that and a lack of a "mean" 
function in the standard library...

I bet you will come up with much better ideas!


More information about the Digitalmars-d mailing list