Final by default?

Daniel Murphy yebbliesnospam at gmail.com
Fri Mar 14 04:21:47 PDT 2014


"Walter Bright"  wrote in message news:lfsv9r$263r$1 at digitalmars.com...

> Nope. It's a very pragmatic decision.

Errr...

> I've seen some of those hoops programmers have done to get that behavior 
> in D, and it resulted in just what I predicted - confusing bugs due to 
> wacky dependencies between modules.
>
> Bluntly, if your code requires more than version(Feature) you are doing it 
> wrong.
>
> I haven't yet seen an example of boolean version expressions that made the 
> code clearer, simpler, or more maintainable than version(Feature).

I agree!  Writing code this way pretty much always leads to better 
organisation and encourages separating things by feature instead of 
irrelevant things like host platform.

HOWEVER - forcing this on everybody all the time is not a good thing.  Not 
all code is for a long term or large project.

A similar example is the common rule that functions should be short and do 
one thing.  This is a great rule to keep things sane - but if the compiler 
errored when my functions got too long it would just be a huge pain in my 
ass.

Why don't we ban goto?  It can certainly be used to write confusing and 
unmaintainable code!  So can switch!  Operator overloading can be awful too!

Most of the time, D gives me all the power and lets me decide how I use it. 
If I wanted those choices to be taken away from me, I'd be using go.

> I've seen endless examples of boolean version expressions that are a rat's 
> nest of unmaintainable, buggy, confusing garbage. I've made a major effort 
> to remove all that garbage from dmd's source code, for example, and am 
> very pleased with the results. There's still some in druntime that I wish 
> to get refactored out.

Of course, DMD is still full of this.  DDMD has to use static if instead of 
version because of this.

> And yes, I'm pretty opinionated about this :-)

:-)  That's fine, and I think you're right about it.  But like "don't use 
goto" a compile error is the wrong place to enforce this. 



More information about the Digitalmars-d mailing list