I'm writing more D code and I just... I can't stop finding things I love.
Like alias. It's like typedef or a macro replacement for a symbol but it's way better.
You can alias not just a TYPE, but also A VARIABLE. And not just a VARIABLE, but a structure's variable.
You can do:
alias x = system.document.file.is_ready;
Which allows you to do something I've never even thought of before. It feels like my brain just opened up a little.
Because I can now do this (and I'm going to extensively use it!):
1// Variable ABBREVIATIONS
4//member function of object_t (which has x, y, width, height)
6bool is_colliding_with(object_t obj)
8 alias x2 = obj.x;
9 alias y2 = obj.y;
10 alias width2 = obj.width; //clear note of dereferences
11 alias height2 = obj.height;
13 if( x > x2 + width2 - 1 || // Your eyes don't care about dereferences
14 y > y2 + height2 - 1 || // here, you care about the algorithm.
15 x2 > x + width - 1 ||
16 y2 > y + height - 1)
18 return false;
21 return true;
I mean, look how concise that code is. And your eyes notice the patterns of what's going on, instead of getting bottled down in large dereferencing chains.
And yes, I get we "should" be able to notice them, but this makes it much clearer. And clearer reduces human errors.
I also like D's explicit member override operator "override." You can't override a base class's members without explicitly adding that keyword to the overriding function. That's another simple language design feature that prevents further errors.