News for hackers. Stuff that matters.
Re:Best Practices for Using Functional Programming in Python by macintux on Wednesday December 05, 2018 @10:15AM (#18608886)
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.
Re:Best Practices for Using Functional Programming in Python by sevensor on Wednesday December 05, 2018 @10:38AM (#18609163)
Python 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.
Re:Best Practices for Using Functional Programming in Python by macintux on Wednesday December 05, 2018 @10:56AM (#18609371)
Tangentially, 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.
Re:Best Practices for Using Functional Programming in Python by kjeetgill on Wednesday December 05, 2018 @06:06PM (#18613669)
Not 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.

Re:Best Practices for Using Functional Programming in Python by macintux on Wednesday December 05, 2018 @07:06PM (#18614085)
You 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.

Re:Best Practices for Using Functional Programming in Python by jolmg on Wednesday December 05, 2018 @10:30AM (#18609066)
Exactly 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.
Re:Best Practices for Using Functional Programming in Python by ssfak on Wednesday December 05, 2018 @10:41AM (#18609208)
Indeed, "Mostly functional" programming does not work: https://queue.acm.org/detail.cfm?id=2611829
Re:Best Practices for Using Functional Programming in Python by nikofeyn on Wednesday December 05, 2018 @10:51AM (#18609320)
i 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.