3 ms·
The worst idiom of Python is the idea of Pythonic. It is usually prefixed with "un" and used pejoratively. The rest of the cases it is used to rationalize arbit
by brudgers 9y ago
The worst idiom of Python is the idea of Pythonic. It is usually prefixed with "un" and used pejoratively. The rest of the cases it is used to rationalize arbitrary biases such as Python's lack of an identity function and the removal of map and filter [1] from the core language.
There's no such thing as "very Pythonic." It's a binary and the worst aspect of Pythonic is that people waste so much energy trying not to be unPythonic in order to meet the mores of the community.
[1]: Edit, Ok, I was confusing two experiences. It was reduce's removal that broke my code using the map->filter->reduce idiom. Map broke by returning a Map object rather than a list (but that was between Python and Python3). And so far as I know, filter has not been changed so as to break code.
- dec0dedab0de 9y agoI understand why you would feel this way but I disagree. The meme of being pythonic has the benefit of most libraries being understandable. It is always very obvious when python code has been written by someone who specializes in another language, and it is usually painful to read their code.
- brudgers 9y agoLike I said, the usual use of the 'Pythonic' idiom within the Python community is prefixed by "un" and used pejoratively. One aspect of the perniciousness of 'Pythonic' is that it promotes the tribalist ideal of specializing in languages. For someone optimizing for readable libraries, Smalltalk is probably a better option.
- empthought 9y agoYour comments are making me bristle a little bit, but to be honest the book being referenced by the blog post makes me bristle more. "You may use the “harmful” examples as templates to search for in your own code. When you find code like that, replace it with the idiomatic version." This is a really dumb idea, especially when paired with the incorrect implementations that the book author encourages and the blog poster critiques. Incorrect code is never idiomatic, full stop.
- brudgers 9y agoIncorrect code is incorrect code. Correct code is useful in and of itself. Idiomatic code isn't.
- emidln 9y agoSo if I have this right, things like Django's Class Based Views and sqlalchemy are Understandable. I'll take functional-style python over Understandable python any day of the week.
- dec0dedab0de 9y agoI love Django's classed based views, though I could see how they would be annoying if you aren't steeped in Python's multiple inheritance. Granted, If it weren't for Pycharm's command+click to open up where an object was defined I don't think I would like them quite as much. But being able to quickly walk the inheritance path, and finding simple clear code in small chunks is very nice.
- empthought 9y agoYes, they're both very understandable. Sorry about your mental blocks.
- akvadrako 9y agoI would say those two examples are not very Pythonic because they are overly abstracted.
- empthought 9y ago> the worst aspect of Pythonic is that people waste so much energy trying not to be unPythonic in order to meet the mores of the community This is why Python is so successful, and yet you've never heard anything about "Python fatigue." Being "Pythonic" (which as a proxy I will define as not needlessly flouting the principles that `python -mthis` prints out) is valued by most open source projects and most heavy Python users. With respect to your complaints, they are not "arbitrary biases," they are all the same conscious decision on the part of Guido to favor the use of comprehension syntax over higher-order functions. See https://www.artima.com/weblogs/viewpost.jsp?thread=98196 https://www.artima.com/weblogs/viewpost.jsp?thread=98196 You might disagree with that decision and prefer another language, but it is not arbitrary at all.
- mercer 9y agoI do minimal python programming but your comment made me re-read The Zen of Python. Such a good reminder of what I'd definitely call good practices.
- brudgers 9y agoThe analogy of religion at its core is part of what makes Pythonic such a toxic concept. It provides the Python community an excuse to treat being unPythonic as moral failing and PEP's as revelation. I suppose a true believer could look at double snake case as a convention to denote private methods in lieu of implementing modular code with actual private methods and see something beautiful and simple and explicit and uncomplicated and a good practice. There's nothing wrong with Python except the bullshit that surrounds it.
- brudgers 9y agoI attribute most of Python's growth to being a better general purpose lanaguage than MatLab and BASIC and Java and C++ and FORTRAN in common academic settings and more readable than Perl and more robust than TCL for moderate sized systems in commercial settings. Given JavaScript, there is evidence that the arbitrariness of a programming language's design is at best weakly correlated to its adoption.
- kevinmgranger 9y ago> the removal of map and filter from the core language This never happened-- perhaps you're thinking of reduce? And reduce is still in it, it just got moved to `functools`.
- empthought 9y agoHah, I didn't even know that it never happened. Goes to show the relative utility of map/filter vs comprehensions...
- amyjess 9y agoIt was proposed to do that with all three, and they walked it back to just reduce because there was a huge outcry.
- brudgers 9y agoThanks, I stand corrected. My high level memory is that the map->filter->reduce idiom was broken because <arbitrary>. Adding to my confusion was my conflating that <arbitary> with my memory of map breaking code by returning a map object rather than a list.
- kevinmgranger 9y agoYou're right in that map returned a list in python 2, but in python 3, it returns an iterator. Anyone who relied on indexing or non-lazy behavior would have their code break. GVR doesn't like functional-style programming, so he much prefers the iterative but compact comprehension alternatives. It may just be the circles I hang out in, but most folks aren't map/filter versus comprehension purists. I'll do comprehensions usually, but map/filter when it helps make the line shorter or more readable.
- brudgers 9y agoI don't have anything against list comprehensions. Sometimes they are a very useful abstraction. Other times map->filter->reduce better expresses the business logic of the program (e.g. when the analog is signal processing [1] or Unix pipes). My issue with 'Pythonic' is that it is used to express the idea that someone's thoughts are or are not properly structured. [1]: https://mitpress.mit.edu/sicp/full-text/sicp/book/node35.html https://mitpress.mit.edu/sicp/full-text/sicp/book/node35.htm...
- crdoconnor 9y agoMost of it ok, but the notion of truthiness and falsiness being pythonic (or even allowed!) was python's billion dollar mistake. It's a magnet for bugs (e.g. stock items with a price of zero being treated as items with no price at all).
- Walkman 9y agoPlease don't ever write Python programs with this mentality.
- brudgers 9y agoLike I said, Pythonic defaults to pejorative.