SlideShare a Scribd company logo
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

Dream Jobs
Dream JobsDream Jobs
Dream Jobs
Mike Kornacki
 
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 Producers
The Transformation Society
 
BlackBerry 10 Rises
BlackBerry 10 RisesBlackBerry 10 Rises
BlackBerry 10 Rises
Volker Hirsch
 
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 Tools
chiarellic
 
Ten Commandments Of A Software Engineer
Ten Commandments Of A Software EngineerTen Commandments Of A Software Engineer
Ten Commandments Of A Software Engineer
Sebastian Marek
 
RailsConf 2008
RailsConf 2008RailsConf 2008
RailsConf 2008
Libin Pan
 
סדנה בשלומי ינואר 2013
סדנה בשלומי ינואר 2013סדנה בשלומי ינואר 2013
סדנה בשלומי ינואר 2013
cheneducation
 

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

Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
Safe Software
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
Claudio Di Ciccio
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
Techgropse Pvt.Ltd.
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
名前 です男
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
Zilliz
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
Claudio Di Ciccio
 

Recently uploaded (20)

Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
Essentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FMEEssentials of Automations: The Art of Triggers and Actions in FME
Essentials of Automations: The Art of Triggers and Actions in FME
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”“I’m still / I’m still / Chaining from the Block”
“I’m still / I’m still / Chaining from the Block”
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdfAI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
AI-Powered Food Delivery Transforming App Development in Saudi Arabia.pdf
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
みなさんこんにちはこれ何文字まで入るの?40文字以下不可とか本当に意味わからないけどこれ限界文字数書いてないからマジでやばい文字数いけるんじゃないの?えこ...
 
Full-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalizationFull-RAG: A modern architecture for hyper-personalization
Full-RAG: A modern architecture for hyper-personalization
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
CAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on BlockchainCAKE: Sharing Slices of Confidential Data on Blockchain
CAKE: Sharing Slices of Confidential Data on Blockchain
 

PEP Presentation for PythonKC