LDC 1.11.0 beta
Mike Franklin
slavo5150 at yahoo.com
Thu Jul 5 10:57:17 UTC 2018
On Thursday, 5 July 2018 at 09:40:46 UTC, kinke wrote:
> I failed to see a benefit from being able to use classes with
> static members only (abuse as namespace?)
Yeah, pretty much, but also static inheritance. You can see the
pattern where I use it at
https://github.com/JinShil/stm32f42_discovery_demo/blob/c324bbf861cf258a819478481521528fca88dcb3/source/stm32f42/pwr.d#L24
It's for an ARM Cortex-M microcontroller. The structure, layout,
and memory locations of all memory-mapped IO registers (there are
100s of them) are all known at compile-time, so there's no need
for instances of anything. The static inheritance allows me to
reuse implementation code and also model the hierarchy according
to my mental model. After all that's one of the pillars of D,
modeling power.
Also, modeling them as static classes allows me to avoid the
memory layout mess in the linker script (Yuck!), as all the
memory addresses accompany the code itself. This also makes it
much, much easier to cross-reference the code to the
microcontroller's datasheet.
D's the only language I know of that can do this; it's not a
strength, not a weakness.
Mike
More information about the Digitalmars-d-announce
mailing list