7 ms·
Python is an imperative language. The control structure, based on indentation, is well matched to Python's imperative character. Attempts to retrofit a functi
by Animats 10y ago
Python is an imperative language. The control structure, based on indentation, is well matched to Python's imperative character. Attempts to retrofit a functional style to Python fit Python's syntax badly. Lambdas, conditionals, and list comprehensions look painful if they extend beyond one line, because the indentation assumptions of Python just don't fit.
As a practical matter, only use Python's functional features in one-liners.
- nsaslideface 10y agoIndeed. I find the huge "some_method" example pretty much invalid because I'd assign that dict to a variable first, so the line would be a nicer "return my_dict if y else {}". What person, style guide or PEP is forcing anyone to write some_method's return statement? I don't get the ideal of saving space and writing huge one-liners (that in Python you'd have to break up over more lines). As they say on IRC: "if you're worried about using too many lines, I can send you a file full of blank ones."
- userbinator 10y agoPython is an imperative language. ...as are many others with the conditional operator's operands in the normal (condition, true-case, false-case) order: https://en.wikipedia.org/wiki/%3F https://en.wikipedia.org/wiki/%3F: I think being "functional" or otherwise has nothing to do with it. Even in imperative languages you must use expressions, and it is there that the conditional operator is most useful.
- jolux 10y agoYeah, this has nothing to do with FP. No idea what the parent was going for...
- pjvandehaar 10y agohttps://en.wikipedia.org/wiki/%3F%3A https://en.wikipedia.org/wiki/%3F%3A
- Lazare 10y agoYou've identified a real issue (the functional features work badly except as one liners), and a good fix (only use them as one liners). I think the cause has everything to do with some poor choices around the parser and syntax, however, and nothing to do with its imperative nature as such.