What were some of your biggest breakthroughs while learning D?
Dennis
dkorpel at gmail.com
Wed Jul 7 15:42:27 UTC 2021
On Tuesday, 6 July 2021 at 20:53:12 UTC, Dylan Graham wrote:
> [Inspiration from this r/C_Programming
> post](https://www.reddit.com/r/C_Programming/comments/oeoq82/what_were_some_of_your_biggest_breakthroughs/)
>
> 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. Their
`null` state is equivalent to their empty state, so you can
always safely insert elements or query their `.length`. In Java I
commonly wrote `null` 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 be `ArrayList!string` in D, but D
also allows `map!"a.x"` or `octal!10`. It took a while to get
accustomed with that idea, but it makes templates very useful for
other things than type polymorphism.
- [UFCS](https://dlang.org/spec/function.html#pseudo-member) is
not just syntactic sugar, but also enables certain generic code.
E.g. an input range can define an `enum empty`, a variable `bool
empty;`, or a function `bool 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](https://gitlens.amod.io/) 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.
More information about the Digitalmars-d
mailing list