News for hackers. Stuff that matters.
Re:Intent to stop using 'null' in my JS code by UncleMeat on Sunday November 01, 2020 @08:04AM (#24959205)
The Option type isn’t really something owned by functional programming. Union types exist just fine in imperative and even declarative programming.
Re:Intent to stop using 'null' in my JS code by c-cube on Sunday November 01, 2020 @10:07AM (#24959929)
The option type also prevents you from accessing the value if it's absent. Something a C union cannot do. Is there any example of options in an imperative language that would predate ML (which AFAIK introduced Some/None as the variants of option)?
Re:Intent to stop using 'null' in my JS code by UncleMeat on Sunday November 01, 2020 @12:44PM (#24961095)
C can’t do that. But imperative programming can. Nothing about type based pattern matching is constrained to FP.
Re:Intent to stop using 'null' in my JS code by phizy on Monday November 02, 2020 @11:00AM (#24969507)
Not that I'm disagreeing with you in any way, but it's worth recognizing that imperative languages typically do pattern matching and type constraining in a declarative manner. So one could make an argument that what you're saying is only true because imperative languages are not forbidden from employing FP. If a language uses declarative constructs, then it's not a wholly imperative language.
Re:Intent to stop using 'null' in my JS code by UncleMeat on Monday November 02, 2020 @07:42PM (#24975138)
I really don't think that FP should be able to take claim for this. Or, at the very least, I don't think the sort of evangelical FP should. Type pattern matching isn't all that different from virtual dispatch if you squint.

If the FP community wants to say that impure languages have been "doing FP" for decades then great! The religious war is over! We can happily have mixed paradigm languages and move on. But that's not what I'm seeing.

Re:Intent to stop using 'null' in my JS code by Spivak on Sunday November 01, 2020 @08:55AM (#24959510)
And the magic sauce that makes Option nice to use is the type checker that can force you to handle the None case.

I would go even further that even if the semantics are a little clunky (wrap/unwrap) any programming language can implement Option.

Re:Intent to stop using 'null' in my JS code by jolux on Sunday November 01, 2020 @09:43AM (#24959759)
True but you can’t restrict the type if your language is dynamic.