Timeline for If null is bad, why do modern languages implement it?
Current License: CC BY-SA 3.0
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 27, 2015 at 1:33 | comment | added | Jim Balter | "The technically superior solutions are all more unwieldy " -- No, they aren't; both Rust and Ceylon are counterexamples. | |
| May 3, 2014 at 0:57 | comment | added | cHao | Frankly, "technically correct" means little more than "does things how i think they should be done". | |
| May 2, 2014 at 23:02 | comment | added | anon | @delnan: That .unwrap() is exactly the kind of thing I'm talking about. I know plenty of programmers who dislike languages like Ruby because you have to go to the lengths of typing end. When writing Python it irritates me that I have to type += 1 rather than ++. The extra typing is, most likely, worth it in the majority of cases but it doesn't feel like it until you've got a really solid grasp of programming and, frankly, many programmers - even professional programmers - don't. | |
| May 2, 2014 at 22:34 | comment | added | user7043 | @mrpyo if file exists { open file } suffers from a race condition. The only reliable way to know if opening a file will succeed is to try opening it. | |
| May 2, 2014 at 20:58 | comment | added | David | @mrpyo Not all languages support option types either. | |
| May 2, 2014 at 20:45 | comment | added | Giorgio | "Because programming languages are generally designed to be practically useful rather than technically correct.": A technically correct language is more useful than one that is not: It gives you less chances of making mistakes. This is an example of the more general myth that in the real world you (always) need some kind of hack in order to do useful things. | |
| May 2, 2014 at 20:36 | comment | added | zduny | Also if in your case file might not exist you should write if (fileexists("joebloggs.txt")) { file = openfile("joebloggs.txt"; ... } and not use try ... catch therefore not using exceptions as flow control... | |
| May 2, 2014 at 20:28 | comment | added | zduny | @David Than you can use ?file (option type) which forces you to to check if value is there, and handle the opposite case. Choose the one you prefer, both solve potential problems. | |
| May 2, 2014 at 20:22 | comment | added | David | @mrpyo Not all languages support exceptions and/or exception handling (a la try/catch). And exceptions can be abused as well -- "exception as flow control" is a common anti-pattern. This scenario -- a file doesn't exist -- is AFAIK the most frequently cited example of that anti-pattern. It would appear you're replacing one bad practice with another. | |
| May 2, 2014 at 18:14 | comment | added | user7043 | Every option type I know of allows you to do the failing-on-null with a single short extra method call (Rust example: let file = something(...).unwrap()). Depending on your POV, it's an easy way to not handle errors or a succinct assertion that null cannot occur. The time wasted is minimal, and you save time in other places because you don't have to figure out whether something can be null. Another advantage (which may by itself be worth the extra call) is that you explicitly ignore the error case; when it fails there is little doubt what went wrong and where the fix needs to go. | |
| May 2, 2014 at 17:53 | comment | added | Martin Ba | +1 for "Because programming languages are generally designed to be practically useful rather than technically correct" | |
| May 2, 2014 at 17:41 | comment | added | zduny | And here you gave an example of what's exactly wrong with nulls. Properly implemented "openfile" function should throw an exception (for missing file) that would stop execution right there with exact explanation of what happened. Instead if it returns null it propagates further (to for line in file) and throws meaningless null reference exception, which is OK for such a simple program but causes real debugging problems in much more complex systems. If nulls didn't exist, designer of "openfile" wouldn't be able to make this mistake. | |
| May 2, 2014 at 17:27 | history | answered | anon | CC BY-SA 3.0 |