On Tuesday, 6 July 2021 at 20:53:12 UTC, Dylan Graham wrote:
>Inspiration from this r/C_Programming post
What's something you learnt or realised, a habit you developed, something you read or project you worked on that helped accelerate your understanding and/or productivity in D?
-
Arrays and Associative Arrays never need
null
checks. Theirnull
state is equivalent to their empty state, so you can always safely insert elements or query their.length
. In Java I commonly wrotenull
checks at the start of functions, I rarely need those in D. -
Template arguments can be any compile-time known value. Coming from Java, I was used to seeing types in angle brackets
ArrayList<String>
which would beArrayList!string
in D, but D also allowsmap!"a.x"
oroctal!10
. It took a while to get accustomed with that idea, but it makes templates very useful for other things than type polymorphism. -
UFCS is not just syntactic sugar, but also enables certain generic code. E.g. an input range can define an
enum empty
, a variablebool empty;
, or a functionbool empty() {...}
, and then you can access.empty
on all of them. Other languages require parentheses for the function, or have the habit to capitalize constants ("EMPTY"). -
This is not specific to D, but the Git Lens VS Code extension is really useful when working on dmd/phobos/druntime. It immediately shows whether the code you're looking at was unchanged for 8 years or recently edited as part of a bug fix, and often helps to clear up why the code was written when there are no comments.