Tango Style: Struct with no members?

Benji Smith dlanguage at benjismith.net
Sat Sep 6 14:58:51 PDT 2008


I've been reading a lot of the Tango source code lately, to educate 
myself on how the library works, and more generally, how to write good 
idiomatic D code.

As I've looked around, I've noticed a peculiar idiom popping up again 
and again that I've never seen or heard of before: struct definitions 
with no member fields, only functions. You can see it in 
"tango.time.WallClock" or "lib.common.tango.core.Runtime".

What's the rationale behind that?

I suppose it's something like a class with nothing but static methods. 
But then why not just define a module with only free functions? Is there 
a hidden benefit to implementing a pseudo-module as an empty struct?

Thanks!

--benji


More information about the Digitalmars-d-learn mailing list