SlideShare a Scribd company logo
1 of 41
Download to read offline
h"p://blogs.uct.ac.za/gallery/669/PowerPoint.gif




                                                   1
Zen	
  of	
  Python	
  (PEP	
  20)




                                     2
>>>	
  import	
  this




h"p://www.bolgernow.com/blog/wp-­‐content/uploads/2010/05/old-­‐lady-­‐middle-­‐finger.jpg


                                                                                            3

                                                                                                3
BeauLful	
  is	
  be"er	
  than	
  ugly




h"p://www.dailystab.com/blog/wp-­‐content/uploads/2009/06/ugly.jpg




                                                                     4
Explicit	
  is	
  be"er	
  than	
  implicit




h"p://cache2.artprinLmages.com/p/LRG/19/1922/GWT9D00Z/art-­‐print/parental-­‐advisory-­‐explicit-­‐lyrics.jpg




                                                                                                                5
Simple	
  is	
  be"er	
  than	
  complex




h"p://musikality.net/wp-­‐content/uploads/simplicity.jpg




                                                           6
Complex	
  is	
  be,er	
  than	
  complicated




h"p://vipdicLonary.com/img/life_geXng_complicated.jpg




                                                        7
Flat	
  is	
  be"er	
  than	
  nested




h"p://3.bp.blogspot.com/_L1y4XexY16s/S_0WXArDtWI/
AAAAAAAAVU0/oUjxL8kI0iY/s1600/NestedDoll0.jpg




                                                        8
Sparse	
  is	
  be"er	
  than	
  dense




h"p://www.pitch.com/imager/come-­‐october-­‐royals-­‐dont-­‐need-­‐all-­‐those-­‐seats/b/original/
2568438/9885/Empty_seats_at_the_Royals_game_thumb.jpg




                                                                                                     9
Readability	
  Counts




h"p://www.voidspace.org.uk/python/weblog/images/readability.gif




                                                                  10
Special	
  cases	
  aren't	
  special	
  enough	
  to	
  break	
  the	
  rules.




h"p://www.hornblend.com/wp-­‐content/uploads/2010/08/duh.jpg




                                                                                      11
Although	
  pracLcality	
  beats	
  purity.




h"p://vilain.net/files/pracLcality.jpg



                                                     12
Errors	
  should	
  never	
  pass	
  silently.




h"p://media02.hongkiat.com/funny_error_messages/funny-­‐bsod-­‐02.jpg




                                                                        13
Unless	
  explicitly	
  silenced.




h"p://thenextweb.com/files/2010/08/Hear.No_.Evil_.jpg




                                                       14
In	
  the	
  face	
  of	
  ambiguity,	
  refuse	
  the	
  
                             tempta>on	
  to	
  guess.




h"p://www.doublejourney.com/wp-­‐content/ambiguity.jpg



                                                                            15
There	
  should	
  be	
  one-­‐-­‐	
  and	
  preferably	
  only	
  
               one	
  -­‐-­‐obvious	
  way	
  to	
  do	
  it.




h"p://www.motorcycles-­‐ok.com/mokpics/x/obvious.jpg



                                                                           16
Although	
  that	
  way	
  may	
  not	
  be	
  obvious	
  at	
  
           first	
  unless	
  you're	
  Dutch.


                                                              Dutch	
  Flag




h"p://ew.cachefly.net/snm/images/nm/flags/nl-­‐lgflag.gif



                                                                              17
Now	
  is	
  be"er	
  than	
  never.




h"ps://lh6.googleusercontent.com/_zGnH6HWaAi0/TY_3ysjUkOI/AAAAAAAAKSI/S168q0DA9vs/never_regret.jpg




                                                                                                     18
Although	
  never	
  is	
  oFen	
  be,er	
  than	
  
                         *right*	
  now.


                                                                    Why,	
  Eddie?




h"p://idioelashback.files.wordpress.com/2010/02/van_halen_logo.jpg



                                                                                 19
If	
  the	
  implementa>on	
  is	
  hard	
  to	
  explain,	
  it's	
  
                        a	
  bad	
  idea.




h"p://img256.imageshack.us/img256/8379/magnets.jpg




                                                                           20
If	
  the	
  implementa>on	
  is	
  easy	
  to	
  explain,	
  it	
  
                       may	
  be	
  a	
  good	
  idea.




