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..."

Комментарии • 204

  • @diatribes
    @diatribes 2 года назад +50

    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

  • @vandelayindustries2971
    @vandelayindustries2971 5 лет назад +74

    PEP 8 unto thyself, not unto others. Brilliant.

  • @f1l4nn1m
    @f1l4nn1m 9 лет назад +196

    One simply does not stop Raymond Hettinger!

  • @MichaelCampbell01
    @MichaelCampbell01 9 лет назад +51

    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!

  • @pienasty
    @pienasty 9 лет назад +226

    How could they stop him? Oo He's brilliant!

    • @oxgubc
      @oxgubc 9 лет назад +14

      ***** Had to have their hour lunch --- :(

    • @wolfson109
      @wolfson109 9 лет назад +24

      +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.

    • @RolandoGarza
      @RolandoGarza 8 лет назад +5

      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.

    • @EduardoJose-xj7zr
      @EduardoJose-xj7zr 7 лет назад

      Pieniasty izolan

    • @albertgao7256
      @albertgao7256 7 лет назад +8

      damn, I highly enjoyed it, then a man from nowhere came out and said we need to go to lunch.... WTF...

  • @anibaldk
    @anibaldk 4 года назад +9

    Who wouldn't sacrifice 10 minutes of lunch for a proper Q&A session with this bloke!?

  • @mikerayco
    @mikerayco 2 года назад +24

    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.

  • @m-th
    @m-th 9 лет назад +73

    If he isn't a fantastic speaker I don't know who is!

  • @NeilTruick
    @NeilTruick 9 лет назад +64

    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.

  • @shirshzibbu330
    @shirshzibbu330 5 лет назад +195

    he's like bob ross for python

  • @MartinLoeschner
    @MartinLoeschner 9 лет назад +55

    He made me to look up the article for P vs. NP while paused before I learned that he actually made a joke. :)

  • @pawekoaczynski4505
    @pawekoaczynski4505 3 года назад +2

    God tier talk. I'll probably rewatch this several times in the future

  • @JasonBrackman
    @JasonBrackman 9 лет назад +461

    Sucks that they stopped him.

    • @RobertButterworth
      @RobertButterworth 9 лет назад +38

      Guido (Talking about Type Hints) asked if he could run overtime and they let him. ;)

    • @joo02
      @joo02 6 лет назад +33

      Robert Butterworth the guy must’ve been pep8 zealot

    • @Engravingsful
      @Engravingsful 5 лет назад +43

      He use "eval" so they calmly ask him to leave

    • @muntoonxt
      @muntoonxt 5 лет назад +20

      @@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. ¯\\\_(ツ)\_/¯

    • @francopiccolo86
      @francopiccolo86 4 года назад +9

      Really man do u really need to stop the best CS presenter in the history of humankind.

  • @pithikoulis
    @pithikoulis 7 лет назад +41

    Well the interruption in the end was annoying. I could easily watch this guy's talk for 3 hours non-stop.

  • @deadbeatffs
    @deadbeatffs 5 лет назад +8

    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

  • @maximlevkov4354
    @maximlevkov4354 9 лет назад +19

    This is really awesome.... really awesome... This is what I call learning.... It is pity that he stopped him.

  • @DeepSukhwani
    @DeepSukhwani 4 года назад +6

    Arghh, it's sad they interrupted him in between. 5 years and his talks are soooo informative and helpful!

  • @islandia57
    @islandia57 4 года назад +9

    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?

  • @SamuelPearlman
    @SamuelPearlman 3 года назад +2

    PEP8 unto thyself, not unto others! I shall carry this wisdom forth into the new year.

  • @paulzupan3732
    @paulzupan3732 Год назад

    Raymond Hettinger is the best public speaker I think I've ever seen

  • @AlqGo
    @AlqGo 6 лет назад +4

    This guy is the reason why my like for Python keeps growing.

  • @arkster00
    @arkster00 9 лет назад +8

    That was awesome. RH always has insight on ways to get people to make their code better.

  • @aaronhall8039
    @aaronhall8039 9 лет назад +16

    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.

  • @robertturner7090
    @robertturner7090 3 года назад +3

    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!

  • @mutyaluamballa
    @mutyaluamballa 6 месяцев назад

    9 years in and still golden.

  • @richieKostenko
    @richieKostenko 9 лет назад +126

    This man is a legend.

    • @f1l4nn1m
      @f1l4nn1m 8 лет назад +12

      +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.

    • @Rinzlov
      @Rinzlov 8 лет назад +5

      Thanks for pointing out mr. Rhodes ;)

  • @MikeDupin
    @MikeDupin 9 лет назад +22

    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.

    • @CrystalGamma
      @CrystalGamma 9 лет назад +35

      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.

    • @MikeDupin
      @MikeDupin 9 лет назад +10

      CrystalGamma Thank you very much :) Now it all makes sense.

  • @infomoreandmore
    @infomoreandmore Год назад

    I was looking for this exact explanation. Enjoyed the talk throughout.

  • @gromilla1990
    @gromilla1990 7 лет назад +59

    Json is a person, JsOn is a file format :D cracked me up 18:23

    • @antopolskiy
      @antopolskiy 6 лет назад +3

      me too. but it is actually spelled jsön ;)

  • @yomajo
    @yomajo 2 года назад

    Awesome talk years later. Raymond's the best.

  • @stivosaurus
    @stivosaurus 8 лет назад +9

    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.

  • @vene
    @vene 3 года назад +2

    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.

  • @f1l4nn1m
    @f1l4nn1m 9 лет назад +80

    Lunch is way NP.

  • @grawss
    @grawss Год назад +1

    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

  • @AmanSingh-wk4qu
    @AmanSingh-wk4qu 5 лет назад

    this has to be one of the best videos I've seen on programming.

  • @gustavenk
    @gustavenk 9 лет назад +12

    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? :-)

    • @gustavenk
      @gustavenk 9 лет назад +3

      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 :-)

    • @SeanReifschneider
      @SeanReifschneider 9 лет назад +3

      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.

    • @stedi57
      @stedi57 7 лет назад +2

      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!

  • @yoloswaggins2161
    @yoloswaggins2161 5 лет назад +3

    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.

  • @nikosc
    @nikosc 9 лет назад +11

    Where can I find the "p vs np" recipe files mentioned @ 39:47 ?

    • @spidermine63
      @spidermine63 3 года назад +3

      5 years late but here you go bud
      gist.github.com/Maecenas/5878ceee890a797ee6c9ad033a0ae0f1

  • @StevenCalwas
    @StevenCalwas 6 лет назад +25

    Beyond PEP 8, but not beyond LUNCHTIME 12

  • @knipknap
    @knipknap 5 лет назад +3

    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.

  • @mkarnicki
    @mkarnicki 4 года назад +1

    I don't code in Python, and this was a great talk!

  • @luiz7607
    @luiz7607 4 года назад +7

    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.

  • @BryanChance
    @BryanChance 3 года назад

    Priceless learning. Highly recommend all Hettinger's videos. :-/

  • @heerthsdaytuehlp6771
    @heerthsdaytuehlp6771 2 года назад +1

    "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.

    • @MegaKiri11
      @MegaKiri11 Год назад

      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!

  • @Formulka
    @Formulka 9 лет назад +207

    from now on I hate lunch

  • @drd105
    @drd105 4 года назад

    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.

  • @LanceSloan-UMich
    @LanceSloan-UMich 4 года назад +2

    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. 😉

  • @gregbrown9287
    @gregbrown9287 3 года назад +2

    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!

  • @jobicarter3253
    @jobicarter3253 7 лет назад +1

    Great speaker and presentation.

  • @user-ug8qc6tr6b
    @user-ug8qc6tr6b 8 лет назад +8

    Wow! That was awesome!

  • @ashrasmun1
    @ashrasmun1 3 года назад

    I love this guy. I feel comfortable being stupid when I'm listening to this.

  • @MuhammedDarwish
    @MuhammedDarwish 6 лет назад

    What is the link to the examples presented? I can’t find them in the link in the description.

  • @xfreeman86
    @xfreeman86 7 лет назад +1

    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.

  • @akunnaemeka395
    @akunnaemeka395 2 года назад

    i love Raymond talks

  • @iamsuperroot
    @iamsuperroot 6 лет назад

    The links to lead to where your slides are at. Can you post them? Thanks.

  • @danielstromberg
    @danielstromberg 8 лет назад +1

    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.

    • @you238
      @you238 8 лет назад +13

      That sounds like a problem with pylint, rather than the collections module. Maybe open an issue/PR?

    • @tarcisioe
      @tarcisioe 8 лет назад +6

      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.

  • @sartaj1004
    @sartaj1004 9 лет назад

    Amazing talk. Pretty insightful.
    Learnt quite a few things

  • @unoti
    @unoti 9 лет назад +4

    Brilliant. I have a new hero!

  • @vcool
    @vcool 7 лет назад

    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.

  • @aoliveira_
    @aoliveira_ 5 лет назад

    You don't have the slides for this talk in those locations linked.

  • @southpole76
    @southpole76 Месяц назад

    is it still worth watching this in the black / ruff era?

  • @Mr8lacklp
    @Mr8lacklp 7 лет назад +1

    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

    • @yvrelna
      @yvrelna 5 лет назад

      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).

  • @fireh3211
    @fireh3211 8 месяцев назад

    You can't exclude that specific line from pep8?

  • @Techiesse
    @Techiesse 4 года назад +1

    If I have this guy in a conference he would speak for as long as he wanted. Wants 2 hours? Take it! Go ahead!

  • @ricosipka
    @ricosipka 6 лет назад +2

    This man is amazing.

  • @theoryofmine7473
    @theoryofmine7473 7 лет назад +4

    I make sound effects when I type. Particularly when I copy & paste :-D

  • @koenvanderrijt5244
    @koenvanderrijt5244 7 лет назад

    I only just started programming python.. but Iove this stuff

  • @erickmagnus
    @erickmagnus 7 лет назад +12

    I love PEP-8. But 79 columns is a pain...

    • @vcool
      @vcool 7 лет назад +3

      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.

  • @midlight25
    @midlight25 3 года назад +1

    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.

  • @hardikkakadia
    @hardikkakadia 6 лет назад +1

    i attended him in personal class .. Steve Jobs of Python.

  • @Caelghoul
    @Caelghoul 4 месяца назад

    Why PySide6 doesn't adhere to PEP 8 rules

  • @AsifSaifuddinAuvipy
    @AsifSaifuddinAuvipy 2 года назад

    slides are not available in the provided link

  • @ManicEightBall
    @ManicEightBall 7 лет назад +2

    I line wrap at 120 characters. Am I a bad person?

    • @DerekHohls
      @DerekHohls 5 лет назад

      Yes.

    • @DimitrisK5
      @DimitrisK5 5 лет назад

      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.

  • @revoiceful
    @revoiceful 7 лет назад +1

    amazing teacher!

  • @that_matt
    @that_matt 5 лет назад +2

    I've been happier since I stopped formatting code and let black do it for me.

  • @Elkmor2
    @Elkmor2 7 лет назад +4

    So did he write 100 lines to make other 20 shorter? I didn't quite get it.

    • @Max24871
      @Max24871 5 лет назад +1

      The point is that the adapter is supposed to be reusable (I believe).

    • @DimitrisK5
      @DimitrisK5 5 лет назад +2

      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.

  • @eladkapuza4551
    @eladkapuza4551 6 лет назад

    A pythonic code is also a flat code. I wanted to know what is the maximum nested indentations to make the code flat? Thanks

    • @polyeder2000
      @polyeder2000 4 года назад

      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.

  • @tricky2014
    @tricky2014 9 лет назад +2

    Very insightfult talk

  • @Fetrovsky
    @Fetrovsky 6 лет назад +1

    Also, why does he keep saying "tupple" instead of "tuple?"

  • @Soulthym
    @Soulthym 4 года назад +1

    I am so annoyed at that unexecuted ")" in his if p.saturation statement. That print is bugging me out!

    • @luiz7607
      @luiz7607 4 года назад

      I think he perhaps wanted to explain something about Python silently working even with that SyntaxError, perhaps showing the importance of good coverage/testing.

  • @abrarmasumabir3809
    @abrarmasumabir3809 2 года назад

    what font is he using in his emacs

  • @victorklimov5254
    @victorklimov5254 7 лет назад +2

    Excellent! 5 stars!

    • @Zen-rw2fz
      @Zen-rw2fz 7 лет назад

      Виктор Климов i like pepe

  • @CrystalGamma
    @CrystalGamma 9 лет назад +1

    Damn you, Raymond! I was just drinking a glass of water at 2:50, now it's all over my face and lap :P

  • @DasSuper
    @DasSuper 6 лет назад +1

    Lunch can wait

  • @mckdoeful
    @mckdoeful 3 года назад

    which emacs color scheme is he using?

  • @innstikk
    @innstikk 9 лет назад +1

    Great talk!

  • @CushTuse
    @CushTuse 8 лет назад

    although the first half was a little slow, from about 24:40 on it got really good.

  • @gerardgv20
    @gerardgv20 3 года назад

    This was just awesome.

  • @kithenry
    @kithenry 2 года назад

    my right ear is overwhelmed

  • @saurabhchopra
    @saurabhchopra 4 года назад

    will this throw an import error for logging?

  • @alexanderlazarev
    @alexanderlazarev 6 лет назад +1

    What a great guy!

  • @drygordspellweaver8761
    @drygordspellweaver8761 2 года назад

    The guy who interrupted him at the end is the one who wrote PEP8

  • @armynyus9123
    @armynyus9123 4 года назад

    YESS! Single Quotes FTW! I'm using axblack.

  • @DeepSukhwani
    @DeepSukhwani 4 года назад +1

    38:30 - He asks "Who learnt something new?" about `__len__` and `__getitem__` - I did 😁

  • @theprogrammingshuttle2975
    @theprogrammingshuttle2975 6 лет назад +1

    using py2 ?

  • @asgardiful
    @asgardiful 9 лет назад +1

    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.

    • @nichtverstehen2045
      @nichtverstehen2045 5 лет назад

      > I liked it, have to show it to my Java coworkers
      Did you get beaten that day?

  • @dantheman52420
    @dantheman52420 6 лет назад +1

    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 :)

  • @rednafi
    @rednafi 5 лет назад +1

    Now I know why Black's creator Lukasz Langa picked 88 character (90ish) for Black.

  • @gloweye
    @gloweye 4 года назад

    We use 140 line length.

  • @firstnamelastnamesons6830
    @firstnamelastnamesons6830 6 лет назад

    Awesome talk