> NULL is a value that is not a value. And that’s a problem. The problem isn't NULL, it's languages not enforcing the necessary checks for the "no data" condition. Option can still be NULL ("None" in rust), wrapping NULL in a struct doesn't provide any safety. The safety of Option wrapper types is from the other language features (like rust's "match") and a stricter compiler that forces the programmer to write the NU…
NULL: The worst mistake of computer science? (2015)
71–80 of 377 posts
Re: NULL: The worst mistake of computer science? (2015)
#72Earlier quoted context omitted.
Have you ever dealt with the Maybe(Haskell)/Option(F#) types? If not, then you don't understand what's wrong with NULL and how to easily avoid it without much work.
I find Maybe a bad idea. It forces me to write denormalized code when I know that something is not NULL. It's not possible to specify this knowledge as a data structure since data structures are static but context is dynamic. I much prefer the simple NULL sentinel that blows up like an assertion when I made a mistake. That said, there's not very often a need for NULL at all if you structure the code correctly.
Haskell, for instance, has the 'fromJust :: Maybe A -> A' function that allows you to do just that. It unpacks the Maybe typed value and throws a runtime error if it fails.
Re: NULL: The worst mistake of computer science? (2015)
#73Other candidates: - null terminated strings - machine dependent integer widths
Null-terminated strings are useful for buffering values of unknown length (e.g. copying from a network stream). Length-prefixed strings have issues of their own (e.g. what size length prefix to use, efficient encoding of variable-length integer prefixes, what happens if a length-prefixed string's calculated end-position is outside the process' memory space?)
That doesn't seem like a good example. The data arriving over the network arrives length-prefixed, because 0 is a legal byte value for arbitrary data. What do you then gain by throwing away your existing knowledge of the length?
Re: NULL: The worst mistake of computer science? (2015)
#74Earlier quoted context omitted.
I disagree. nullptr is directly convertable to a boolean 0: #include int main(int argc, char *argv[]) { printf("%d\n", nullptr == 0); return 0; }
1. You're comparing a null pointer literal with a null pointer constant. You're literally comparing two things guaranteed to be equal. How, exactly, is it surprising that they do? Did you even attempt to understand what I wrote? 2. The specific implementation you have on hand could use zero-valued null pointers, I'm telling you what the standard doesn't say, confirmed by the C FAQ: http://c-faq.com/null/varieties.htm…
Re: NULL: The worst mistake of computer science? (2015)
#75Progress, it's now a solved problem in modern languages like Rust, Swift or Kotlin See for example: https://kotlinlang.org/docs/reference/null-safety.html
Re: NULL: The worst mistake of computer science? (2015)
#76Earlier quoted context omitted.
I wonder why this gets downvoted - seems pretty reasonable to me...
It's a rather odd argument and it falls apart as soon as you ask about 0 Kelvin.
Huh? The whole point of Kelvins is that their zero point is an actual 0 value. That's why Kelvins are a unit and °C aren't.
Q: An object's temperature is 20°C. The object's temperature increases by 10%. What is the new temperature of the object?
A: 49°C.
Re: NULL: The worst mistake of computer science? (2015)
#77NULL is a convenient way to map singularities in your model of the problem. I have on a few occasions tried to write NULL-less code, and it adds a good bit of work. - model all possible states for a value - determine appropriate default actions for all types - meaningful place-holder values It's a good exercise, and I think more code should be written this way, but - as an Engineer I'm trying to model just enough of…
Really depends on the language. On Java / C#, it's hard to avoid null-checking a lot of stuff. In C++ you will never encounter a null std::string outside of code written by indian students learning on Turbo C++ 3.5. So you don't need to check for anything: if it's a value, it exists.
Re: NULL: The worst mistake of computer science? (2015)
#78Other candidates: - null terminated strings - machine dependent integer widths
Re: NULL: The worst mistake of computer science? (2015)
#79Nulls in strongly typed languages can get rather weird but from a C/C++ perspective it is the same as 0. nullptr is just a correctly casted 0.
This is only true in C, which is part of why C is less insane than C++. The two languages should not be conflated anymore.
Re: NULL: The worst mistake of computer science? (2015)
#80Earlier quoted context omitted.
It's a rather odd argument and it falls apart as soon as you ask about 0 Kelvin.
> it falls apart as soon as you ask about 0 Kelvin Huh? The whole point of Kelvins is that their zero point is an actual 0 value. That's why Kelvins are a unit and °C aren't. Q: An object's temperature is 20°C. The object's temperature increases by 10%. What is the new temperature of the object? A: 49°C.
Could I ask that you update Wikipedia with your discovery? Sadly the page appears to be erroneously using the word "unit" all over the place! https://en.wikipedia.org/wiki/Celsius
Also, NIST might benefit from your guidance: https://physics.nist.gov/cuu/Units/kelvin.html