3 ms·
Readable functional programming imo really hinges on some essential basic language primitives. Those are sum types, pattern matching, and restricting mutability
by the_duke 7y ago
Readable functional programming imo really hinges on some essential basic language primitives. Those are sum types, pattern matching, and restricting mutability.
Forcing sum types onto a language that does not support them is bound to end in awkwardness and reduced readability without providing the real benefits of increased
correctness.
This is a great example. std::option from C++ is another one.
- deleted 7y ago[deleted]
- vishbar 7y agoScala's for-comprehensions (and Haskell's do-notation) help quite a lot as well.
- antisemiotic 7y agoAlso F#'s computational expressions.
- Dirlewanger 7y agoYeah it's really hard to introduce, let alone completely stick with, FP in a non-FP language. I started to introduce some into our Ruby/Rails project, but halfway through, the code was more procedural than functional (which admittedly is more concise and cogent than OO); it's really hard to remember to treat everything as immutable all the time.
- lacampbell 7y agoWhen combined with flow or typescript, Javascript absolutely supports sum types. Also, it's trivial to encode the Option and Either monad using Objects to get the same functionality.