|
Tony Hoare, the inventor of null, has gone on record calling it his ‘billion-dollar mistake’. So what should replace it? Maybe, at its core, is a construct that allows programmers to move null checks into the type system, so they can be enforced at compile-time. Instead of forgetting to deal with a null check and finding out with an exception at run-time, you forget to deal with a null check and find out at compile-time, before anyone else even sees it! And that’s not just some null checks, that’s all of them, guaranteed! Schrodinger's Type: Maybe it's there. Maybe it's not.
|
|
|
|
|
I disagree. Maybe is not better than NULL its more complex and will lead to more mistakes.
Worse than that this is yet another example of trying to 'fix it by changing the language'. Hasn't 15 years of failure from Microsoft made it clear enough THAT DOESN'T WORK.
You have to fix the problem, which is essentially the inability of most code to operate safely when given one or more empty parameters, not the language so as to hide empty parameters inside unions. As for the idea that this change means checks can be done at compile time, bilge, most NULLs arise from the lack of existence of user input, files, communication or some other artifact or item of data at runtime. Trying to ban these situations at compile time will simply lead to unhandled real world situations, commonly known as unhandled exceptions.
The one part of this that is correct is that the answer is to use the type system to create checked types that can throw when they evaluate to NULL. This can be done, I know because I've done it and definitely doesn't require any language level changes.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Matthew Faithfull wrote: Maybe is not better than NULL its more complex and will lead to more mistakes.
Just try a language that has no nulls and you'll change your mind quickly.
|
|
|
|
|
Hmm, that's what they said about languages with no types.
No thanks, I'll wait for version 3.5 or 4.0 of said language when they put NULLs back in to solve the problems they caused by having to write situation specific exception handlers almost but not quite identically all over the code.
The solution is a conceptually more advanced type system where types include declaratively what they can and cannot be converted to, what values they can and cannot be set to including NULL.
This doesn't need a new language just proper use of some of the better ones we have already. In other words a better understanding of what a type is amongst developers rather then a new language which further obscures the answer to that question by trying and inevitably failing to do it for you.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
Matthew Faithfull wrote: No thanks, I'll wait for version 3.5 or 4.0 of said language when they put NULLs back in to solve the problems they caused
Some of the languages without nulls are pretty old (ML, for instance) and I've never heard of any of them adding them. Nulls are simply a mistake - a billion dollar one[^], according to Tony Hoare who first introduced them:
"I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years. In recent years, a number of program analysers like PREfix and PREfast in Microsoft have been used to check references, and give warnings if there is a risk they may be non-null. More recent programming languages like Spec# have introduced declarations for non-null references. This is the solution, which I rejected in 1965."
|
|
|
|
|
Point me at a substantial open source project written in ML and I'll consider learning it, or Spec# or that matter.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|
|
Thanks, the link produces a 403 but I managed to find MLDonkey. It's been 15 years since I last looked at ML and it's still almost as ugly as SQL. The interesting thing to me is the apparent ability to integrate with something as concrete and 'real world' as GTK. That's real progress for a functional language, the idea that it might actually get used to write software rather than prove a point. I don't believe Miranda ever got that far. Maybe ML is worth another look but it will have to wait until after the elections, my brain is reading critical right now and all the sirens are going off. Time to sleep before tomorrows radio debate.
"The secret of happiness is freedom, and the secret of freedom, courage."
Thucydides (B.C. 460-400)
|
|
|
|
|