Live data from Hacker News

NULL: The worst mistake of computer science? (2015)

lucidchart.com

351–360 of 377 posts

Re: NULL: The worst mistake of computer science? (2015)

#351

That 'nothing' is inconvenient applies the same in mathematics with zero. Why do we have to have a number we can't divide by? What is 0 to the power of 0? It's a special case we always need to worry about. But its inclusion in the number system is not in question. And I remember my distress using a financial package being told that my unused zero value still MUST have a currency! My pocket is empty, how can it have a…

I recall having a friendly argument with a friend who insisted that 30°C was exactly twice as hot as 15°C.

Re: NULL: The worst mistake of computer science? (2015)

#352
post #239

Earlier quoted context omitted.

I'm sorry, I misunderstood you. These typedefs as I'm used to them do address cross-platform issues. Storage classes are "minutiae" however when all you want is just a straight up number. Python gives me an Integer type when I want a whole number, or a Float when I want to represent partials. I don't really care to be honest how that gets represented in memory in this case.

A float in Python is an implementation-specific size, just like C. So I'm really confused about using it as an example here. > Storage classes are "minutiae" however when all you want is just a straight up number. You can have a single "straight up number" and mention the bit width in the language spec. The mere act of writing it down doesn't force coders to deal with any more minutiae than they already had to deal w…

You can strongly object all you want, but when I'm writing code in python, or any other high-level language I don't care one jot about storage size.

Re: NULL: The worst mistake of computer science? (2015)

#353
post #351

That 'nothing' is inconvenient applies the same in mathematics with zero. Why do we have to have a number we can't divide by? What is 0 to the power of 0? It's a special case we always need to worry about. But its inclusion in the number system is not in question. And I remember my distress using a financial package being told that my unused zero value still MUST have a currency! My pocket is empty, how can it have a…

I recall having a friendly argument with a friend who insisted that 30°C was exactly twice as hot as 15°C.

It looks as if even in temperature zero is a bit problematic. https://en.m.wikipedia.org/wiki/Zero-point_energy

Re: NULL: The worst mistake of computer science? (2015)

#354

Earlier quoted context omitted.

That's a great example of MySQL creating a proprietary extension of ANSI SQL that does little more than deliberately mislead users.

According to https://en.wikipedia.org/wiki/Null_%28SQL%29#BOOLEAN_data_ty... NULL is the same as UNKNOWN. The standard also asserts that NULL and UNKNOWN "may be used interchangeably to mean exactly the same thing" In 20+ years of DB work, I have NEVER seen anyone use UNKNOWN. It is always NULL. Always .

Alright, I will withdraw my criticism of MySQL on this issue.

However....

> In 20+ years of DB work, I have NEVER seen anyone use UNKNOWN.

I mean, I've already shown where Microsoft does just that [0]. Oracle pretty clearly does the same [1] [2]. People don't use it because you can almost never refer to it directly. The language intentionally hides it. About the only place I know that you can is PostgreSQL [3], which supports the "boolean_expression IS UNKNOWN" predicate.

> The standard also asserts

I assume you've got the 2003 draft standard that's around [4]. I will use that because I don't see any more recent version of 9075-2 that's freely available.

Yes, the standard does say under 4.5 Boolean types:

> This specification does not make a distinction between the null value of the boolean data type and the truth value Unknown that is the result of an SQL , , or ; they may be used interchangeably to mean exactly the same thing.

However, that's in the context of describing the Boolean user data type, a.k.a., BOOLEAN. You can tell because 4.2 describes character strings (CHAR, VARCHAR, etc), 4.3 describes binary strings, 4.4 describes the numeric data type, 4.6 describes DATETIME, and 4.7 describes user-defined types.

The standard is not saying that UNKNOWN and NULL are the same. It's saying that the Boolean user data type can use NULL to represent UNKNOWN. It's saying that if you choose implement a BOOLEAN user data type, you can use NULL to represent UNKNOWN. If you choose to assign a boolean expression to a column, that is. Nevertheless, an SQL , , or has a value of True, False, or Unknown. This shown by looking at 6.34 :

   ::=
      TRUE
      | FALSE
      | UNKNOWN
Or by searching section 8 and seeing where every time they talk about one of the value expressions being the null value, then the predicate "is Unknown".

[0]: https://docs.microsoft.com/en-us/sql/t-sql/language-elements...

[1]: https://docs.oracle.com/cd/B19306_01/server.102/b14200/condi...

[2]: https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_e...

[3]: https://www.postgresql.org/docs/11/functions-comparison.html

[4]: http://www.wiscorp.com/sql_2003_standard.zip

Edit: Bit of cleanup.

Re: NULL: The worst mistake of computer science? (2015)

#355
post #334
post #273

Earlier quoted context omitted.

I'm not overselling zero values in Go. Simply try to envision the cascading consequences on the language if you removed the zero values; no existing Go code would work, and I think the language would need to shift so much that even hello world couldn't be automatically translated to such a language. All to prevent a single type of runtime error among many, one that Go developers are not complaining about the way that…

Nobody is arguing that Go should have algebraic types and ditch zero values, so I don't know why you're harping on this point. Now -- it would be somewhat nice because errors would be much more reasonable to handle (the new "check" proposal is okay but still quite flawed) but you're right that it would either be far too complicated or old code wouldn't work anymore. Go has already made it's bed when it comes to nil v…

I've had I believe a single NPE in Go in production for three years. It's a blip on the radar. If you are testing your code, how do you even get an NPE in production? Seriously, it should be rare. I've actually had more trouble with channels than pointers in Go.

