SlideShare une entreprise Scribd logo
1  sur  35
Télécharger pour lire hors ligne
Code quality
 Patch quality
Malcolm Tredinnick
malcolm.tredinnick@gmail.com
Code Quality Matters
“Have you ever written a library
before? It's like people seeing you in
your underwear. You gotta make
sure it's clean.”
Do The Basics Properly
Yr Doin' It Wrng!

●   If the word “print” is still in your patch
    –   Similarly for the phrase “import pdb”
Yr Doin' It Wrng!


●   If you don't have a test or a really good reason
    –   Your reason is never going to be good enough.
    –   Fail before; pass afterwards
Yr Doin' It Wrng!


●   If you think “PEP 8” is the name of a new
    energy drink
How Hard Can It Be(tm)?
●   They're called patches for a reason.
●   Go to the top of the project tree.
●   Then: svn diff (or git diff or ...)
    –   “svn add” works locally

●   Even if you're a translator or a documenter.
Code style is somewhat opinionated
Your opinions don't matter
       (that much)
Read the contributing document
Code is...


Written once
●




Read many, many times
●
Comments should last
Comments should be correct!
Fix problems not symptoms!
Symptom fixing...
Ticket #8182:
  Infinite loop iterating over PermWrapper

The template code below will cause an infinite
memory-eating loop if context_processors.auth is
enabled. My main issue with that is that it was
incredibly hard to debug for me, when I passed
my own 'perms' queryset to a template.
...

{% for perm in perms %}
{% endfor %}
django/contrib/auth/models.py     |   22 ++++++++++++++++++++++
django/core/context_processors.py |    5 +++++
docs/authentication.txt           |   11 ++++++++---

3 files changed, 35 insertions(+), 3 deletions(-)
Where else does it happen?
Warning: may be hard!
r7740
Author: mtredinnick
Date:   Thu Jun 26 11:01:21 2008 +1000

...

This is the same problem as [7597]
but for values() field
specifications, so this covers the
second case where Django adds extra
stuff to the select-clause.
r8107

Author: mtredinnick
Date:   Mon Jul 28 04:16:17 2008 +1000

...

Fixed a missed case of promoting table
joins when using disjunctive filters.
r8783

Author: mtredinnick
Date:   Mon Sep 1 18:43:55 2008 -0700

...

Fixed an oversight when I first fixed
ordering on nullable foreign keys.
r8853
Author: mtredinnick
Date:     Tue Sep 2 06:52:07 2008 -0700
....

+       def promote_alias_chain(self, chain,...):
+        """
+        Walks along a chain of aliases, promoting the first
+        nullable join and any joins following that. If
+        'must_promote' is True, all the aliases in
+        the chain are promoted.
+        """
+        for alias in chain:
+            if self.promote_alias(alias, must_promote):
+                must_promote = True
+
Know your limitations
The crowd is smarter than you!
   (the code mostly works)
“Here is a trivial patch”
Translation: “here are some bugs I
    thought you should have”
Research is not a four letter word
●   Django runs out-of-the-box on databases.
    Plural.
        –   SQLite, MySQL, PostgreSQL, Oracle

●   External backends, too
●   Separate solution approach into pieces
        –   It has a chance of working and here's a good
              start.
        –   It has a perfect implementation.
●   Django runs on multiple operating systems
    –   Windows, Linux, Mac, ...

●   Some things are hard
    –   File handling, locking, ...
    –   Character encoding

●   Best defense is “don't do that”.
●   Next best is a good offense (Research!)
●   There are RFCs.
    –   They apply in this universe.

●   There are competing specs
    –   Real world software beats paper

●   There are contradictory requirements
    –   Duh!
Python needs research, too
●   Pickle has mulitple protocols:
    –   0 and 2 are important

●   __len__() is eeevviiilll
    –   With good reason
    –   Swallows exceptions
         ●   TypeError
         ●   Others (Python 2.3, Python 2.6.0 – 2.6.1)

●   Unicode matters. So does UTF-8
Always contribute!

Best beats perfect

Contenu connexe

Tendances

Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
tswr
 

Tendances (9)

Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming Language
 
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
Windows 10 - Endpoint Security Improvements and the Implant Since Windows 2000
 
Trusting files (and their formats)
Trusting files (and their formats)Trusting files (and their formats)
Trusting files (and their formats)
 
