>NULL is a terrible design flaw, one that continues to cause constant, immeasurable pain Exaggeration much? Certainly not "the worst mistake of computer science". IPv4 is much worse, just for one example. NULL isn't even visible to end-users, many mistakes in CS are quite visible and really impact non-programmers' lives. NULL is just the color of the wallpaper in the engine room.
What is wrong with NULL
101–110 of 147 posts
Re: What is wrong with NULL
#102Earlier quoted context omitted.
NIL is objectively, unquestionably safer than a raw machine pointer that is null. It's a first class object with a type; a symbol with a name, and instance of the NULL class and so on. Of course, if you want to use NIL as a character string or floating-point value, there is an exception. That's your fault: you needed a way to indicate "I don't have a string here" or "I don't have a number", and you bungled the logic.
" Of course, if you want to use NIL as a character string or floating-point value, there is an exception. That's your fault: you needed a way to indicate "I don't have a string here" or "I don't have a number", and you bungled the logic. " And there's the rub: Just like NULL. And, in fact, that's the major problem with NULL. NIL is better than NULL, but not by much.
NIL is probably the best you can get once you realize that the empty state is unavoidable. My personal problem with this kind of rant is that is full of hate but lacking in general in alternatives to represent an empty state.
The author mention optional types as an alternative. That's fine for parameters but that doesn't cover when you need to have an empty reference.
Re: What is wrong with NULL
#103Here is what is wrong with Option. option.ifPresent(x -> System.out.println(x)); So instead of just checking to see if it is NULL you want me to create an instance of a specialized class that holds my variable that has a method that acts like an "if" statement that I need to pass an anonymous function to that receives the value I already have? Why not just do: x && System.out.println(x) or: System.out.println(x) if x…
Type safety is one benefit, but composability is an important benefit (as, you know, is extensively discussed in the source article.)
Re: What is wrong with NULL
#104NUL-terminated strings aren't that bad: * unlike Pascal-style strings, they can be usefully sliced, especially if you can modify them strtok-style. * unlike (ptr,len) "Modern C buffers"/Rust-style strings, references to them are pointer-sized, and they can be used as a serialization format. This makes the kind of application that is based on cutting pieces of a string and passing them around a good measure faster, es…
> unlike Pascal-style strings, they can be usefully sliced, especially if you can modify them strtok-style. Slicing Pascal-style strings is also easy and constant-time: just track the buffer, offset, and length of the slice of characters you want. Java used to do it implicitly whenever you called `substring`. > unlike (ptr,len) "Modern C buffers"/Rust-style strings, references to them are pointer-sized, and they can…
That's just coercing into a "modern C buffer" and slicing it. It has the disadvantage that coercion is not equality or subtyping - i.e. you will have to do lots of wrappings and unwrappings in mixed code.
> Every C method that takes a character buffer either a) has a corresponding length parameter or b) is avoided because of the security risks. In practice this means that C also stores the length information, just on the side instead of combined into a struct with the buffer.
You are surely talking about the buffer's capacity, not the string's length. These are distinct concepts. Anyway, functions that only read strings, and structs that only store them read-only, aren't interested in the capacity of any buffer.
Anyway, C strings aren't responsible for the fixed-size buffers of Cold War-era code - that code uses fixed-size buffers for everything. Their main claim to fame is their popularity in parsing code, which is edge-case- and bug-prone.
Re: What is wrong with NULL
#105NUL-terminated strings aren't that bad: * unlike Pascal-style strings, they can be usefully sliced, especially if you can modify them strtok-style. * unlike (ptr,len) "Modern C buffers"/Rust-style strings, references to them are pointer-sized, and they can be used as a serialization format. This makes the kind of application that is based on cutting pieces of a string and passing them around a good measure faster, es…
std::string isn't reference-counted in a conforming implementation (that doesn't do atomic ops just for fun).
Re: What is wrong with NULL
#106Here is what is wrong with Option. option.ifPresent(x -> System.out.println(x)); So instead of just checking to see if it is NULL you want me to create an instance of a specialized class that holds my variable that has a method that acts like an "if" statement that I need to pass an anonymous function to that receives the value I already have? Why not just do: x && System.out.println(x) or: System.out.println(x) if x…
Re: What is wrong with NULL
#107>NULL is a terrible design flaw, one that continues to cause constant, immeasurable pain Exaggeration much? Certainly not "the worst mistake of computer science". IPv4 is much worse, just for one example. NULL isn't even visible to end-users, many mistakes in CS are quite visible and really impact non-programmers' lives. NULL is just the color of the wallpaper in the engine room.
In the same way HIV isn't visible; sure, the cause isn't visible to most people, but the adverse effects are.
Re: What is wrong with NULL
#108 WITH NullCTE AS
(SELECT a.*
FROM
(VALUES (NULL), (1), (2)) a (Number)
)
,One AS
(SELECT Number = 1)
SELECT *
FROM NullCTE nc
WHERE nc.Number NOT IN
(SELECT Number
FROM One)
UNION
SELECT *
FROM NullCTE nc
WHERE nc.Number IN
(SELECT Number
FROM One)
Running this will give you back a two-row table, containing 1 and 2, but the NULL is excluded from both WHERE conditions.The naive expectation is that the combination of a condition and the NOT of that condition cover all possible circumstances.
Re: What is wrong with NULL
#109Earlier quoted context omitted.
Not completely. non-nullable by default is nice, ignoring possible nulls is nice, but Haskell's Maybe still suffers from premature generality by conflating all forms of absence. A 'Maybe T' is fundamentally, context-sensitively, not equivalent to any other 'Maybe T' in the same way all 'T's are. This is bad. edit: carsongross beat me to what I'm talking about with a better explanation: https://news.ycombinator.com/it…
Can't you just handle this with something like `Either ErrCode T`? (And if not, please do explain why!)
Re: What is wrong with NULL
#110lol the null / undefined issue in javascript is further exacerbated by the fact there is no int type and everything is just a "number".... yet the number 0 is still treated the same as null/undefined by js special forms like "if" and "==". This is particularly hilarious because it leads to some null-check bugs like: if ( user.getScrollPosition() ) { whatever(); } else { die(); } 99% of the time, the code would be fin…
user.getScrollPostion() != undefined
or in CoffeeScript just use:
user.getScrollPosition()?
Arrays have various types of ints and floats of various word lengths and signs.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Type...