Also, if the situation is really so bad.... How come no one cares? I saw no Go 2 proposal to fix this situation, just generics, less boilerplate for error handling. But nothing about nil pointers. It's not at the top of anyone's list. Generally, people feel comfortable with nil in Go in ways they don't in JS and C.

I will take that for fact even though certainly you disagree. So why do people feel more comfortable with nil in Go? Because nil is not an error.

In C and JS, there are cases where nil is treated as an error. For example, getElementById returns null when it finds nothing. If you designed this API in Go, you'd instead return nil, PLUS an error (or Perhaps, a bool, if no other possible errors exist.) You can argue semantics but in Go it's generally held that if you aren't returning what the user wanted you should return an error. Exceptions to that exist but probably mostly just string manipulation functions.

This convention is so strong, though, that it nearly eliminates nil pointer errors caused by edge cases. Most nil pointer errors you DO hit in Go are:

1. Set on nil map 2. Send on nil channel 3. Failing to check error

The thing is, if you are writing production code, and writing tests for your production code, this shouldn't even make it to your code repository. It's virtually a non issue.

Even better; in C and C++, when you hit a null pointer, you don't get an NPE. You get a segfault. Everything dies. Kaput. Go is obviously not alone in not having this issue, but it's surely worth noting that it doesn't.

Go is not going to die some day because it's "not safe enough" - it's absolutely safe enough to write reliable code. The difference is, writing reliable code in Go is easy because for the most part, all you have to do is follow conventions and unit test. Same cannot be said about C and JS where you will inevitably get blindsided by sharp edges.

If you are in a situation where you can't have runtime errors, it's a poor fit. I don't know personally any developers that are in this situation. If your code doesn't put lives on the line, its OK to have a runtime error. Most of your real outages will be due to other bugs, and probably more of then will be due to other people's bugs, natural disasters, human operator error, bad configuration pushes, etc.

If you really think Go NPEs are even a significant portion of Go reliability issues I'm gonna need more evidence.

Re: NULL: The worst mistake of computer science? (2015)

#356
post #352

Earlier quoted context omitted.

A float in Python is an implementation-specific size, just like C. So I'm really confused about using it as an example here. > Storage classes are "minutiae" however when all you want is just a straight up number. You can have a single "straight up number" and mention the bit width in the language spec. The mere act of writing it down doesn't force coders to deal with any more minutiae than they already had to deal w…

You can strongly object all you want, but when I'm writing code in python, or any other high-level language I don't care one jot about storage size.

You could apply that same "who cares?" attitude to the size of "double" in C. Whether you burden yourself with that knowledge is not a feature of the language. More "C coders" care because they're micro-optimizing, but it's no more needed in C than Python.

Also you named Java as being on the easy side and that has four different integer sizes...

Re: NULL: The worst mistake of computer science? (2015)

#357
post #352

Earlier quoted context omitted.

You can strongly object all you want, but when I'm writing code in python, or any other high-level language I don't care one jot about storage size.

You could apply that same "who cares?" attitude to the size of "double" in C. Whether you burden yourself with that knowledge is not a feature of the language. More "C coders" care because they're micro-optimizing, but it's no more needed in C than Python. Also you named Java as being on the easy side and that has four different integer sizes...

No ... not really.

Double doesn't behave like a whole number.

java only has a single int type, which is 32-bit regardless of machine architecture.

Re: NULL: The worst mistake of computer science? (2015)

#358
post #268

Earlier quoted context omitted.

> Your requirements break the abstraction not because the system is constrained, but because you're breaking the conceptual model that's the foundation of what you're trying to use. How so? Elsewhere in the thread it's claimed that the original relational model didn't have nulls, which is what I'd expect.

Relational algebra doesn't have nulls, but there's a difference between the mathematical theory and concepts and the reality of a relational system. As I mention elsewhere, Codd's own list of rules for a relational database [0] explicitly require nulls (see Rule 3). [0]: https://en.wikipedia.org/wiki/Codd%27s_12_rules

I don't see any entanglement with the rest of the rules, or with what makes a relational database a relational database. "A systemic way to represent missing and inapplicable information" may be necessary, but better alternatives to null are imaginable. A relational database without nulls sounds like an ML without exceptions: actually a pretty good idea.

Re: NULL: The worst mistake of computer science? (2015)

#359

Earlier quoted context omitted.

According to https://en.wikipedia.org/wiki/Null_%28SQL%29#BOOLEAN_data_ty... NULL is the same as UNKNOWN. The standard also asserts that NULL and UNKNOWN "may be used interchangeably to mean exactly the same thing" In 20+ years of DB work, I have NEVER seen anyone use UNKNOWN. It is always NULL. Always .

Alright, I will withdraw my criticism of MySQL on this issue. However.... > In 20+ years of DB work, I have NEVER seen anyone use UNKNOWN. I mean, I've already shown where Microsoft does just that [0]. Oracle pretty clearly does the same [1] [2]. People don't use it because you can almost never refer to it directly. The language intentionally hides it. About the only place I know that you can is PostgreSQL [3], which…

Ok, I will concede you are technically correct! However, I never seen a developer use "is unknown", even with Postgres. (I have been working with Postgres for over 15 years.) They always use "is null", which is, for all intents and purposes, the same thing from a developer perspective.

Re: NULL: The worst mistake of computer science? (2015)

#360
post #150

Earlier quoted context omitted.

Psst: I think the thingie you're referring to is called a 'monad': https://en.wikipedia.org/wiki/Monad_(functional_programming)

It isn't. There exists a common monad that solves this problem but a wrapper type like Option or Maybe need not be a monad. For example, `Nullable ` in C# is not a monad.

Aha! You're right. I misremembered this excellent blog series from Eric Lippert (a member of the c# design team): https://ericlippert.com/2013/02/25/monads-part-two/
Post reply on HN