TypeScript 2.0 Released (arstechnica.com)
An anonymous reader quotes a report from Ars Technica: Since its introduction, TypeScript has included new features to improve performance, enhance JavaScript compatibility, and extend the range of error checking that the TypeScript compiler performs. TypeScript 2.0 introduces a big step forward here by giving developers greater control over null values. null, used to denote (in some broad, hand-waving sense) that a variable holds no value at all, has been called the billion dollar mistake. Time and time again, programs trip up by not properly checking to see if a variable is null, and for good or ill, every mainstream programming language continues to support the null concept. TypeScript 2.0 brings a range of new features, but the biggest is control over these null values. With TypeScript 2.0, programmers can opt into a new behavior that by default prevents values from being null. With this option enabled, variables by default will be required to have a value and can't be set to null accidentally. This in turn allows the compiler to find other errors such as variables that are never initialized.
Why learn ONE shitty language, when you can learn TWO shitty languages -- Shitty language 1 compiles to shitty language 2, even better!
And wasn't the "billion dollar mistake" the one where somebody decided to make the stack grow upward instead of downward (or whichever way it goes, I can't remember).
"This in turn allows the compiler to find other errors such as variables that are never initialized."
Maybe a code smell but not an error, but surely this is more a function of an IDE rather than the compiler? Does it sing you lullabies while it holds your hand too?
I say get rid of nulls. They cause all kinds of problems and bloat up code. The few times you do "need" them can be handled other ways.
For example, check to make sure the data structure has values (elements) before running an "average" operation on it. If you don't check and there are no elements in it, then it should throw an error rather than produce a null.
Perhaps nulls are used in RDBMS because it's not easy to use conditionals or error handlers in queries to deal with an empty structure or no rows. Maybe have the Average function return two values (columns): one with the result value, and another column with a the count of elements averaged. If the count is zero, then the result value is invalid (not informative), but would be set to zero for consistency.
A potential problem with getting rid of nulls is that languages may have to support them for backward compatibility with existing stuff that produces nulls.
Table-ized A.I.
And yet, /* Report error condition */
if ((file_ptr = fopen("", "r")) == (FILE *) 0) {
}
is so useful. Of course, as a developer you have to be sufficiently disciplined to always check for such things. Perhaps that's why software development is considered a discipline rather than a rote occupation.
null !== undefined...
Many variables just don't have a valid default value. You gain nothing by forcing a meaningless value.
I mean, you wouldn't ask someone who is sleeping if they want a cup of tea.
(If you don't get this joke, you are better off.)
I wasn't sure what TypeScript is so I looked it up.
https://en.wikipedia.org/wiki/TypeScript
It's a language similar to JavaScript that allows you to optionally use types on variables. It "transcompiles" to JavaScript, so you can write programs in TypeScript and then they will run in standard web browsers that only support JavaScript.
It's possible to use standard JavaScript libraries with TypeScript, and further is it possible to write a header file that documents type information for those libraries. So it is possible to use TypeScript and take advantage of its type checking without needing to re-implement all the libraries.
lf(1): it's like ls(1) but sorts filenames by extension, tersely
...poorly implemented. Yet another MicroSoft-quality product. 'nuff said.
If you have a function that may return an object or may not for some reason, then it must return an Option or a Result (or something of a similar nature) and the caller has to explicitly test and handle what got returned.
Null is only supported for unsafe operations, e.g. calling out to some 3rd party library or a system API.
Are you allowed to simply cut-and-paste three paragraphs from Ars Technica to Slashdot? Even though you attribute it, it's still a copyright violation.
DuoCode?
I've been much happier keeping everything in C#.
every mainstream programming language continues to support the null concept.
Because you cannot do without. The computer cannot guess a value of a variable, so the default is always "Not Set" aka Null. Other languages use a Type.NULL or whatever, but it's just the same as Null. So, every language have a null concept.
http://www.mueller-public.de - My site http://www.anr-institute.com/ - Advanced Natural Research Institute
As I ranted about in the Java 8 story re lambda hype, the problem is our common languages have a crappy OOP model with "stiff" method definitions.
myFile = file.open(myPath) method openError {display("oh shit!");stop();}
(A "method" keyword may not be needed; it's shown for clarity here.)
Table-ized A.I.