Wed Oct 17 - Avoiding Code Smells by Walter Bright
Stanislav Blinov
stanislav.blinov at gmail.com
Wed Oct 31 00:50:09 UTC 2018
On Tuesday, 30 October 2018 at 22:22:33 UTC, H. S. Teoh wrote:
> Haha, I liked how Walter caught the audience's attention by
> using #include <windows.h> as the first example of a code
> smell. :-D
>
> Honestly, though, IMO this is also a code smell:
>
> import std.stdio;
>
> That is, if it appears at the top of every source file.
IMO, if it appears anywhere at all :)
Pop quiz. Try to answer without compiling, what do you think this
*should* print, and what *does* it print?
```
void main() {
static struct S {
int value;
this(this) {
++value;
}
}
writefln("%s", S.init);
}
```
In an imaginary ideal world, my answer to the first question
would've been "S(0)"... The language has `auto ref` and `shared`,
so it has all the capacity necessary to achieve that. Alas,
there's a "but" in there somewhere...
> As for encapsulating globals in a struct, I don't like it...
That's something one has to rigorously audit at all times.
Grouping of globals is something that just *must* be done, but
first and foremost having in mind access locality. The last thing
you want to do is sacrifice cache just for that one occasional
read or write (*cough* errno *cough*...)
More information about the Digitalmars-d
mailing list