Live data from Hacker News

Null References: The Billion Dollar Mistake (2009) [video]

infoq.com

101–110 of 130 posts

Re: Null References: The Billion Dollar Mistake (2009) [video]

#101
post #70

Earlier quoted context omitted.

omg. I forgot about that. the one thing even worse than overloading the return domain.

Bit my company in the ass recently we uncovered a bug that was causing us to lose 20% of our data for a year. sqlite C libraries apparently still do this. The person who wrote the code was both not very good and had no idea that an error was even occuring.

Blame the lack of a proper linter instead of blaming the person who wrote the code?

Re: Null References: The Billion Dollar Mistake (2009) [video]

#102
post #22

Earlier quoted context omitted.

Yes, I suppose null references are only a problem if you are unable to write a conditional statement.

The problem with null references is you have to write those conditional statements everywhere, otherwise your program might crash. You generally know as the programmer which pointers you expect to be nullable and which should always be an object. But the compiler has no idea, so it can’t help make sure you have null checks in all the places you need them.

And what to do if null check fails? Call abort()?

Re: Null References: The Billion Dollar Mistake (2009) [video]

#103

Earlier quoted context omitted.

Yes, I suppose null references are only a problem if you are unable to write a conditional statement.

null references are a problem when: - null is a valid member of every type - there's no way to constrain a reference to only non-null members of the referenced type - the compiler allows dereferencing values of a nullable type Weirdly, all three are true of C, C++ and Java.

Null is a valid member of every type only in Java. C and C++ have value types.

Re: Null References: The Billion Dollar Mistake (2009) [video]

#104
post #80

Earlier quoted context omitted.

The problem is that you don't always have a legal state, especially at object creation. If you forbid illegal states you end up with fake objects taking the place of non-existent real ones. (What's Find supposed to return if it's not there??) In most cases it's better to blow up when you try to work with a null than to mistakenly work with something that takes the place of a null. A null is easier to detect and thus…

> If you forbid illegal states you end up with fake objects taking the place of non-existent real ones. You don't use a fake object, you use a real one of a different type. In the cases where what you want is "maybe this thing, maybe nothing" you can use an option/maybe type. In the cases where you want something else (e.g. "either this thing or an error message") you can use a type that represents that. > Yeah, well…

In C++ std::optional::value throws an std::bad_optional_access exception when the value is missing. How is this different from a NullPointerException?

Re: Null References: The Billion Dollar Mistake (2009) [video]

#105
post #70

Earlier quoted context omitted.

Bit my company in the ass recently we uncovered a bug that was causing us to lose 20% of our data for a year. sqlite C libraries apparently still do this. The person who wrote the code was both not very good and had no idea that an error was even occuring.

Blame the lack of a proper linter instead of blaming the person who wrote the code?

There's no linter that checks for a missing if statement and a missing error handler.

Re: Null References: The Billion Dollar Mistake (2009) [video]

#107
post #52

Earlier quoted context omitted.

> Thankfully governments have finally start paying attention regarding software liability. And we'll see a great slowdown in the software industry.

When people buy damaged goods, they ask for a refund, they don't expect to close and reopen the box and have the product reappear in perfect shape. The industry has miseducated them, and now it is finally happening, software products aren't a special snowflake. Digital stores with returns, consulting contracts with warranty clauses with fixes at the expense of provider, and naturally cyber security bills. Move fast a…

A strong, competitive free market naturally selects what people value the most. Because there is no black and white - most decisions are tradeoffs between cost, difficulty, time, convenience, safety, functionality, and so on.

Government regulations practically place an infinity price on selected characteristics. The result is less entrants in the market, less competition and naturally worse results across all parameters.

Re: Null References: The Billion Dollar Mistake (2009) [video]

#108
post #23

Earlier quoted context omitted.

Genuinely curious: why don't suggest that to WG14? (WG14) is the ISO workgroup which maintains the C specification.

And what would it achieve to "fix" this (without re-designing the rest of the language)? Every piece of code such as: int a[SIZE]; foo(a, SIZE); Would have to be rewritten to: int a[SIZE]; foo(&a[0], SIZE); And this additional noise would just make C harder to write for no reason. Rather than making C harder to write, just pick a different programming language.

A tool to do this transformation would not be hard.

Re: Null References: The Billion Dollar Mistake (2009) [video]

#109
post #53

Earlier quoted context omitted.

Something is lost - the array length. "Decays" is the correct word.

It is not correct. The array length is still there, what is happening is that you are implicitly asking for only a pointer to the first element of the array because of the context in which it is used. You did not ask for its length. The language has no way of passing an array itself by value. You could have asked for a pointer to the whole array but you didn't. When you are using an array in the context in which it i…

The length is there but you can't access it.

Re: Null References: The Billion Dollar Mistake (2009) [video]

#110

Earlier quoted context omitted.

I would go all-in and make arrays a distinct type , so the only way to create an array is with the [..] syntax, and forbid implicit type compatibility between arrays and pointers (which would discard the dimension part of the array type). An explicit conversion (cast) from pointer-to-array should require the dimension as part of the type. So &c on a char should produce char , and &c on a char[20] should produce char[…

Why not standardize something like std::span in C?

Lack of willigness.
Post reply on HN