On Thursday, 28 April 2016 at 22:40:36 UTC, Timon Gehr wrote:
On 28.04.2016 05:55, Joakim wrote:
On Wednesday, 27 April 2016 at 18:38:17 UTC, Max Samukha wrote:
[...]
Syntax matters. Both for the ease of programmers reading it
and, as
we've seen with C++, the speed of the compiler.
I look at that code sample and I don't want to read code like
that. I
have the same feeling when I see template-heavy C++ code. It
is one of
the primary reasons I use D, because it reads very easily to
me.
Is it just because I'm used to C-style code? Is it purely
aesthetic? I
don't know, but there is a difference. Walter has talked
about an
aesthetic quality to D that he tries to optimize, and whatever
it is, it
comes through to me.
...
This is some D code I wrote:
template CreateBinderForDependent(string name, string
fun=lowerf(name)){
mixin(mixin(X!q{
template @(name)(string s, bool propErr = true)
if(s.split(",")[0].split(";").length==2){
enum ss = s.split(";");
enum var = ss[0];
enum spl = var.split(" ");
enum varn = strip(spl.length==1?var:spl[$-1]);
enum sss = ss[1].split(",");
enum e1 = sss[0];
enum er = sss[1..$].join(" , ");
enum @(name)=`
auto _@(name)_`~varn~`=`~e1~`.@(fun)(`~er~`);
if(auto d=_@(name)_`~varn~`.dependee){
static if(is(typeof(return) A:
Dependent!T,T)) return d.dependent!T;
else
mixin(`~(propErr?q{SemProp}:q{PropRetry})~`!q{sc=d.scope_;d.node});
}
`~(propErr?`assert(!_@(name)_`~varn~`.dependee,text("illegal
dependee ",_@(name)_`~varn~`.dependee.node,"
",_@(name)_`~varn~`.dependee.node.sstate));`:``)~`
static
if(!is(typeof(_@(name)_`~varn~`)==Dependent!void))`~var~`=_@(name)_`~varn~`.value;
`;
}
}));
}
Ugly code can be written in any language.
I agree, both about the D code sample and the principle, but
that's a very high bar. This is uncommon code, likely impossible
in most languages. Whereas the Rust code seems like something
you'd be more likely to run into, though I don't know what either
code sample does nor do I want to look deeper to find out. ;)
Is common code ugly? That's the threshold that must not be
crossed, and I believe Walter says the same above, in a different
way.