On Thursday, 13 October 2016 at 19:06:26 UTC, Karabuta wrote:
I assume the purpose for those demonstrations are to win the
interest of the user as to how easy and clean D code can be.
Then why;
// Round floating point numbers
import std.algorithm, std.conv, std.functional,
std.math, std.regex, std.stdio;
alias round = pipe!(to!real, std.math.round, to!string);
static reFloatingPoint = ctRegex!`[0-9]+\.[0-9]+`;
void main()
{
// Replace anything that looks like a real
// number with the rounded equivalent.
stdin
.byLine
.map!(l => l.replaceAll!(c => c.hit.round)
(reFloatingPoint))
.each!writeln;
}
How is a new visitor supposed to know "!" is for templates and
not some complicated syntax?
I think the point of the examples is to show D at its most
expressive/concise. The thing is that if you presented "Hello,
world!" a lot of people who come from other languages would
complain about how D doesn't seem to have chaining, mapping,
templates etc. and that the examples are too easy, blah blah.
We've had loads of discussions about this.
Also, it's good to show people how D code should look like right
from the start. Whenever I (have to) learn a new language, I look
immediately at the best practices trying to avoid awkward code.