3 ms·
Adding FP features to an otherwise-mutable language has always seemed a mixed bag to me. Obviously it’s nice to have those features, but you don’t get the immut
by macintux 8y ago
Adding FP features to an otherwise-mutable language has always seemed a mixed bag to me. Obviously it’s nice to have those features, but you don’t get the immutability constraint that makes development so much more predictable.
- jolmg 8y agoExactly this. In Haskell, I can look at a function signature or definition and be guaranteed a lot of what that function is or is not able to do without needing to look at the code it's calling. That's never going to be the case with Python. I can only, at most, trust the conventions the writer seems to be following.
- sevensor 8y agoPython offers immutable data structures in addition to the mutable ones. Tuples are immutable, we've had namedtuple for a while, and now it's possible to write immutable data classes as well. As time goes by, I find myself using less and less mutability in Python. At this point I default to immutable structures, and I bring in mutable ones only if I need them for performance or there's no reasonable immutable alternative.
- macintux 8y agoTangentially, I was extremely annoyed to discover that tuple unpacking in function headers was removed with Python 3. Coming from Erlang, tuples were quite appealing, but that was frustrating.
- ssfak 8y agoIndeed, "Mostly functional" programming does not work: https://queue.acm.org/detail.cfm?id=2611829 https://queue.acm.org/detail.cfm?id=2611829
- nikofeyn 8y agoi understand who the author of that article is, but i feel that's an overly hardline approach. f# and racket are perfectly fine and productive mostly functional languages.
- kjeetgill 8y agoNot true at all! Coming from Java, notoriously OOP heavy idiomatically, or python, sprinkling in some functional programming is Fantastic(!). Despite all the FP vs OOP hoopla I think they actually play fairly well together. Even OOP has moved to immutable records + localized behavior as the rule and fully mutable objects with side-effects are the exception. FP is great at the high-level for orchestrating workflows and in the lower-level processing/transforming/aggregating over streams of immutable records. OOP is great at the high-level for independent communicating services/life-cycles and fine-tuned memory bound algorithms and needing state machines lower down. You generally know what parts of your code mutate and what don't well enough to get the nice side-effect free usage from your functional parts. Someone smarter than me once said: OOP? FP? It's really all just about being principled about state. A closure is just an object with one function.
- macintux 8y agoYou can get those OOP benefits using Erlang. I’m not saying it’s bad to add FP bits to other languages. I just haven’t seen the same benefits as when I know what a called library/module can and can’t do with my data.