Timeline for Are null references really a bad thing?
Current License: CC BY-SA 3.0
15 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 27, 2021 at 14:04 | comment | added | Domi | C# 8 introduced nullable reference types. It's an opt-in mechanism to make reference types non-nullable by default, unless they are declared nullable. | |
Jul 23, 2017 at 13:31 | history | edited | Deduplicator | CC BY-SA 3.0 |
added syntax-highlighting
|
Apr 22, 2017 at 9:34 | comment | added | r0estir0bbe | As a concrete example, Kotlin implements exactly this. See also Null Safety in Kotlin. | |
Jul 29, 2014 at 17:57 | comment | added | radarbob | Nulls aren't so bad, they're just coded that way | |
May 2, 2014 at 16:17 | comment | added | Yogu |
@SimonBarker: you can be sure if Customer.FirstName is of type String (as opposed to String? ). That's the real benefit - only variables/properties that have a meaningful nothing value should be declared as nullable.
|
|
Mar 13, 2014 at 12:12 | comment | added | Simon B | There's still an issue with this example. Just because you know that c is not null, you still can't be sure that c.FirstName is not null and c.LastName is not null. | |
Mar 12, 2014 at 22:42 | history | made wiki | Post Made Community Wiki by sea-rob | ||
Aug 22, 2011 at 18:38 | comment | added | Tyler |
This looks like what Haskell calls a Maybe -- A Maybe Customer is either Just c (where c is a Customer ) or Nothing . In other languages, it's called Option -- see some of the other answers on this question.
|
|
Oct 18, 2010 at 23:36 | history | edited | Note to self - think of a name | CC BY-SA 2.5 |
oops silly me
|
Oct 18, 2010 at 23:31 | comment | added | Note to self - think of a name |
@Tim - Yes, documentation is a huge benefit of this approach. It's not just objects -- imagine a String.Find method which returns int? -- that's also much easier to use as well.
|
|
Oct 18, 2010 at 23:15 | comment | added | Dean Harding | You're right that it's not the null object pattern, though. | |
Oct 18, 2010 at 23:12 | comment | added | Dean Harding | @JBRWilkinson: This is just a cooked-up example to show the idea, not an example of an actual implementation. I actually think it's a pretty neat idea. | |
Oct 18, 2010 at 21:55 | comment | added | JBRWilkinson | What language is this? Objects are nullable by design - no such thing as a 'Nullable<Object>', which ? is a shorthand for. Also, The Null Object Pattern is something completely different - please check GoF book or Huperniketes' answer. | |
Oct 18, 2010 at 19:37 | comment | added | Tim Goodman |
Wow, that's pretty cool. In addition to catching a lot more errors at compile time, it spares me from having to check the documentation to figure out whether GetByLastName returns null if not found (as opposed to throwing an exception) -- I can just see if it returns Customer? or Customer .
|
|
Oct 18, 2010 at 19:06 | history | answered | Note to self - think of a name | CC BY-SA 2.5 |