Raymond Hettinger - Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015
HTML-код
- Опубликовано: 21 окт 2024
- "Speaker: Raymond Hettinger
Distillation of knowledge gained from a decade of Python consulting, Python training, code reviews, and serving as a core developer. Learn to avoid some of the hazards of the PEP 8 style guide and learn what really matters for creating beautiful intelligible code.
Slides can be found at: speakerdeck.co... and github.com/PyC..."
I'm watching this like 7 years later and it still blows my mind how such a simple talk can have a profound impact on how you approach problems
PEP 8 unto thyself, not unto others. Brilliant.
One simply does not stop Raymond Hettinger!
I love the guy introducing Raymond glibly comments "I didn't know there was anything beyond PEP 8 in beauty", and then Raymond's entire talk was basically destroying that notion. Great talk!
How could they stop him? Oo He's brilliant!
***** Had to have their hour lunch --- :(
+Pieniasty Having chaired a conference before, it is a thankless task. People either complain that you let a talk run too long, or they get upset when you cut a talk short to make sure the conference stays on schedule.
as another commenter said, perhaps the right approach as an organizer is to check with the audience it they're willing to cut down from 60 minutes to 50 so they can validate if the consensus is that the talk is more important than the food.
Pieniasty izolan
damn, I highly enjoyed it, then a man from nowhere came out and said we need to go to lunch.... WTF...
Who wouldn't sacrifice 10 minutes of lunch for a proper Q&A session with this bloke!?
This is still one of the best talks about Python, with lots of wisdom and insights to learn from. It's a shame that this was cut short.
If he isn't a fantastic speaker I don't know who is!
In my career, I have only known three presenters who can make me say, at the end of their talks and presentations, "I wish it could have gone longer": Mark Miller, Marco Cantu, and Ray Konopka. (Yes, I was a Delphi maven back in the day...)
I now know four.
he's like bob ross for python
He made me to look up the article for P vs. NP while paused before I learned that he actually made a joke. :)
God tier talk. I'll probably rewatch this several times in the future
Sucks that they stopped him.
Guido (Talking about Type Hints) asked if he could run overtime and they let him. ;)
Robert Butterworth the guy must’ve been pep8 zealot
He use "eval" so they calmly ask him to leave
@@RobertButterworth I mean... it's Guido. The entire reason everyone is there.
But then this is Raymond. The other reason everyone is there. So idk. ¯\\\_(ツ)\_/¯
Really man do u really need to stop the best CS presenter in the history of humankind.
Well the interruption in the end was annoying. I could easily watch this guy's talk for 3 hours non-stop.
This talk is the talk i have watched maybe like 10 times already. Wisdom of appreciating the idioms that were coined in Python, giving the life to idioms that make Python so impressive
This is really awesome.... really awesome... This is what I call learning.... It is pity that he stopped him.
Arghh, it's sad they interrupted him in between. 5 years and his talks are soooo informative and helpful!
I was pretty sure the "Gorilla in the room" was the fact he PEP-8'd ne.cleanup(''''commit''') in to ne.cleanup('scommit'). Did everyone in the room miss that?
PEP8 unto thyself, not unto others! I shall carry this wisdom forth into the new year.
Raymond Hettinger is the best public speaker I think I've ever seen
This guy is the reason why my like for Python keeps growing.
That was awesome. RH always has insight on ways to get people to make their code better.
I enjoyed that immensely. He was definitely preaching to the choir with me, I was questioning the procedural style, but it was apropos to the purpose when I saw where he was heading. I recommend speeding through the first ten minutes to about 11:00 where he starts the style fixes, and then slow down at about 22:00 when he gets to the main point of the talk.
I need to get to a pycon with this gentleman as a speaker. Third presentation I've seen of his, packed full of wisdom and humor I've yet to find in any textbook. Thank you!
9 years in and still golden.
This man is a legend.
+richieKostenko I think you are right. He is gifted with clarity and practicality, although he also possesses vast experience. I really like his talks. I also like Brandon Rhodes' talks.
Thanks for pointing out mr. Rhodes ;)
Can anyone tell me what's Raymond mentioning and why, when he discusses named tuples? It's the thing about which he jokes that doesn't please someone from the audience. I've listened to that moment several times, but I can't get it.
Michal Wysokinski I think he's saying 'eval', i. e. runtime code compilation (even though it's 'exec' in the source code: hg.python.org/cpython/file/default/Lib/collections/__init__.py#l404 ). Took me a while to figure out myself.
CrystalGamma Thank you very much :) Now it all makes sense.
I was looking for this exact explanation. Enjoyed the talk throughout.
Json is a person, JsOn is a file format :D cracked me up 18:23
me too. but it is actually spelled jsön ;)
Awesome talk years later. Raymond's the best.
Named tuples, Woo Woo! Just last night, I was thinking no way am I going to make a class just so I can refer to it's two members by name. Three cheers for readability.
I expected that a talk from six years ago might be redundant or less useful nowadays. Nope. Absolutely brilliant advice that I haven't seen hammered home like this before.
I remember first seeing named tuples and wondering what the hell they are for, now it's obvious and I feel like a dummy for not seeing it previously.
Lunch is way NP.
Wow this is amazing, and this logic can be applied to all of society and human nature. People will do as they're told, on average, but this psychology isn't a 1 or a 0 -- on or off --, it's a spectrum, and the tendency to start "fixing" problems while ignoring the underlying issues is a big part of that. When the "bosses" or creators of the code bases and big industry want more integration between code bases and code that's easier to read and update, intuitively it's a good idea to focus on prettying it up, but coders are engineers, and engineers should always always always be focused on making the simplest version of the task at hand.
Look at any old invention that still works today and you'll see things people would scoff at were it not 100% fact that it works flawlessly. That's old code. The engineers and creators of today may follow more standards, and may be more organized, but we're all human, and the gorilla in the room is all the things beyond the famous quote: "Perfection is Achieved Not When There Is Nothing More to Add, But When There Is Nothing Left to Take Away" -Antoine de Saint-Exupery
this has to be one of the best videos I've seen on programming.
In his refactoring he added a typo - 'commit' changed to 'scommit'. I wonder if that was deliberate, and he intended to go back to it at the end (he did mention nobody having seen "the gorilla") but got cut short before he could?
Or was it just proof that even simple refactorings aren't risk-free when done in front of a live audience? :-)
Sean Reifschneider Yeah, that was clearly the real point. But it did amuse me that he'd introduced the typo. The perils of live coding on stage, I guess :-)
I'm surprised nobody said that when he asked if anyone would commit those changes. I'd bet that Larry caught it but didn't speak up.
Original code ended up calling ne.cleanup() twice upon exceptions; this may have catastrophic consequences with dangling class members etc.. But of course, unit tests would have caught that. PEP8-processed code was no better and still had wrong indentation in else: block. For I while I thought that was the gorilla but no, it was the elephant :) Pythonic code does it all correctly. I think I need to really study Python one of these days!
34:50 The old code does a commit on error while the new one doesn't. (I assume 'scommit' is just a typo). At 35:50 he addresses this by saying that you don't want to do a commit on a disconnect which is the behavior of the new code but not the old. That said if this is what you want then the old code is very odd, since the finally section will execute no matter what, error or no error.
Where can I find the "p vs np" recipe files mentioned @ 39:47 ?
5 years late but here you go bud
gist.github.com/Maecenas/5878ceee890a797ee6c9ad033a0ae0f1
Beyond PEP 8, but not beyond LUNCHTIME 12
I like the 80 character limit, because I can't think of many features that improved my productivity like using vertical windows. Doing that with the 80 char limit allows for three vertical windows on my laptop. Beyond that, it becomes unreadable.
I don't code in Python, and this was a great talk!
Looks like a very wise idea to stop a brilliant talk by Raymond to call people for lunch. And it was near the end already, and this is one of the most important PyCon talks I've ever seen - doesn't make any sense.
Priceless learning. Highly recommend all Hettinger's videos. :-/
"I know, we'll indent less. Two space indents" ... [instead of Python's forced 4] ... "Does that make the code better?".
At this point I shouted to myself YES!!!!
Of course, Raymond said "No, but it fits in 79 characters, and they'd rather fit in 79 characters and give up the intelligibility that comes from four space indents."
I contend that four space indents does very little to increase intelligibility over two space indents. It merely consumes more horizontal space for indentation (leaving less for code). Even allowing that *some* people might have trouble in *some* cases tracking the alignment of code, I think the cost of that lost space is far more detrimental to the code.
2 spaces are a bit too small, but 3 is perfect! There was such coding style at one of the companies I worked for. It's great, but you need to set up every IDE to work with that. Savage!
from now on I hate lunch
#lynchLunch
This is why I always skip lunch.
Been meaning to watch this video for years. Now I finally got to it. So pythonic way is to use context managers and namedtuple. There is a number of flame wars that can be stopped by simply linking to this video.
I like his last remark about making the code "less fra-jee-lay". I bet he likes the movie "A Christmas Story". He should get a major award for this presentation. 😉
21:30 Does it trigger anyone else that the 2 first lines in the Else block are still not the same indentation level as the Try and Except blocks, even after fixing the indentation in the script? Amazing talk, nonetheless. Learned a lot!
Yes, profoundly
Great speaker and presentation.
Wow! That was awesome!
I love this guy. I feel comfortable being stupid when I'm listening to this.
What is the link to the examples presented? I can’t find them in the link in the description.
The volume is way quiet. I've got the video volume all the way, my laptop volume all the way up, and I still can't hear most of it unless the room is completely quiet.
i love Raymond talks
The links to lead to where your slides are at. Can you post them? Thanks.
Terrific talk.
One quibble: Named tuples present a nice API, but I don't like them, and it's not because they use eval. It's because pylint can't see inside them, so named_tuple.almost_speled_right isn't flagged as an error.
That sounds like a problem with pylint, rather than the collections module. Maybe open an issue/PR?
Using pylint 1.4.1 and it apparently now does flag errors with namedtuples correctly. I was also pleasantly surprised by jedi-vim autocompleting them with ease, recently.
Amazing talk. Pretty insightful.
Learnt quite a few things
Brilliant. I have a new hero!
Enforcing PEP 8 via the *pycodestyle* tool is great, but I recommend also using *pylint* for more comprehensive static analysis. The latter is not a replacement for the former.
You don't have the slides for this talk in those locations linked.
is it still worth watching this in the black / ruff era?
I never understood why the counting of line lengths doesn't start after the indents, it's not like there is any reason why you would not need to write the same longish lines inside some nested loops or ifs
Deeply nested statements are also a code smell. If you have more than two levels of indentations in your code, you're probably doing something too complicated for its own good. The 90-ish guideline is already about the size of 79, but with some allowances for nesting (4 for class indent, 4 for function indent, 2x4 for nested blocks, and finally another 4 for indenting multiline function calls).
You can't exclude that specific line from pep8?
If I have this guy in a conference he would speak for as long as he wanted. Wants 2 hours? Take it! Go ahead!
This man is amazing.
I make sound effects when I type. Particularly when I copy & paste :-D
I only just started programming python.. but Iove this stuff
I love PEP-8. But 79 columns is a pain...
It is but you can configure it to use 120 or any other value as I do. Just set "max-line-length = 120" in a section named [pycodestyle] in a tox.ini or setup.cfg file for your project.
19:50 "Who should PEP8-ify this code? The intern? The boss?" God-damn, if I don't love modern development with my linters and automatic formatters. AutoPEP8 for the win.
i attended him in personal class .. Steve Jobs of Python.
Why PySide6 doesn't adhere to PEP 8 rules
slides are not available in the provided link
I line wrap at 120 characters. Am I a bad person?
Yes.
Me too (I only write business code). The 80 characters limit was introduced when monitor couldn't handle 2 files with 120 characters side-by-side.
amazing teacher!
I've been happier since I stopped formatting code and let black do it for me.
So did he write 100 lines to make other 20 shorter? I didn't quite get it.
The point is that the adapter is supposed to be reusable (I believe).
The point wasn't to reduce the lines of code, but to create a better (and more pythonic) API. This is especially important if the API is going be used by lots of people (e.g. as a reusable library). Writing more lines once to: 1) reduce lines of code, 2) improve readability, 3) help avoid mistakes, etc., in multiple places (e.g. in the business parts of your code) is very desirable.
A pythonic code is also a flat code. I wanted to know what is the maximum nested indentations to make the code flat? Thanks
In some talk Uncle Bob said the maximum is 1, iirc. Look up his talks about clean code. Another fantastic speaker with knowledge and wisdom.
Very insightfult talk
Also, why does he keep saying "tupple" instead of "tuple?"
I am so annoyed at that unexecuted ")" in his if p.saturation statement. That print is bugging me out!
I think he perhaps wanted to explain something about Python silently working even with that SyntaxError, perhaps showing the importance of good coverage/testing.
what font is he using in his emacs
Excellent! 5 stars!
Виктор Климов i like pepe
Damn you, Raymond! I was just drinking a glass of water at 2:50, now it's all over my face and lap :P
Lunch can wait
which emacs color scheme is he using?
Great talk!
although the first half was a little slow, from about 24:40 on it got really good.
This was just awesome.
my right ear is overwhelmed
will this throw an import error for logging?
What a great guy!
The guy who interrupted him at the end is the one who wrote PEP8
YESS! Single Quotes FTW! I'm using axblack.
38:30 - He asks "Who learnt something new?" about `__len__` and `__getitem__` - I did 😁
using py2 ?
I liked it, have to show it to my Java coworkers. :-)
I tend to use double quotes for strings that are in human language and don't affect meaning of the code (such as messages), and single quotes for strings like symbols or computer commands that do affect program semantics.
> I liked it, have to show it to my Java coworkers
Did you get beaten that day?
Proof that when you're overly worried about style, you miss the fact that you're looking at bad code with a lack of solid design patterns. It's 2018 now, there are awesome tools to automatically format your code. Get VS Code and install all of the Python extensions. Then read about design patterns now that you don't have to worry about flake8 failing your continuous build :)
Now I know why Black's creator Lukasz Langa picked 88 character (90ish) for Black.
We use 140 line length.
Awesome talk