billion-dollar mistake

back to index

13 results

pages: 47 words: 8,976

Learning TypeScript: Enhance Your Web Development Skills Using Type-Safe JavaScript
by Josh Goldberg
Published 29 Sep 2022

TypeScript is part of a surge of modern programming languages that utilizes strict null checking to fix the dreaded “billion dollar mistake”. The Billion Dollar Mistake The “billion dollar mistake” is a catchy industry term for many type systems allowing values such as null to be used in places that require a different type. In languages without strict null checking, code like example that assign null to a string is allowed: const firstName: string = null; If you’ve previously worked in a typed language such as C++ or Java that suffers from the billion dollar mistake, it may be surprising to you that some languages don’t allow such a thing.

In languages without strict null checking, code like example that assign null to a string is allowed: const firstName: string = null; If you’ve previously worked in a typed language such as C++ or Java that suffers from the billion dollar mistake, it may be surprising to you that some languages don’t allow such a thing. If you’re never worked in a language with the billion dollar mistake before, it may be surprising that some languages do allow such a thing in the first place! In the words of the developer who coined the phrase: I call it my billion-dollar mistake. It was the invention of the null reference in 1965… 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. Tony Hoare, 2009 The TypeScript compiler has an --strictNullChecks option to toggle whether strict null checking is enabled.

"Tony Hoare" : undefined; nameMaybe.toLowerCase(); Roughly speaking, disabling strict null checking adds | null | undefined to every type in your code, thereby allowing any variable to receive null or undefined. TypeScript best practice is generally to enable strict null checking. Doing so helps prevent crashes and eliminates the billion dollar mistake. With strict null checking enabled, TypeScript sees the potential crash in the code snippet: let nameMaybe = Math.random() ? "Tony Hoare" : undefined; nameMaybe.toLowerCase(); // Error: Object is possibly 'undefined'. Truthiness Narrowing TypeScript can also narrow a variable’s type from a truthiness check if only some of its potential values may be truthy.

pages: 448 words: 71,301

Programming Scala
by Unknown
Published 2 Jan 2010

Because Scala runs on the JVM and .NET and because it must interoperate with other libraries, Scala has to support null. Still, you should avoid using null in your code. Tony Hoare, who invented the null reference in 1965 while working on an objectoriented language called ALGOL W, called its invention his “billion dollar mistake” (see [Hoare2009]). Don’t contribute to that figure. So, how would you write a method that returns an Option? Here is a possible implementation of get that could be used by a concrete subclass of Map (Map.get itself is abstract). For a more sophisticated version, see the implementation of get in scala.collection.immutable.HashMap in the Scala library source code distribution: def get(key: A): Option[B] = { if (contains(key)) new Some(getValue(key)) else None } The contains method is also defined for Map.

For fixed sets of more complex, constant objects, use sealed case objects. Using Nulls Versus Options When we introduced Option in “Option, Some, and None: Avoiding nulls” on page 41, we briefly discussed how it encourages avoiding null references in your code, which Tony Hoare, who introduced the concept of null in 1965, called his “billion dollar mistake” (see [Hoare2009]). Scala has to support null, because null is supported on both the JVM and .NET and other libraries use null. In fact, null is used by some Scala libraries. What if null were not available? How would that change your designs? The Map API offers some useful examples. Consider these two Map methods: trait Map[A,+B] { ... def get(key: A) : Option[B] def getOrElse [B2 >: B](key : A, default : => B2) : B2 = ... ... } A map may not have a value for a particular key.

Finally, recall from “Partial Functions” on page 183 that the case user => ... statements, for example, cause the compiler to generate a PartialFunction to pass to flatMap and map, so no corresponding foo match {...} style wrappers are necessary. Using Options with for comprehensions eliminate the need for most “null/empty” checks. Exceptions and the Alternatives If nulls are the “billion dollar mistake” as we discussed in “Option, Some, and None: Avoiding nulls” on page 41, then what about exceptions? You can argue that nulls should never occur and you can design a language and libraries that never use them. However, exceptions have a legitimate place because they separate the concerns of normal program flow from “exceptional” program flow.

pages: 821 words: 178,631

The Rust Programming Language
by Steve Klabnik and Carol Nichols
Published 14 Jun 2018

Rust doesn’t have the null feature that many other languages have. Null is a value that means there is no value there. In languages with null, variables can always be in one of two states: null or not-null. In his 2009 presentation “Null References: The Billion Dollar Mistake,” Tony Hoare, the inventor of null, has this to say: I call it my billion dollar mistake. At that time, I was designing the first comprehensive type system for references in an object-oriented language. My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler.

Matches in Rust are exhaustive: we must exhaust every last possibility in order for the code to be valid. Especially in the case of Option<T>, when Rust prevents us from forgetting to explicitly handle the None case, it protects us from assuming that we have a value when we might have null, thus making the billion-dollar mistake discussed earlier. The _ Placeholder Rust also has a pattern we can use when we don’t want to list all possible values. For example, a u8 can have valid values of 0 through 255. If we only care about the values 1, 3, 5, and 7, we don’t want to have to list out 0, 2, 4, 6, 8, 9 all the way up to 255.

