Slashdot Mirror


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.

4 of 89 comments (clear)

  1. Re:Do away with them by murdocj · · Score: 3, Insightful

    And what do you do when something doesn't have a value? A new employee has been hired but you don't know his birthday? Plug in 1900-01-01? And check for that? Nulls serve a purpose.

  2. Re:This is stupid by ATMAvatar · · Score: 2

    Languages without nulls usually solve that problem with option types. Non-existent values get the value None (or some equivalent).

    --
    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety."
  3. Re:Do away with them by ShanghaiBill · · Score: 4, Funny

    We want a learning curve, not a learning wall.

    The problem with JavaScript is that the learning curve bends in the wrong direction.

  4. Re:Do away with them by rasmusbr · · Score: 3, Insightful

    Well the answer to your question is that Type.NULL is something that you define yourself or read about in the docs/code if it is coming from a dependency and use instead of NULL.

    There are times when having your software lie to you is better than having it do nothing. That's when you use Type.NULL.

    There are also times when having the software crash is better than having it lie. That's what NULL is for.

    Of course, if you and everyone on your team always writes correct code then it doesn't matter how you encode non-existent values. Your code will neither crash nor lie. The problem is that writing correct code is sometimes hard and often takes a lot of time.