Strict mode

bearophile bearophileHUGS at lycos.com
Thu Sep 24 12:31:01 PDT 2009


language_fan:

> Since your suggestion may add new syntactic constructs, can you somehow 
> show that making the language more strict also improves overall program 
> quality in some ways that unit testing and stronger type system cannot 
> achieve.

In that example I've shown the possible syntax of tuples, but that's a feature unrelated to strictness. So the only syntax I have suggested related to strictness is that "outer" keyword followed by the list of names that aren't arguments (with in/out/inout too).

There are several D features that can be removed and replaced by unit testing. Sometimes they are two ways to do the same thing, to specify semantics and restrict behaviours. The advantage of unit tests is that they are more flexible and allow to test more complex things. The advantage of various annotations is that they are usually shorter to write, they are more compiler-enforced and they can be more systematic. In my D programs I like to have both. In my D code for every 1 line of code I write about 2.5 lines of unit tests, about as in Python (where I don't add type annotations and accessibility annotations).

You can create a stronger type system, but you often have to give it more inputs. Otherwise you need complex automatic inference systems that increase compiler complexity a lot and compilation time too. So that "outer" can be seen as an annotation.

It's not easy to be sure "outer" improves code quality/readability. My experience in trying to translate and understand code written by other people tells me that global/outer variables make such translation/understanding quite harder. Having a language where such outer names must be listed looks like a compromise between a language like C/D with no limits in where it looks for names, and a language like Delight (a D resyntaxed, but with other differences and improvements) that forbids global/outer mutables at all.

Such "outer" can be useful if you translate some D code to other languages, because good software often gets translated. It's good to help future programmers to abandon their D programs and translate them to other languages :-)

Bye,
bearophile



More information about the Digitalmars-d mailing list