Final by default?

bearophile bearophileHUGS at lycos.com
Wed Mar 12 16:51:40 PDT 2014


Walter Bright:

> The argument for final by default, as eloquently expressed by 
> Manu, is a good one. Even Andrei agrees with it (!).
>
> The trouble, however, was illuminated most recently by the 
> std.json regression that broke existing code. The breakage 
> wasn't even intentional; it was a mistake.

Making final by default is a intentional and planned change, 
first you introduce "virtual" (it's already present in dmd 
2.066alpha), then you give a warning, and then you deprecate 
things, and then later you generate errors. This gives time to 
people to fix the code. Even languages far older and far more 
widespread than D change, like the nullptr of C++ that replaces 
the 0 as null pointer. People that use D for production code 
should expect to give a look at the changelog every time a D 
version comes out and fix the code accordingly. I am keeping a 
large amount of D2 code updated and introducing the usage of 
"virtual" in my code will take an amount of time that is little 
compared to actually writing new code, refactoring code for other 
purposes, fixing bugs, etc. I don't think you can write D code 
today and expect it to work perfectly years from now. You have to 
keep your code updated or keep using the same compiler version.

We can introduce ways to better manage the change, like the 
"deprecate" keyword, introducing a refactoring tool like the one 
in Go language, and keep some backwards incompatible changes that 
the community and you regard as sufficiently important (like 
deprecating some usages of the comma operator, etc).

I don't even care much about "final by default".

Also in D there are several features that are "going to be 
deprecated". Like old style operator overloading, the built-in 
sort, and more and more. Keeping such things in the language for 
years without even a deprecation messages is bad. In the D.learn 
newsgroup I keep saying to people "don't use that, it's going to 
be deprecated". People use those things and if someday they will 
get actually deprecated they will cause a damage, perhaps 
comparable to introducing final by default. So please add 
deprecation messages now for all things that should be deprecated.

Bye,
bearophile


More information about the Digitalmars-d mailing list