Timeline for Are null references really a bad thing?
Current License: CC BY-SA 3.0
13 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Jul 23, 2017 at 13:32 | history | edited | Deduplicator | CC BY-SA 3.0 |
added syntax-highlighting
|
Feb 11, 2016 at 16:29 | comment | added | kbolino |
@TimGoodman While division by zero may not be the best example for all numeric value types (IEEE 754 defines a result for division by zero), in cases where it would throw an exception, instead of having values of type T divided by other values of type T , you would limit the operation to values of type T divided by values of type NonZero<T> .
|
|
Feb 11, 2016 at 16:25 | comment | added | kbolino | @greenoldman It's not an exception, it's a compiler error. The first code snippet will compile (probably with a warning, since it's so obvious that the value is null) but will throw an exception at runtime. The second code snippet won't even compile. | |
Aug 26, 2014 at 18:32 | comment | added | Tikhon Jelvis |
@greenoldman: You would have some way to pattern match on the Maybe<A> value (ie do this when it has a value and that when it's null). Most languages can include this in a library with first-class functions and lambdas, and many languages have specific constructs for pattern-matching like this (ie switch on steroids).
|
|
Mar 12, 2014 at 22:42 | history | made wiki | Post Made Community Wiki by sea-rob | ||
May 22, 2013 at 13:31 | comment | added | greenoldman |
Your example does not make more sense (Maybe snippet) -- if you didn't notice you cannot call ANY method for foo -- so how this is progress of creating an object and not being able to use it? Even if you correct your code, you still don't make progress because you simply shift from one type of exception to another.
|
|
Oct 20, 2010 at 15:00 | comment | added | Matthieu M. | @FredOverflow: since the prelude is loaded by default, I would consider it "from scratch", that Haskell has a astonishing enough type system to allow this (and other) niceties to be defined with the general rules of the language is just a bonus :) | |
Oct 18, 2010 at 21:28 | comment | added | fredoverflow |
I'm not certain what you mean by "from scratch", but Maybe isn't built into the core language, its definition just happens to be in the standard prelude: data Maybe t = Nothing | Just t .
|
|
Oct 18, 2010 at 20:54 | comment | added | Matthieu M. | @Tim Goodman: you can include all the integer overflow/underflow here too... it's extremely unsettling that we are still plagued by such a thing. | |
Oct 18, 2010 at 20:15 | comment | added | Tim Goodman |
I included "arguably" for the people who will say "It makes perfect sense, it's just NaN !" :)
|
|
Oct 18, 2010 at 20:14 | comment | added | Tim Goodman | But surely lots of common programming constructs allow for nonsensical code, no? Division by zero is (arguably) nonsensical, but we still allow division, and hope the programmer remembers to check that the divisor is non-zero (or handle the exception). | |
Oct 18, 2010 at 19:17 | comment | added | Mark C | -1 for "leverage"! | |
Oct 18, 2010 at 19:13 | history | answered | Matthieu M. | CC BY-SA 2.5 |