Timeline for If null is bad, why do modern languages implement it?
Current License: CC BY-SA 3.0
9 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| May 2, 2014 at 20:37 | comment | added | Doval | @SteveEvers I can't take credit for it, but here you go. Replace Either = Left | Right with the ADT of your choice. The missing detail is that the subclasses need to be sealed inner classes, and the base class needs to have a private constructor. That ensures no one can add additional subclasses and break it. | |
| May 2, 2014 at 20:31 | comment | added | Steven Evers | @Doval Do you happen to have a link or something? I tried doing something similar and it turned out kinda nasty. Yours sounds like it might not be so bad. | |
| May 2, 2014 at 18:50 | comment | added | Doval | @SteveEvers It's possible to fake it using an abstract base class with private constructor, sealed inner classes, and a Match method that takes delegates as arguments. Then you pass lambda expressions to Match (bonus points for using named arguments) and Match calls the right one. | |
| May 2, 2014 at 18:25 | comment | added | Steven Evers | Option types go hand-in-hand with (statically verified) pattern matching, which C# unfortunately doesn't have. F# does though, and it's wonderful. | |
| May 2, 2014 at 13:30 | comment | added | Telastyn | @KarlBielefeldt - a good point. C# eventually put in option types for structs, and I wouldn't be surprised if they went that way if initial development weren't done later. | |
| May 2, 2014 at 13:28 | comment | added | Karl Bielefeldt | You make a good argument for allowing null, but you can still allow null without encouraging it. Scala is a good example of this. It can seamlessly interoperate with Java apis that use null, but you're encouraged to wrap it in an Option for use within Scala, which is as easy as val x = Option(possiblyNullReference). In practice, it doesn't take very long for people to see the benefits of an Option. | |
| May 2, 2014 at 13:06 | comment | added | Telastyn | @delnan - sorry, I am more familiar with C#, which does have this sort of interop. I rather assumed that many of the foundational Java libraries use JNI at the bottom as well. | |
| May 2, 2014 at 13:00 | comment | added | user7043 | The first paragraph doesn't make sense to me. Java does not have C interop in the shape you suggest (there's JNI but it already jumps through a dozen hoops for everything pertaining to references; plus it's rarely used in practice), same for other "modern" languages. | |
| May 2, 2014 at 12:33 | history | answered | Telastyn | CC BY-SA 3.0 |