4 ms·
Speaking of.. is there an article about writing Pythonic python? I think that would be extremely useful to various team members. Sometimes the official document
by sgt 5y ago
Speaking of.. is there an article about writing Pythonic python? I think that would be extremely useful to various team members. Sometimes the official documentation is too verbose.
- fnord123 5y agoPythonic guide, not too verbose? >>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. Unless explicitly silenced. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!
- throwaway894345 5y agoI've often wished Python indexed more on "simple is better than complex" and "There should be one-- and preferably only one --obvious way to do it". Python has become quite complex over the years, including its object system, its tooling, ecosystem, and even many of the standard library APIs (thinking of you, `subprocess`!).
- richardwhiuk 5y agoOr format strings.
- CornCobs 5y agoI think f strings are great - obvious, unambiguous and an instant huge qol improvement
- kzrdude 5y agoRaymond Hettinger's talks are great. I know it's not a succint blog post, but they are out there are watching a video is very approachable. Maybe https://www.youtube.com/watch?v=T-TwcmT6Rcw https://www.youtube.com/watch?v=T-TwcmT6Rcw (Dataclasses! We could cheekily say Python gets better at something Rust does - dataclasses makes Python better at records.) And https://www.youtube.com/watch?v=S_ipdVNSFlo https://www.youtube.com/watch?v=S_ipdVNSFlo This talk (2013): https://www.youtube.com/watch?v=OSGv2VnC0go https://www.youtube.com/watch?v=OSGv2VnC0go Unfortunately this video is now a bit out of touch with modern Python. Another (2013) classic: https://www.youtube.com/watch?v=HTLu2DFOdTg https://www.youtube.com/watch?v=HTLu2DFOdTg it is very well known, and it has the very memorable advice: what's a class that only has one method? That should be a function!
- dec0dedab0de 5y agoAnother by Raymond Hettinger that is fantastic. Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015 https://www.youtube.com/watch?v=wf-BqAjZb8M https://www.youtube.com/watch?v=wf-BqAjZb8M
- kzrdude 5y agoThis is the best one :)
- fnord123 5y ago> Dataclasses! We could cheekily say Python gets better at something Rust does - dataclasses makes Python better at records It's not clear if you mean python got better at storing records than previous python or if it got better at storing records than rust. To be clear, dataclasses make python better at storing records than what was previously available in python but still not as good as Rust (serde, immutable defaults, no perf penalty with immutability).
- whalesalad 5y agoIt’s a journey, to be honest. Very hard to prescribe one solution because there are different ways people think about this question (syntax or architecture?) and different cultures around tools (like basing a web app on a heavier tool such as Django vs a lighter tool like Flask) and then of course battles over line lengths, types vs no types, etc… (I also divide Python into two big camps: building software/apps vs. data science and analysis, which further subdivides the community - if you ever read a post on how to do XYZ from the perspective of a data hacker it will usually fall into the non-pythonic category) There is a fantastic book in the Ruby world called “Eloquent Ruby” but I have yet to encounter an analog for Python. RealPython has some cool posts, though. I think they’re doing the best job pushing more modern/clean practices forward at the moment.
- pletnes 5y agoThe Fluent python book is fantastic for exactly that.
- wraptile 5y agoI highly recommend "Writting Idiomatic Python" by Jeff Knupp!