News for hackers. Stuff that matters.
Re:What is wrong with NULL by geofft on Monday August 31, 2015 @05:17PM (#10149132)
It's worth noting that having a NULL, somewhere, is not so much a problem as forcing types to have a NULL. In this respect, e.g. Python and Rust both get it right: while Python has a None, and Rust has std::ptr::null(), an object that is a string cannot be any of those, because those are different types (NoneType and raw pointer, respectively). C's problem is that a string could be null, and there's no syntax for a non-null string.

Python's problem, meanwhile, is that any parameter could be any type. In C, you can pass NULL to a function expecting a non-null string. In Python, you can also pass 42, [], or the sqlalchemy module. None isn't special here. :)

Also, to quibble a bit: Rust's std::ptr::null() is just a raw pointer, and isn't actually usable in safe Rust. Actual safe pointer types are guaranteed non-null and you'd use Option<&T> to specify that they're nullable. Raw pointers cannot be dereferenced in safe Rust. It is true that std::ptr::null() is in Rust's standard library, but Foreign.Ptr.nullPtr is in Haskell's, and the purpose is the same (a special raw-pointer type only used for FFI purposes), so Rust isn't any worse than Haskell here.

Re:What is wrong with NULL by mcguire on Monday August 31, 2015 @05:23PM (#10149177)
"In Python, you can also pass 42, [], or the sqlalchemy module. None isn't special here..."

...the interpreter's environment, my left elbow, the magic unicorn that lives under my steps,...

Re:What is wrong with NULL by kazinator on Monday August 31, 2015 @05:32PM (#10149230)
Sorry, no. You can only pass a stable, property typed Python representation of your left elbow, or the magic unicorn, not the elbow or unicorn itself.
Re:What is wrong with NULL by foota on Monday August 31, 2015 @11:01PM (#10150476)
If it quacks like a unicorn then it's still a duck
Re:What is wrong with NULL by kazinator on Tuesday September 01, 2015 @12:42AM (#10150761)
Unicorn? Une corne?

Ceci n'est pas une corne.

Sometimes a horn is just a cigar.

Re:What is wrong with NULL by _Ogre on Monday August 31, 2015 @06:14PM (#10149422)
You can get a None type when you are expecting a String type... that is exactly the bug they are talking about. The fact that Python makes this problem BIGGER by allowing other types as well doesn't make it less bug prone.
Re:What is wrong with NULL by Latty on Tuesday September 01, 2015 @12:12PM (#10153434)
Except the language is designed around this - for example, trying to get a value from a dictionary in Python doesn't return `None` if it doesn't exist, it throws an exception.

I'm not saying static typing has no value, but there are benefits to dynamic typing, and Python embraces its dynamic typing and is designed around it, so none of the problems given in the article really apply.

Re:What is wrong with NULL by paulddraper on Monday August 31, 2015 @05:34PM (#10149232)
You make a good point. I removed the mention of std::ptr::null, since it really isn't really a NULL like other languages. Like you said, it's for FFI.
Re:What is wrong with NULL by bjz_ on Monday August 31, 2015 @06:15PM (#10149428)
Could you add a strikethrough and an addendum noting that it is like Haskell's nullPtr? It can be educational for others to see why you removed it.
Re:What is wrong with NULL by dradtke on Monday August 31, 2015 @05:31PM (#10149226)
I also think that Go did pretty well to fix NULL. It didn't get rid of it completely, but it (nil) is only valid for pointers and interfaces, so it's not possible to use it in place of a string, integer, etc. It's not as bulletproof as Rust or Haskell, but something as simple as disallowing nil strings can make a world of difference.
Re:What is wrong with NULL by tines on Monday August 31, 2015 @06:01PM (#10149349)
This is what C does, so I don't think Go deserves much credit for innovation on this point...
Re:What is wrong with NULL by azth on Tuesday September 01, 2015 @05:42PM (#10155962)
Go didn't really fix anything when it comes to NULL. The defense the Go authors gave to keep it around was laughable.