On Tuesday, 5 August 2025 at 12:32:53 UTC, Brother Bill wrote:
I am in my learning curve for D as an experienced developer.
What has attracted me to D is the combination of features:
Design by Contract, Functional Programming, OOP, and more.
But I have been exploring the "weeds" and am curious if D is
only for rocket scientists or for regular programmers,
including as a first programming language.
It would be good to have a "style" document that showed the
"best practices" and "Do's and Don'ts" of good D programming.
D is invested in letting you program how you want, it is designed
to allow many different programming styles to co-exist. You can
go full C procedural style, or opt for a more functional style,
or use OO, or any combination of the three. None of these ways is
wrong or right.
My only word of advice is to consider using structs over classes
when passing around small amounts of data. A lot of D newbies use
classes for everything and ignore structs as if they don't exist.
Also check out
[`std.sumtype`](https://dlang.org/phobos/std_sumtype.html) if you
ever need tagged unions. It's really useful for a lot of stuff!
Should D be considered a language that should be learned in its
entirety?
For fun, yes. But if you get started and learn as you go then
you'll probably pick up the vast majority of it. And the stuff
you don't learn is probably not important to you. For example, if
you use OO a lot then you will probably barely touch D's
incredibly rich (and complex!) meta-programming.
Things I recommend familiarising yourself with are:
- the range interface & what ranges are (`front`, `popFront`,
`empty`)
- how strings work in D (they're arrays of `immutable char`,
where `char` is a UTF-8 code unit—not to be confused with a UTF-8
code point)
- what slices are (AKA 'dynamic arrays') and how/when mutating
GC-allocated slices causes them to be re-allocated
- other things you need to know to get your work done. If you
need to process data, like splitting by comma, sorting, etc. then
get familiar with `std.algorithm`. If your work requires lots of
maths then get familiar with `std.math`.
- a lot of Phobos functions are named a bit oddly, so sometimes
you have to rummage a little to find what you want, or you might
not realise that it's there.
Or should most developers stick to the "Safe D" subset?
If you are doing web development, yes.
If you are a low-level systems programmer or game developer, then
try to use `@safe` on as much of your code as possible, but you
will be calling `@system` functions in a lot of places to get
your job done. (e.g. kernel, SDL, etc.) I recommend checking out
the new
[`-preview=safer`](https://dlang.org/changelog/2.111.0.html#dmd.safer) as well if this interests you. And remember: if you misuse `@trusted`, then `@safe` will not save you.