Lisp in a Startup: the Good, the Bad, and the Ugly
Lisp in a Startup: the Good, the Bad, and the UglyLisp in a Startup: the Good, the Bad, and the Ugly
Lisp in a Startup: the Good, the Bad, and the Ugly
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
 
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
Patching Windows Executables with the Backdoor Factory | DerbyCon 2013
 
An overview of potential leaks via PDF
An overview of potential leaks via PDFAn overview of potential leaks via PDF
An overview of potential leaks via PDF
 
AV Evasion with the Veil Framework
AV Evasion with the Veil FrameworkAV Evasion with the Veil Framework
AV Evasion with the Veil Framework
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

En vedette (7)

Getting Connected: Social Media for Business
Getting Connected: Social Media for BusinessGetting Connected: Social Media for Business
Getting Connected: Social Media for Business
 
Social media & causes
Social media & causesSocial media & causes
Social media & causes
 
Kit Instant de Optimism
Kit Instant de OptimismKit Instant de Optimism
Kit Instant de Optimism
 
Slideshow Dell Istituto Comprensivo Trento 6
Slideshow Dell Istituto Comprensivo Trento 6Slideshow Dell Istituto Comprensivo Trento 6
Slideshow Dell Istituto Comprensivo Trento 6
 
Bdd and-testing
Bdd and-testingBdd and-testing
Bdd and-testing
 
Summer Camps At Fsu
Summer Camps At FsuSummer Camps At Fsu
Summer Camps At Fsu
 
New To Sakai
New To SakaiNew To Sakai
New To Sakai
 

Similaire à Code quality. Patch quality

Unbreaking Your Django Application
Unbreaking Your Django ApplicationUnbreaking Your Django Application
Unbreaking Your Django Application
OSCON Byrum
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanics
elliando dias
 
Next.ml Boston: Data Science Dev Ops
Next.ml Boston: Data Science Dev OpsNext.ml Boston: Data Science Dev Ops
Next.ml Boston: Data Science Dev Ops
Eric Chiang
 
Contest Tips and Tricks
Contest Tips and TricksContest Tips and Tricks
Contest Tips and Tricks
mbuzdalov
 

Similaire à Code quality. Patch quality (20)

The innerHTML Apocalypse
The innerHTML ApocalypseThe innerHTML Apocalypse
The innerHTML Apocalypse
 
Puppet@Citygrid - Julien Rottenberg - PuppetCamp LA '12
Puppet@Citygrid - Julien Rottenberg - PuppetCamp LA '12Puppet@Citygrid - Julien Rottenberg - PuppetCamp LA '12
Puppet@Citygrid - Julien Rottenberg - PuppetCamp LA '12
 
Killer Bugs From Outer Space
Killer Bugs From Outer SpaceKiller Bugs From Outer Space
Killer Bugs From Outer Space
 
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
The Dirty Little Secrets They Didn’t Teach You In Pentesting Class
 
Android antipatterns
Android antipatternsAndroid antipatterns
Android antipatterns
 
Unbreaking Your Django Application
Unbreaking Your Django ApplicationUnbreaking Your Django Application
Unbreaking Your Django Application
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanics
 
Behind the Scenes of ChatGPT.pptx
Behind the Scenes of ChatGPT.pptxBehind the Scenes of ChatGPT.pptx
Behind the Scenes of ChatGPT.pptx
 
Tdd in practice
Tdd in practiceTdd in practice
Tdd in practice
 
Os Goodger
Os GoodgerOs Goodger
Os Goodger
 
Django at Scale
Django at ScaleDjango at Scale
Django at Scale
 
Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...Austin Python Learners Meetup - Everything you need to know about programming...
Austin Python Learners Meetup - Everything you need to know about programming...
 
JavaScript Best Pratices
JavaScript Best PraticesJavaScript Best Pratices
JavaScript Best Pratices
 
Debugging multiplayer games
Debugging multiplayer gamesDebugging multiplayer games
Debugging multiplayer games
 
Java Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky ProblemJava Tools and Techniques for Solving Tricky Problem
Java Tools and Techniques for Solving Tricky Problem
 
Dev secops opsec, devsec, devops ?
Dev secops opsec, devsec, devops ?Dev secops opsec, devsec, devops ?
Dev secops opsec, devsec, devops ?
 
