3 ms·
I'll bite: Impossible to write pure functional style code in python, hence it loses any elegance contest right out of the gate. ;) I work in a python shop now,
by matsemann 3y ago
I'll bite: Impossible to write pure functional style code in python, hence it loses any elegance contest right out of the gate. ;)
I work in a python shop now, and the code I've written the last years must be the ugliest of my career. If it's too complicated to be solved with a list comprehension, it will be so much uglier than lambdas in a language with a form of piping.
- boxed 3y ago> Impossible to write pure functional style code in python What does that even mean?
- behnamoh 3y agoThey probably mean you need to import some modules to do things like partial functions. But it's not like functional programming is not possible in Python. I'd argue that Elixir's syntax is more of hindrance to FP than Haskell's elegant syntax.
- matsemann 3y agoNo, if importing something was enough it would be fine. It's more that how a lambda can only contain a single expression means you need to split and name things everywhere, how you can't pipe/chain things means you need to have intermediate variables or an ungodly amount of nesting etc. Yeah, technically feasible, but it's not "pythonic" so you solve it some other (to me) less elegant way.
- bPspGiJT8Y 3y ago> It's more that how a lambda can only contain a single expression That's exactly how lambdas (and all functions) work in actually functional languages like Haskell. And it's a good thing,lambdas shouldn't allow statements. > how you can't pipe/chain things Ironically after switching from Elixir to a language where I can have any operator I wish, I found myself using the equivalent of Elixir's |> only on a very rare occasion. IMO they're vastly overrated.
- matsemann 3y agoHmm, you can surely use multiple lets in a lambda in haskell, as in every other function? And it doesn't have to be the pipe operator, just something similar. Like list.map().filter().reduce() instead of reduce(filter(map(list))) which quickly gets unwindly.
- boxed 3y ago> need to split and name things everywhere It can sometimes be annoying yes, but when you come back to the code 6 months later it's mostly a good thing.
- matsemann 3y agoBut in other languages it's clear what the code is doing. If you have a chain of map, filters and other operations, they are all named and easy to grok. In a python list comprehension a lot of things will be going on, without named parts. So then you need to name stuff to keep track. So you got foo, then foo_filtered, then foo_sorted, then foo_grouped. And that doesn't really convey anything more than in a language where you would do foo.filter().sort().group().
- regulation_d 3y agoWhen I first started writing Elixir, I had no idea how much I would come to love immutable data as a language feature. "functional" can mean so many things, but for me immutable data as part of the runtime (i.e. not bolted on later) is one of the most important things. Never having to ask: did I pass by reference or value? Never having worry about data changing out from underneath you. It's pretty amazing. Sure there are times that a need for performance calls for mutable data. But for me those times are pretty rare, and when they happen it's usually easy enough to quarantine the mutation.