Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Code quality. Patch quality


Published on

Getting the basics right when starting to contribute patches to open source. The patches don't have to be perfect, but you should tuck your shirt in and use neat handwriting to get in the door.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Code quality. Patch quality

  1. 1. Code quality Patch qualityMalcolm
  2. 2. Code Quality Matters
  3. 3. “Have you ever written a librarybefore? Its like people seeing you inyour underwear. You gotta makesure its clean.”
  4. 4. Do The Basics Properly
  5. 5. Yr Doin It Wrng!● If the word “print” is still in your patch – Similarly for the phrase “import pdb”
  6. 6. Yr Doin It Wrng!● If you dont have a test or a really good reason – Your reason is never going to be good enough. – Fail before; pass afterwards
  7. 7. Yr Doin It Wrng!● If you think “PEP 8” is the name of a new energy drink
  8. 8. How Hard Can It Be(tm)?● Theyre 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 youre a translator or a documenter.
  9. 9. Code style is somewhat opinionated
  10. 10. Your opinions dont matter (that much)
  11. 11. Read the contributing document
  12. 12. Code is...Written once●Read many, many times●
  13. 13. Comments should last
  14. 14. Comments should be correct!
  15. 15. Fix problems not symptoms!
  16. 16. Symptom fixing...
  17. 17. Ticket #8182: Infinite loop iterating over PermWrapperThe template code below will cause an infinitememory-eating loop if context_processors.auth isenabled. My main issue with that is that it wasincredibly hard to debug for me, when I passedmy own perms queryset to a template....{% for perm in perms %}{% endfor %}
  18. 18. django/contrib/auth/ | 22 ++++++++++++++++++++++django/core/ | 5 +++++docs/authentication.txt | 11 ++++++++---3 files changed, 35 insertions(+), 3 deletions(-)
  19. 19. Where else does it happen?
  20. 20. Warning: may be hard!
  21. 21. r7740Author: mtredinnickDate: Thu Jun 26 11:01:21 2008 +1000...This is the same problem as [7597]but for values() fieldspecifications, so this covers thesecond case where Django adds extrastuff to the select-clause.
  22. 22. r8107Author: mtredinnickDate: Mon Jul 28 04:16:17 2008 +1000...Fixed a missed case of promoting tablejoins when using disjunctive filters.
  23. 23. r8783Author: mtredinnickDate: Mon Sep 1 18:43:55 2008 -0700...Fixed an oversight when I first fixedordering on nullable foreign keys.
  24. 24. r8853Author: mtredinnickDate: 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+
  25. 25. Know your limitations
  26. 26. The crowd is smarter than you! (the code mostly works)
  27. 27. “Here is a trivial patch”
  28. 28. Translation: “here are some bugs I thought you should have”
  29. 29. Research is not a four letter word
  30. 30. ● 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 heres a good start. – It has a perfect implementation.
  31. 31. ● Django runs on multiple operating systems – Windows, Linux, Mac, ...● Some things are hard – File handling, locking, ... – Character encoding● Best defense is “dont do that”.● Next best is a good offense (Research!)
  32. 32. ● There are RFCs. – They apply in this universe.● There are competing specs – Real world software beats paper● There are contradictory requirements – Duh!
  33. 33. 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
  34. 34. Always contribute!Best beats perfect