Next.ml Boston: Data Science Dev Ops
Next.ml Boston: Data Science Dev OpsNext.ml Boston: Data Science Dev Ops
Next.ml Boston: Data Science Dev Ops
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
Statistical Learning and Text Classification with NLTK and scikit-learn
Statistical Learning and Text Classification with NLTK and scikit-learnStatistical Learning and Text Classification with NLTK and scikit-learn
Statistical Learning and Text Classification with NLTK and scikit-learn
 
Contest Tips and Tricks
Contest Tips and TricksContest Tips and Tricks
Contest Tips and Tricks
 

Dernier

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Dernier (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Code quality. Patch quality

  • 1. Code quality Patch quality Malcolm Tredinnick malcolm.tredinnick@gmail.com
  • 3. “Have you ever written a library before? It's like people seeing you in your underwear. You gotta make sure it's clean.”
  • 4. Do The Basics Properly
  • 5. Yr Doin' It Wrng! ● If the word “print” is still in your patch – Similarly for the phrase “import pdb”
  • 6. Yr Doin' It Wrng! ● If you don't have a test or a really good reason – Your reason is never going to be good enough. – Fail before; pass afterwards
  • 7. Yr Doin' It Wrng! ● If you think “PEP 8” is the name of a new energy drink
  • 8. How Hard Can It Be(tm)? ● They're called patches for a reason. ● Go to the top of the project tree. ● Then: svn diff (or git diff or ...) – “svn add” works locally ● Even if you're a translator or a documenter.
  • 9. Code style is somewhat opinionated
  • 10. Your opinions don't matter (that much)
  • 12. Code is... Written once ● Read many, many times ●
  • 14. Comments should be correct!
  • 15. Fix problems not symptoms!
  • 17. Ticket #8182: Infinite loop iterating over PermWrapper The template code below will cause an infinite memory-eating loop if context_processors.auth is enabled. My main issue with that is that it was incredibly hard to debug for me, when I passed my own 'perms' queryset to a template. ... {% for perm in perms %} {% endfor %}
  • 18. django/contrib/auth/models.py | 22 ++++++++++++++++++++++ django/core/context_processors.py | 5 +++++ docs/authentication.txt | 11 ++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-)
  • 19.
  • 20. Where else does it happen?
  • 22. r7740 Author: mtredinnick Date: Thu Jun 26 11:01:21 2008 +1000 ... This is the same problem as [7597] but for values() field specifications, so this covers the second case where Django adds extra stuff to the select-clause.
  • 23. r8107 Author: mtredinnick Date: Mon Jul 28 04:16:17 2008 +1000 ... Fixed a missed case of promoting table joins when using disjunctive filters.
  • 24. r8783 Author: mtredinnick Date: Mon Sep 1 18:43:55 2008 -0700 ... Fixed an oversight when I first fixed ordering on nullable foreign keys.
  • 25. r8853 Author: mtredinnick Date: Tue Sep 2 06:52:07 2008 -0700 .... + def promote_alias_chain(self, chain,...): + """ + Walks along a chain of aliases, promoting the first + nullable join and any joins following that. If + 'must_promote' is True, all the aliases in + the chain are promoted. + """ + for alias in chain: + if self.promote_alias(alias, must_promote): + must_promote = True +
  • 27. The crowd is smarter than you! (the code mostly works)
  • 28. “Here is a trivial patch”
  • 29. Translation: “here are some bugs I thought you should have”
  • 30. Research is not a four letter word
  • 31. Django runs out-of-the-box on databases. Plural. – SQLite, MySQL, PostgreSQL, Oracle ● External backends, too ● Separate solution approach into pieces – It has a chance of working and here's a good start. – It has a perfect implementation.
  • 32. Django runs on multiple operating systems – Windows, Linux, Mac, ... ● Some things are hard – File handling, locking, ... – Character encoding ● Best defense is “don't do that”. ● Next best is a good offense (Research!)
  • 33. There are RFCs. – They apply in this universe. ● There are competing specs – Real world software beats paper ● There are contradictory requirements – Duh!
  • 34. Python needs research, too ● Pickle has mulitple protocols: – 0 and 2 are important ● __len__() is eeevviiilll – With good reason – Swallows exceptions ● TypeError ● Others (Python 2.3, Python 2.6.0 – 2.6.1) ● Unicode matters. So does UTF-8