h"p://images.cheezburger.com/completestore/2011/6/11/6c21f0de-­‐4f50-­‐4194-­‐94bd-­‐10ba19b77d8f.jpg




                                                                                                        21
Namespaces	
  are	
  one	
  honking	
  great	
  idea	
  -­‐-­‐	
  
            let's	
  do	
  more	
  of	
  those!




h"p://1.bp.blogspot.com/_GfY7dNRDwYI/TUHlJyG7YKI/AAAAAAAAArU/yk-­‐RtF96ZWM/s1600/ponies-­‐and-­‐rainbows.jpg



                                                                                                               22
PEP 8

Why a Style Guide matters.




                             23
h"p://graphics8.nyLmes.com/images/2010/04/27/world/27powerpoint_CA0_337-­‐span/27powerpoint_CA0-­‐arLcleLarge.jpg


                                                                                                                    24
What	
  is	
  a	
  Style	
  Guide?




h"p://intheknow.lordandtaylor.com/tag/fall-­‐2011/



                                                              25
SecLons
•   Lay-­‐out
•   Imports
•   Whitespace
•   Comments
•   Document	
  Strings
•   Version	
  Bookkeeping
•   Naming	
  Conven>ons
•   Programming	
  Recommenda>ons
                                    26

                                         26
Lay	
  Out
• 4	
  spaces
   – Unless	
  you’re	
  working	
  on	
  some	
  old	
  stuff	
  that	
  is	
  
     already	
  using	
  8	
  spaces
• Ver>cal	
  Alignment
   – Either	
  align	
  with	
  opening	
  delimiter
   – Or	
  use	
  extra	
  indenta>on




                                                                                  27
Lay	
  Out
• Tabs	
  and	
  Spaces
   – Never	
  mix	
  the	
  two	
  (like	
  liquor	
  and	
  beer)
   – If	
  in	
  doubt,	
  go	
  with	
  spaces,	
  only.
• Maximum	
  Line	
  Length
   – 79	
  char.	
  	
  
   – Use	
  the	
  implicit	
  line	
  wrap	
  within	
  parenthesis




                                                                       28

                                                                            28
h"p://blogs.uct.ac.za/gallery/669/Death_by_Powerpoint.jpg




                                                            29
Lay	
  Out
• Blank	
  Lines
   – 2	
  lines	
  between	
  top	
  level	
  func>on	
  and	
  class	
  
     defini>on
   – Use	
  blank	
  lines	
  to	
  logically	
  group	
  sec>ons
   – It’s	
  not	
  MLA.	
  	
  Don’t	
  double-­‐space	
  your	
  code.	
  
• Encodings
   – Core	
  code	
  =	
  ASCII	
  or	
  La>n-­‐1
   – Code	
  >	
  3.0	
  should	
  use	
  UTF-­‐8

                                                                               30

                                                                                    30
Lay	
  Out




             31
Imports
• One	
  import	
  per	
  line
• Put	
  at	
  the	
  top	
  of	
  the	
  document	
  aFer	
  
  comments	
  and	
  doc	
  strings
    – First	
  Standard	
  Library
    – Then	
  related	
  third-­‐party	
  imports
    – Last,	
  applica>on	
  /	
  library	
  specific	
  imports




                                                                  32
Whitespace



   Too	
  much	
  is	
  too	
  much.




h"p://www.alistapart.com/d/whitespace/whitespace.jpg




                                                        33
Whitespace
• Don’t	
  get	
  cute	
  and	
  add	
  whitespace	
  within	
  
  parenthesis	
  or	
  brackets,	
  around	
  binary	
  
  operators.
   – Write	
  it	
  how	
  you	
  would	
  normally	
  write	
  it
• Do	
  use	
  spaces	
  around	
  arithme>c	
  operators
   – Math	
  is	
  hard	
  as	
  it	
  is,	
  don’t	
  make	
  it	
  harder	
  my	
  
     squishing	
  things	
  together...



                                                                                        34

                                                                                             34
Whitespace	
  
• Don’t	
  put	
  compound	
  statements	
  on	
  one	
  line.
• Spread	
  that	
  stuff	
  out	
  so	
  it	
  is	
  easy	
  to	
  find	
  the	
  
  various	
  clauses	
  and	
  stuff.




                                                                                    35

                                                                                         35
Comments
• Comments	
  should	
  match	
  the	
  code.
• If	
  there	
  is	
  a	
  conflict,	
  change	
  one	
  of	
  them!
