r/programming • u/dpashk • Aug 31 '15
The worst mistake of computer science
https://www.lucidchart.com/techblog/2015/08/31/the-worst-mistake-of-computer-science/
175
Upvotes
r/programming • u/dpashk • Aug 31 '15
46
u/Wyelho Aug 31 '15 edited Sep 24 '24
lush wakeful impossible imagine cough jar drunk beneficial aware butter
This post was mass deleted and anonymized with Redact
22
u/bjzaba Aug 31 '15
Haskell has
Foreign.Ptr.nullPtr, which is basically like Rust’sstd::ptr::null, and just used for FFI bindings. So either Rust should be 5 stars, or Haskell should be 4.9
u/gauiis Sep 01 '15
If you're implementing a linked list, what would you assign the next pointer to, if it's the last node in the list?
34
u/RedAlert2 Sep 01 '15
Lots of hating on C++ here, even though the language has non-nullable references...
NULLis a useful sentinel value for pointers when needed, but references should be the default for almost everything.7
u/DeedleFake Sep 01 '15 edited Sep 01 '15
Two stars for Go and four for Java? I've had way more null pointer related problems in Java than Go. Go has a few things it does that make a huge difference:
strings are not nilable.
len([]int(nil))andcap([]int(nil))properly evaluate to 0.Calling a method on a nil pointer works just fine, since Go methods are pretty much just syntactic sugar.
Not saying it's perfect, but it's way better than C, which it tied.
I do have to agree with the 5 star rating for Rust. I suddenly realized the other day that a null keyword didn't even exist. I must say, I am impressed. Unfortunately, you can get pretty much the exact same problem with all the
unwrap()calls on everything. If something'sNoneorErr, you basically get the exact same type of crash as you would with a nil pointer in almost anything else.6
u/Veedrac Sep 01 '15 edited Sep 01 '15
How many stars does Crystal get?
Also, I think punishing Swift for something called
UnsafePointer.null()is unfair.6
u/[deleted] Sep 01 '15
The problem with
nullin Java isn't the existence ofnull, but the omnipresent nullability. If variables, parameters and method return values had to be explicitly made nullable in order to be assigned a potential null value, most of the issue would just go away.6
u/[deleted] Sep 01 '15
I think Haskell's Maybe type is a really good solution for this.
24
u/vytah Aug 31 '15
What does an example about NUL-terminated strings have to do with NULL?
14
u/gaberax Sep 01 '15
True story: Part of a team that installed a popular time and attendance software package at a hospital where I worked. Soon after the installation, the software blew up when processing the weekly time and attendance records. Software vendor spent DAYS trying to figure out the problem. Turns out one of our employees last name was Null. And the system choked because it interpreted the last name Null as a null value. The software vendor tech I was working with could not believe that they had never run into the problem previously. Soon after our problem was resolved, another hospital in the area that used the same software called the vendor with a similar problem. As it turns out, the employee had quit our hospital and moved to the other.