Raymond Hettinger - Beyond PEP 8 -- Best practices for beautiful intelligible code - PyCon 2015

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 เม.ย. 2015
  • "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.com/pycon2015 and github.com/PyCon/2015-slides"

ความคิดเห็น • 206

  • @diatribes
    @diatribes ปีที่แล้ว +46

    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 ปีที่แล้ว +73

    PEP 8 unto thyself, not unto others. Brilliant.

  • @shirshzibbu330
    @shirshzibbu330 5 ปีที่แล้ว +191

    he's like bob ross for python

  • @f1l4nn1m
    @f1l4nn1m 9 ปีที่แล้ว +194

    One simply does not stop Raymond Hettinger!

  • @pienasty
    @pienasty 9 ปีที่แล้ว +224

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

    • @oxgubc
      @oxgubc 9 ปีที่แล้ว +14

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

    • @wolfson109
      @wolfson109 8 ปีที่แล้ว +23

      +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 7 ปีที่แล้ว +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...

  • @NeilTruick
    @NeilTruick 9 ปีที่แล้ว +63

    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.

  • @anibaldk
    @anibaldk 4 ปีที่แล้ว +8

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

  • @MichaelCampbell01
    @MichaelCampbell01 9 ปีที่แล้ว +48

    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!

  • @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 ปีที่แล้ว +72

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

  • @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. :)

  • @colacheng83
    @colacheng83 9 ปีที่แล้ว +67

    Here is the "missing 2nd half" for people who felt the talk ended abruptly: th-cam.com/video/OSGv2VnC0go/w-d-xo.html

    • @ManuGanji
      @ManuGanji 8 ปีที่แล้ว +1

      +Cheng Guo Thanks a lot!

    • @ajinjoyacdc
      @ajinjoyacdc 6 ปีที่แล้ว

      thanks man!

  • @maximlevkov4354
    @maximlevkov4354 9 ปีที่แล้ว +19

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

  • @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 4 ปีที่แล้ว +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 3 ปีที่แล้ว +9

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

  • @arkster00
    @arkster00 9 ปีที่แล้ว +8

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

  • @DeepSukhwani
    @DeepSukhwani 4 ปีที่แล้ว +6

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

  • @pawekoaczynski4505
    @pawekoaczynski4505 3 ปีที่แล้ว +2

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

  • @deadbeatffs
    @deadbeatffs 4 ปีที่แล้ว +7

    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

  • @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!

  • @SamuelPearlman
    @SamuelPearlman 3 ปีที่แล้ว +2

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

  • @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 7 ปีที่แล้ว +5

      Thanks for pointing out mr. Rhodes ;)

  • @slutmonke
    @slutmonke 6 ปีที่แล้ว +1

    This is a really great talk for someone like me who's been busy running between languages during my career.

  • @AmanSingh-wk4qu
    @AmanSingh-wk4qu 5 ปีที่แล้ว

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

  • @AlqGo
    @AlqGo 6 ปีที่แล้ว +4

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

  • @infomoreandmore
    @infomoreandmore 11 หลายเดือนก่อน

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

  • @mutyaluamballa
    @mutyaluamballa 3 หลายเดือนก่อน

    9 years in and still golden.

  • @f1l4nn1m
    @f1l4nn1m 9 ปีที่แล้ว +80

    Lunch is way NP.

  • @stivosaurus
    @stivosaurus 7 ปีที่แล้ว +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.

  • @yomajo
    @yomajo 2 ปีที่แล้ว

    Awesome talk years later. Raymond's the best.

  • @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.

  • @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

  • @gromilla1990
    @gromilla1990 7 ปีที่แล้ว +59

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

    • @antopolskiy
      @antopolskiy 5 ปีที่แล้ว +3

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

  • @jobicarter3253
    @jobicarter3253 7 ปีที่แล้ว +1

    Great speaker and presentation.

  • @paulzupan3732
    @paulzupan3732 ปีที่แล้ว

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

  • @sartaj1004
    @sartaj1004 9 ปีที่แล้ว

    Amazing talk. Pretty insightful.
    Learnt quite a few things

  • @vene
    @vene 2 ปีที่แล้ว +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.

  • @pithikoulis
    @pithikoulis 7 ปีที่แล้ว +38

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

  • @StevenCalwas
    @StevenCalwas 5 ปีที่แล้ว +25

    Beyond PEP 8, but not beyond LUNCHTIME 12

  • @heerthsdaytuehlp6771
    @heerthsdaytuehlp6771 ปีที่แล้ว +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!

  • @user-ug8qc6tr6b
    @user-ug8qc6tr6b 8 ปีที่แล้ว +8

    Wow! That was awesome!

  • @mkarnicki
    @mkarnicki 4 ปีที่แล้ว +1

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

  • @drd105
    @drd105 3 ปีที่แล้ว

    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.

  • @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?

  • @BryanChance
    @BryanChance 2 ปีที่แล้ว

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

  • @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.

  • @vcool
    @vcool 6 ปีที่แล้ว

    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.

  • @unoti
    @unoti 9 ปีที่แล้ว +4

    Brilliant. I have a new hero!

  • @Formulka
    @Formulka 9 ปีที่แล้ว +207

    from now on I hate lunch

    • @sephreed1938
      @sephreed1938 7 ปีที่แล้ว +8

      #lynchLunch

    • @muntoonxt
      @muntoonxt 4 ปีที่แล้ว

      This is why I always skip lunch.

  • @revoiceful
    @revoiceful 7 ปีที่แล้ว +1

    amazing teacher!

  • @ricosipka
    @ricosipka 6 ปีที่แล้ว +2

    This man is amazing.

  • @innstikk
    @innstikk 8 ปีที่แล้ว +1

    Great talk!

  • @akunnaemeka395
    @akunnaemeka395 2 ปีที่แล้ว

    i love Raymond talks

  • @yoloswaggins2161
    @yoloswaggins2161 4 ปีที่แล้ว +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.

  • @gerardgv20
    @gerardgv20 3 ปีที่แล้ว

    This was just awesome.

  • @koenvanderrijt5244
    @koenvanderrijt5244 7 ปีที่แล้ว

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

  • @tricky2014
    @tricky2014 9 ปีที่แล้ว +2

    Very insightfult talk

  • @alexanderlazarev
    @alexanderlazarev 6 ปีที่แล้ว +1

    What a great guy!

  • @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.

  • @DasSuper
    @DasSuper 5 ปีที่แล้ว +1

    Lunch can wait

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

  • @victorklimov5254
    @victorklimov5254 7 ปีที่แล้ว +2

    Excellent! 5 stars!

    • @Zen-rw2fz
      @Zen-rw2fz 7 ปีที่แล้ว

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

  • @firstnamelastnamesons6830
    @firstnamelastnamesons6830 6 ปีที่แล้ว

    Awesome talk

  • @nikosc
    @nikosc 8 ปีที่แล้ว +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

  • @gregbrown9287
    @gregbrown9287 2 ปีที่แล้ว +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!

  • @Silvertestrun
    @Silvertestrun 6 หลายเดือนก่อน

    Thank you

  • @MuhammedDarwish
    @MuhammedDarwish 6 ปีที่แล้ว

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

  • @iamsuperroot
    @iamsuperroot 6 ปีที่แล้ว

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

  • @hardikkakadia
    @hardikkakadia 6 ปีที่แล้ว +1

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

  • @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.

  • @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 7 ปีที่แล้ว +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.

  • @ashrasmun1
    @ashrasmun1 2 ปีที่แล้ว

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

  • @zfarahx
    @zfarahx 7 ปีที่แล้ว

    So cool!

  • @CushTuse
    @CushTuse 8 ปีที่แล้ว

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

  • @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.

  • @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

  • @theoryofmine7473
    @theoryofmine7473 7 ปีที่แล้ว +4

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

  • @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.

  • @aoliveira_
    @aoliveira_ 5 ปีที่แล้ว

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

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

  • @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 3 ปีที่แล้ว

      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.

  • @kithenry
    @kithenry 2 ปีที่แล้ว

    my right ear is overwhelmed

  • @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!

  • @armynyus9123
    @armynyus9123 3 ปีที่แล้ว

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

  • @saurabhchopra
    @saurabhchopra 4 ปีที่แล้ว

    43:55 We have type declarations in python3.

    • @luiz7607
      @luiz7607 4 ปีที่แล้ว

      Wouldn't solve the problem unless you use a type alias or TypeVar, which would look particularly weird for a primitive type. Keyword args are still the way to go I would say

  • @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!

  • @that_matt
    @that_matt 5 ปีที่แล้ว +2

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

  • @mckdoeful
    @mckdoeful 3 ปีที่แล้ว

    which emacs color scheme is he using?

  • @saurabhchopra
    @saurabhchopra 4 ปีที่แล้ว

    will this throw an import error for logging?

  • @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?

  • @abrarmasumabir3809
    @abrarmasumabir3809 2 ปีที่แล้ว

    what font is he using in his emacs

  • @DeepSukhwani
    @DeepSukhwani 4 ปีที่แล้ว +1

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

  • @theprogrammingshuttle2975
    @theprogrammingshuttle2975 6 ปีที่แล้ว

    jnett -> nett?

  • @SkySesshomaru
    @SkySesshomaru 6 ปีที่แล้ว

    That guy... DAMN YOU

  • @gloweye
    @gloweye 4 ปีที่แล้ว

    We use 140 line length.

  • @drygordspellweaver8761
    @drygordspellweaver8761 2 ปีที่แล้ว

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

  • @black_squall
    @black_squall 8 ปีที่แล้ว

    what font is that he's using?

    • @bernoulli9047
      @bernoulli9047 4 ปีที่แล้ว +1

      My guess is Monaco. This comment is only... 4 years too late.

  • @LPFan33
    @LPFan33 3 ปีที่แล้ว

    nice

  • @AsifSaifuddinAuvipy
    @AsifSaifuddinAuvipy 2 ปีที่แล้ว

    slides are not available in the provided link

  • @fireh3211
    @fireh3211 5 หลายเดือนก่อน

    You can't exclude that specific line from pep8?

  • @PiaFrausTube
    @PiaFrausTube 2 ปีที่แล้ว

    "You put too many thoughts on one line". I wish someone who designed/approved walrus operator listened to this.