• Comments	
  should	
  be	
  complete	
  sentences,	
  wri,en	
  in	
  
  English.
• Lean	
  towards	
  using	
  block	
  comments.
• Use	
  inline	
  comments	
  sparingly.
• Don’t	
  be	
  the	
  obvious	
  troll.




                                                                           36
Doc	
  Strings



• Use	
  them!
• PEP	
  257




h"p://catmacros.files.wordpress.com/2010/05/itoldyouno"odothat.jpg




                                                                    37
Naming	
  ConvenLons
• Single	
  Lower	
  (d)
• Single	
  Upper	
  (W)
• lowercase
• lower_with_underscore
• UPPERCASE
• UPPER_WITH_UNDER
• CamelCase
• mixedCase


                                 38
Naming	
  ConvenLons	
  
• Avoid:
    – ‘l’,	
  ‘O’,	
  ‘I’
•   Modules	
  should	
  be	
  short,	
  lowercase
•   Classes	
  in	
  CamelCase
•   Func>ons	
  should	
  be	
  lower_with_underscores
•   Constants	
  should	
  be	
  UPPER_WITH_UNDER



                                                         39

                                                              39
Programming	
  RecommendaLons


• Thing	
  about	
  the	
  other	
  guys.
• Don’t	
  use	
  equality	
  when	
  comparing	
  singletons
• “if	
  X	
  is	
  not	
  None”	
  is	
  not	
  the	
  same	
  as	
  “if	
  X”




                                                                                  40
h"p://thecoredump.org/images/interesLng-­‐man-­‐powerpoint.jpg



                                                                 41

More Related Content

Similar to PEP Presentation for PythonKC

History of CHI (Human-Computer Interaction)
History of CHI (Human-Computer Interaction)History of CHI (Human-Computer Interaction)
History of CHI (Human-Computer Interaction)Erik Duval
 
Crossing Boundaries 3: Consumers Become Producers
Crossing Boundaries 3: Consumers Become ProducersCrossing Boundaries 3: Consumers Become Producers
Crossing Boundaries 3: Consumers Become ProducersThe Transformation Society
 
Redes sociais: pecado ou virtude?
Redes sociais: pecado ou virtude?Redes sociais: pecado ou virtude?
Redes sociais: pecado ou virtude?João Sá
 
Web Teaching Tools
Web Teaching ToolsWeb Teaching Tools
Web Teaching Toolschiarellic
 
Ten Commandments Of A Software Engineer
Ten Commandments Of A Software EngineerTen Commandments Of A Software Engineer
Ten Commandments Of A Software EngineerSebastian Marek
 
RailsConf 2008
RailsConf 2008RailsConf 2008
RailsConf 2008Libin Pan
 
סדנה בשלומי ינואר 2013
סדנה בשלומי ינואר 2013סדנה בשלומי ינואר 2013
סדנה בשלומי ינואר 2013cheneducation
 

Similar to PEP Presentation for PythonKC (9)

Dream Jobs
Dream JobsDream Jobs
Dream Jobs
 
History of CHI (Human-Computer Interaction)
History of CHI (Human-Computer Interaction)History of CHI (Human-Computer Interaction)
History of CHI (Human-Computer Interaction)
 
Crossing Boundaries 3: Consumers Become Producers
Crossing Boundaries 3: Consumers Become ProducersCrossing Boundaries 3: Consumers Become Producers
Crossing Boundaries 3: Consumers Become Producers
 
BlackBerry 10 Rises
BlackBerry 10 RisesBlackBerry 10 Rises
BlackBerry 10 Rises
 
Redes sociais: pecado ou virtude?
Redes sociais: pecado ou virtude?Redes sociais: pecado ou virtude?
Redes sociais: pecado ou virtude?
 
Web Teaching Tools
Web Teaching ToolsWeb Teaching Tools
Web Teaching Tools
 
Ten Commandments Of A Software Engineer
Ten Commandments Of A Software EngineerTen Commandments Of A Software Engineer
Ten Commandments Of A Software Engineer
 
RailsConf 2008
RailsConf 2008RailsConf 2008
RailsConf 2008
 
סדנה בשלומי ינואר 2013
סדנה בשלומי ינואר 2013סדנה בשלומי ינואר 2013
סדנה בשלומי ינואר 2013
 

Recently uploaded

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

Recently uploaded (20)

SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 

PEP Presentation for PythonKC