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

Поділитися
Вставка
  • Опубліковано 22 гру 2024

КОМЕНТАРІ • 206

  • @diatribes
    @diatribes 2 роки тому +54

    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 років тому +79

    PEP 8 unto thyself, not unto others. Brilliant.

  • @f1l4nn1m
    @f1l4nn1m 9 років тому +197

    One simply does not stop Raymond Hettinger!

  • @MichaelCampbell01
    @MichaelCampbell01 9 років тому +53

    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 3 роки тому +25

    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.

  • @anibaldk
    @anibaldk 4 роки тому +9

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

  • @pawekoaczynski4505
    @pawekoaczynski4505 3 роки тому +2

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

  • @pienasty
    @pienasty 9 років тому +228

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

    • @oxgubc
      @oxgubc 9 років тому +14

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

    • @wolfson109
      @wolfson109 9 років тому +25

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

  • @m-th
    @m-th 9 років тому +73

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

  • @AlqGo
    @AlqGo 6 років тому +4

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

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

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

  • @SamuelPearlman
    @SamuelPearlman 4 роки тому +2

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

  • @DeepSukhwani
    @DeepSukhwani 4 роки тому +6

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

  • @maximlevkov4354
    @maximlevkov4354 9 років тому +18

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

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

  • @paulzupan3732
    @paulzupan3732 Рік тому

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

  • @arkster00
    @arkster00 9 років тому +8

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

  • @richieKostenko
    @richieKostenko 9 років тому +125

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

  • @MartinLoeschner
    @MartinLoeschner 9 років тому +56

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

  • @infomoreandmore
    @infomoreandmore Рік тому

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

  • @shirshzibbu330
    @shirshzibbu330 5 років тому +196

    he's like bob ross for python

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

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

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

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

  • @AmanSingh-wk4qu
    @AmanSingh-wk4qu 5 років тому

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

  • @yomajo
    @yomajo 2 роки тому

    Awesome talk years later. Raymond's the best.

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

  • @JasonBrackman
    @JasonBrackman 9 років тому +463

    Sucks that they stopped him.

    • @RobertButterworth
      @RobertButterworth 9 років тому +39

      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.

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

  • @gromilla1990
    @gromilla1990 7 років тому +58

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

  • @knipknap
    @knipknap 6 років тому +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.

  • @mutyaluamballa
    @mutyaluamballa 8 місяців тому

    9 years in and still golden.

  • @mkarnicki
    @mkarnicki 4 роки тому +1

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

  • @f1l4nn1m
    @f1l4nn1m 9 років тому +79

    Lunch is way NP.

  • @BryanChance
    @BryanChance 3 роки тому

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

  • @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 років тому +34

      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.

  • @nikosc
    @nikosc 9 років тому +11

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

    • @spidermine63
      @spidermine63 4 роки тому +3

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

  • @theoryofmine7473
    @theoryofmine7473 7 років тому +4

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

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

  • @user-ug8qc6tr6b
    @user-ug8qc6tr6b 8 років тому +8

    Wow! That was awesome!

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

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

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

  • @jobicarter3253
    @jobicarter3253 8 років тому +1

    Great speaker and presentation.

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

  • @CushTuse
    @CushTuse 8 років тому

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

  • @unoti
    @unoti 9 років тому +4

    Brilliant. I have a new hero!

  • @xfreeman86
    @xfreeman86 8 років тому +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.

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

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

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

  • @ricosipka
    @ricosipka 6 років тому +2

    This man is amazing.

  • @StevenCalwas
    @StevenCalwas 6 років тому +25

    Beyond PEP 8, but not beyond LUNCHTIME 12

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

  • @Formulka
    @Formulka 9 років тому +207

    from now on I hate lunch

    • @sephreed1938
      @sephreed1938 7 років тому +8

      #lynchLunch

    • @muntoonxt
      @muntoonxt 5 років тому

      This is why I always skip lunch.

  • @sartaj1004
    @sartaj1004 9 років тому

    Amazing talk. Pretty insightful.
    Learnt quite a few things

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

  • @fireh3211
    @fireh3211 10 місяців тому

    You can't exclude that specific line from pep8?

  • @Caelghoul
    @Caelghoul 6 місяців тому

    Why PySide6 doesn't adhere to PEP 8 rules

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

  • @ashrasmun1
    @ashrasmun1 3 роки тому

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

  • @akunnaemeka395
    @akunnaemeka395 2 роки тому

    i love Raymond talks

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

  • @aoliveira_
    @aoliveira_ 5 років тому

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

  • @victorklimov5254
    @victorklimov5254 8 років тому +2

    Excellent! 5 stars!

    • @Zen-rw2fz
      @Zen-rw2fz 8 років тому

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

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

  • @AsifSaifuddinAuvipy
    @AsifSaifuddinAuvipy 2 роки тому

    slides are not available in the provided link

  • @abrarmasumabir3809
    @abrarmasumabir3809 2 роки тому

    what font is he using in his emacs

  • @iamsuperroot
    @iamsuperroot 6 років тому

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

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

  • @koenvanderrijt5244
    @koenvanderrijt5244 7 років тому

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

  • @mckdoeful
    @mckdoeful 4 роки тому

    which emacs color scheme is he using?

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

  • @revoiceful
    @revoiceful 8 років тому +1

    amazing teacher!

  • @Elkmor2
    @Elkmor2 7 років тому +4

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

    • @Max24871
      @Max24871 6 років тому +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.

  • @saurabhchopra
    @saurabhchopra 4 роки тому

    will this throw an import error for logging?

  • @MuhammedDarwish
    @MuhammedDarwish 6 років тому

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

  • @alexanderlazarev
    @alexanderlazarev 6 років тому +1

    What a great guy!

  • @southpole76
    @southpole76 3 місяці тому

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

    • @RoamingAdhocrat
      @RoamingAdhocrat 2 місяці тому

      Less relevant now I think. He talks about how slavishly PEP8ifying your codebase by hand is a distraction... but who does that today? But it's still entertaining and applicable in a more abstract way

  • @gerardgv20
    @gerardgv20 3 роки тому

    This was just awesome.

  • @that_matt
    @that_matt 5 років тому +2

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

  • @erickmagnus
    @erickmagnus 8 років тому +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.

  • @tricky2014
    @tricky2014 9 років тому +2

    Very insightfult talk

  • @innstikk
    @innstikk 9 років тому +1

    Great talk!

  • @philippdowling
    @philippdowling 6 років тому +1

    8:47 LĀMP?

  • @DasSuper
    @DasSuper 6 років тому +1

    Lunch can wait

  • @Fetrovsky
    @Fetrovsky 7 років тому +1

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

  • @hardikkakadia
    @hardikkakadia 6 років тому +1

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

  • @DeepSukhwani
    @DeepSukhwani 4 роки тому +1

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

  • @theprogrammingshuttle2975
    @theprogrammingshuttle2975 6 років тому

    jnett -> nett?

  • @Silvertestrun
    @Silvertestrun 11 місяців тому

    Thank you

  • @gloweye
    @gloweye 4 роки тому

    We use 140 line length.

  • @theprogrammingshuttle2975
    @theprogrammingshuttle2975 6 років тому +1

    using py2 ?

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

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

  • @Fetrovsky
    @Fetrovsky 7 років тому +1

    Am I the only one ticked off by the space after RToffset???

  • @firstnamelastnamesons6830
    @firstnamelastnamesons6830 7 років тому

    Awesome talk