pages: 648 words: 183,275

The Rust Programming Language, 2nd Edition
by Steve Klabnik and Carol Nichols
Published 27 Feb 2023

Rust doesn’t have the null feature that many other languages have. Null is a value that means there is no value there. In languages with null, variables can always be in one of two states: null or not-null. In his 2009 presentation “Null References: The Billion Dollar Mistake,” Tony Hoare, the inventor of null, had this to say: I call it my billion-dollar mistake. At that time, I was designing the first comprehensive type system for references in an object-oriented language. My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler.

Matches in Rust are exhaustive: we must exhaust every last possibility in order for the code to be valid. Especially in the case of Option<T>, when Rust prevents us from forgetting to explicitly handle the None case, it protects us from assuming that we have a value when we might have null, thus making the billion-dollar mistake discussed earlier impossible. Catch-All Patterns and the _ Placeholder Using enums, we can also take special actions for a few particular values, but for all other values take one default action. Imagine we’re implementing a game where, if you roll a 3 on a dice roll, your player doesn’t move, but instead gets a new fancy hat.

pages: 629 words: 83,362

Programming TypeScript
by Boris Cherny
Published 16 Apr 2019

Then, when something really is null, you get a dreaded null pointer exception at runtime: function addDeliciousFish(pizza: Pizza) { return pizza.addAnchovies() // Uncaught TypeError: Cannot read } // property 'addAnchovies' of null // TypeScript lets this fly with strictNullChecks = false addDeliciousFish(null) null has been called the “billion dollar mistake” by the guy that introduced it in the 1960s. The problem with null is it’s something that most languages’ type systems can’t express and don’t check for; so when a programmer tries to do something with a variable that they thought was defined but it actually turns out to be null at runtime, the code throws a runtime exception!

pages: 316 words: 94,886

Decisive: How to Make Better Choices in Life and Work
by Chip Heath and Dan Heath
Published 26 Mar 2013

This is an insightful book for leaders in government, health care, public safety, and technology who need to prepare for the unexpected. Paul B. Carroll and Chunka Mui (2008). Billion Dollar Lessons: What You Can Learn from the Most Inexcusable Business Failures of the Last 25 Years. The authors, a journalist and a consultant, analyze a series of billion-dollar mistakes in the business world and share advice on how to avoid similar mistakes (on a smaller scale). If you’re involved in strategic decisions for your organization, this book will help you avoid major pitfalls. John Mullins and Randy Komisar (2009). Getting to Plan B: Breaking Through to a Better Business Model.

The Future of Money
by Bernard Lietaer
Published 28 Apr 2013

Specifically in our case, the consequences of a shift of control over money systems to various new players in society will be highlighted. 3. To work creatively with these discoveries, and use the clarity they inspire to shape a more desirable future. Scenarios are not academic exercises. The scenario-building process enabled Shell to forecast and prepare for the fall of the former Soviet Union, thereby avoiding billion-dollar mistakes in North Sea oil investments. Shell still updates its scenarios roughly every three years. This process also contributed to the 'South African miracle' of the peaceful transition after Apartheid (see sidebar). These same methods were further refined by the Global Business Network founded by several Shell alumni, and later published by Peter Schwartz.

pages: 406 words: 105,602

The Startup Way: Making Entrepreneurship a Fundamental Discipline of Every Enterprise
by Eric Ries
Published 15 Mar 2017

It’s why the Lean Startup movement is so focused on scientific “validated learning” as a unit of progress. 11. psychologytoday.com/​blog/​wired-success/​201511/​why-financial-incentives-don-t-improve-performance. 12. steveblank.com/​2010/​11/​01/​no-business-plan-survives-first-contact-with-a-customer-%E2%80%93-the-5-2-billion-dollar-mistake/. 13. Remarks at the National Defense Executive Reserve Conference, November 14, 1957; presidency.ucsb.edu/​ws/​?pid=10951. 14. Most boards are composed of representatives from three groups: insiders (founders and employees), investors, and independent directors. The most common configuration in my experience is 2/2/1 for a total of five directors.

pages: 424 words: 115,035

How Will Capitalism End?
by Wolfgang Streeck
Published 8 Nov 2016

By late July of the pre-election year of 2015, total campaign contributions already amounted to $388 million. ‘Small Pool of Rich Donors Dominates Election Giving’, New York Times, 1 August 2015, nytimes.com, last accessed 12 August 2015. For a broader account see David Cole, ‘The Supreme Court’s Billion-Dollar Mistake’, New York Review of Books, 19 January 2015: ‘Over the five years since [the Court’s Citizens United rule], super PACs have spent more than one billion dollars on federal election campaigns … About 60 percent of that billion dollars has come from just 195 people … The average donation over $200 of the ironically named Ending Spending, a conservative PAC, was $502,188 …’ For the 2016 election campaign, the brothers Charles G. and David H.

pages: 455 words: 133,322

The Facebook Effect
by David Kirkpatrick
Published 19 Nov 2010

The polished and well-liked son of a wealthy Brazilian business magnate, Saverin was an officer in the college Investment Club and a superb chess player who was known by his friends as a math genius. The two nineteen-year-olds agreed to invest $1,000 each. (Joe Green says Zuckerberg also approached him to be a business partner, but when Professor Green heard about it, he got “kind of pissed,” so Joe declined. Later he took to calling it, always with a pained laugh, his “billion-dollar mistake.”) On the afternoon of Wednesday, February 4, 2004, Zuckerberg clicked a link on his account with Manage.com. Thefacebook.com went live. Its home screen read: “Thefacebook is an online directory that connects people through social networks at colleges. We have opened up Thefacebook for popular consumption at Harvard University.

pages: 669 words: 210,153

Tools of Titans: The Tactics, Routines, and Habits of Billionaires, Icons, and World-Class Performers
by Timothy Ferriss
Published 6 Dec 2016

It was just huge and went up to $129M domestically, and I think worldwide it was $269M or something like that.” TF: This reminded me of the deal that George Lucas crafted for Star Wars, in which the studio effectively said, “Toys? Yeah, sure, whatever. You can have the toys.” That was a multi-billion-dollar mistake that gave Lucas infinite financing for life (an estimated 8,000,000,000+ units sold to date). When deal-making, ask yourself: Can I trade a short-term, incremental gain for a potential longer-term, game-changing upside? Is there an element here that might be far more valuable in 5 to 10 years (e.g., ebook rights 10 years ago)?

Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems
by Martin Kleppmann
Published 17 Apr 2017

Thompson: “XML Schema 1.1,” W3C Recommendation, May 2001. [12] Francis Galiegue, Kris Zyp, and Gary Court: “JSON Schema,” IETF InternetDraft, February 2013. [13] Yakov Shafranovich: “RFC 4180: Common Format and MIME Type for Comma-Separated Values (CSV) Files,” October 2005. [14] “MessagePack Specification,” msgpack.org. [15] Mark Slee, Aditya Agarwal, and Marc Kwiatkowski: “Thrift: Scalable CrossLanguage Services Implementation,” Facebook technical report, April 2007. [16] “Protocol Buffers Developer Guide,” Google, Inc., developers.google.com. [17] Igor Anishchenko: “Thrift vs Protocol Buffers vs Avro - Biased Comparison,” slideshare.net, September 17, 2012. [18] “A Matrix of the Features Each Individual Language Library Supports,” wiki.apache.org. [19] Martin Kleppmann: “Schema Evolution in Avro, Protocol Buffers and Thrift,” martin.kleppmann.com, December 5, 2012. [20] “Apache Avro 1.7.7 Documentation,” avro.apache.org, July 2014. [21] Doug Cutting, Chad Walters, Jim Kellerman, et al.: “[PROPOSAL] New Subpro‐ ject: Avro,” email thread on hadoop-general mailing list, mail-archives.apache.org, April 2009. [22] Tony Hoare: “Null References: The Billion Dollar Mistake,” at QCon London, March 2009. [23] Aditya Auradkar and Tom Quiggle: “Introducing Espresso—LinkedIn’s Hot New Distributed Document Store,” engineering.linkedin.com, January 21, 2015. [24] Jay Kreps: “Putting Apache Kafka to Use: A Practical Guide to Building a Stream Data Platform (Part 2),” blog.confluent.io, February 25, 2015. [25] Gwen Shapira: “The Problem of Managing Schemas,” radar.oreilly.com, Novem‐ ber 4, 2014. [26] “Apache Pig 0.14.0 Documentation,” pig.apache.org, November 2014. [27] John Larmouth: ASN.1 Complete.

pages: 1,237 words: 227,370

Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems
by Martin Kleppmann
Published 16 Mar 2017

[19] Martin Kleppmann: “Schema Evolution in Avro, Protocol Buffers and Thrift,” martin.kleppmann.com, December 5, 2012. [20] “Apache Avro 1.7.7 Documentation,” avro.apache.org, July 2014. [21] Doug Cutting, Chad Walters, Jim Kellerman, et al.: “[PROPOSAL] New Subproject: Avro,” email thread on hadoop-general mailing list, mail-archives.apache.org, April 2009. [22] Tony Hoare: “Null References: The Billion Dollar Mistake,” at QCon London, March 2009. [23] Aditya Auradkar and Tom Quiggle: “Introducing Espresso—LinkedIn’s Hot New Distributed Document Store,” engineering.linkedin.com, January 21, 2015. [24] Jay Kreps: “Putting Apache Kafka to Use: A Practical Guide to Building a Stream Data Platform (Part 2),” blog.confluent.io, February 25, 2015