Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
January 23, 2015 dlang.org redesign -- a better code sample for landing page | ||||
---|---|---|---|---|
| ||||
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. |
January 23, 2015 Re: dlang.org redesign -- a better code sample for landing page | ||||
---|---|---|---|---|
| ||||
Posted in reply to aldanor | 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!
|
January 23, 2015 Re: dlang.org redesign -- a better code sample for landing page | ||||
---|---|---|---|---|
| ||||
Posted in reply to aldanor | aldanor: > 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, lines.walklength seems better than lines.array.length, but you can also use a reduce with two functions (a sum and a counting one), scanning the input file only once. > oh wait, that and a lack of a "mean" function in the standard library... Yes, it's worth adding to Phobos. Bye, bearophile |
January 23, 2015 Re: dlang.org redesign -- a better code sample for landing page | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | > Yes, it's worth adding to Phobos. The issue: https://issues.dlang.org/show_bug.cgi?id=14034 Bye, bearophile |
January 26, 2015 Re: dlang.org redesign -- a better code sample for landing page | ||||
---|---|---|---|---|
| ||||
Posted in reply to aldanor | On Friday, 23 January 2015 at 13:55:04 UTC, aldanor wrote:
> auto lines = stdin.byLine.map!(line => line.length);
> writefln("Average line length: %.4f.", 1.0 * lines.sum / lines.array.length);
This won't work; `sum` already consumes the range, so there will be nothing left to compute the length from.
|
March 11, 2015 Re: dlang.org redesign -- a better code sample for landing page | ||||
---|---|---|---|---|
| ||||
Posted in reply to aldanor | 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. Further, I believe we should show off D in all its virtue at http://dlang.org/hash-map.html by addition to int* p = ("hello" in aa); if (p !is null) {} also include the even compacter if (auto p = "hello" in aa) {} along with if (const p = "hello" in aa) {} in the non-mutating case. |
Copyright © 1999-2021 by the D Language Foundation