C is Brittle D is Plastic
Dennis
dkorpel at gmail.com
Mon Mar 30 14:23:35 UTC 2026
On Monday, 30 March 2026 at 12:31:37 UTC, matheus wrote:
> It's hard to
> compare with more flexible language today, so it's look like
> brittle, but at the same time is less complex than newer
> languages. Coming from C, sometimes I get lost reading new
> languages code and people making simple things more complex.
I can relate. When reading D code, code often looks
over-engineered. For example by aggressively deduplicating code
using a string mixin and CTFE instead of normal functions.
```D
mixin(TraceHook!("Tarr", "_d_arrayappendcTX"));
```
https://github.com/dlang/dmd/blob/371c7a5e3ef9c84d84bea869e2476ad050fbc916/druntime/src/core/internal/array/appending.d#L125
---
On the other hand, most C code bases I find come with their own
macro language to make up for C lacking the most basic
necessities. For example:
https://github.com/EpicGamesExt/raddebugger/blob/7021d6056a8058b34e7b026e728b5f44346be1a1/src/base/base_core.h#L412
```C
#define ArrayCount(a) (sizeof(a) / sizeof((a)[0]))
//...
typedef uint32_t U32;
typedef uint64_t U64;
//...
global U64 max_U64 = 0xffffffffffffffffull;
//...
#define DeferLoop(begin, end) for(int _i_ = ((begin), 0);
!_i_; _i_ += 1, (end))
#define DeferLoopChecked(begin, end) for(int _i_ = 2 * !(begin);
(_i_ == 2 ? ((end), 0) : !_i_); _i_ += 1, (end))
#define EachIndex(it, count) (U64 it = 0; it < (count); it += 1)
#define EachElement(it, array) (U64 it = 0; it <
ArrayCount(array); it += 1)
#define EachEnumVal(type, it) (type it = (type)0; it <
type##_COUNT; it = (type)(it+1))
#define EachNonZeroEnumVal(type, it) (type it = (type)1; it <
type##_COUNT; it = (type)(it+1))
#define EachInRange(it, range) (U64 it = (range).min; it <
(range).max; it += 1)
#define EachNode(it, T, first) (T *it = first; it != 0; it =
it->next)
#define EachBit(it, flags) (U64 (_i_) = (flags), it = (flags) &
-(flags); (_i_) != 0; (_i_) &= ((_i_) - 1), it = (flags) &
-(flags))
```
Not looking so simple anymore :-)
I'm glad D users at least use standard `.length`, `ulong.max` and
`foreach` instead of everyone inventing their own versions of
them.
More information about the Digitalmars-d
mailing list