HANDS OFF!Best Practicesfor Code HandoffsNaomi DushayndushayStanford University LibrariesCode4Lib 2013
Code Handoffs Aren’t Like This
Code Handoffs
Code Handoffs
Code Handoffs
I’m supposed                                          to take over                                           WHAT???http:/...
Sources    Clean Code: A Handbook of Agile    Software Craftsmanship – Robert    Martin, Prentice Hall, 2008    Refactorin...
“The ratio of time spent reading vs. writingis well over10:1”            Reading   Writing– Clean Code
The Truck Test“What if I were run over by a truck?”
Write code as if a strangerwill need to understand it.
My code doesn’t have to age long for me to        be a stranger.
The Boy Scout Rule“Leave the code cleaner thanyou found it”paraphrased from Clean Code
“The code needs to be keptclean over time”- Clean Code
It’s More Than Code• Servers• Configurations• …
ServersConsider Naming By Purpose- bacon-dev:    development- bacon-test:   testing- bacon-prod:   production
Config Files1. Inline documentation on what config   file expects  1. purpose/use of value  2. syntax expected (examples!)...
# Settings for BnF Images# You will want to copy this file and change the following settings:# 1. coll_fld_val# 2. log_nam...
production config filesshould not point to boxesnamed "dev" or "test”
It’s More Than Code• …• Tools Chosen  – Deployment  – Automated Monitoring  – Issue Tracking  – User Feedback• …
It’s the Tools You Choose“I’m probably not the first person to …”-   … Parse XML-   … work with jpeg2000-   … Write deploy...
When NOT to Roll Your Own- Is there already local expertise?- What solutions have your colleagues adopted?- Are there exis...
It’s More Than Code• …• Scripts• …
Scripts• Named Well  – “harvest_set” vs. “get”• Begin With Comments Explaining  Purpose, Arguments Expected, Results
#! /bin/bash# pullThenIndexSirsiIncr.sh# Pull over the latest incremental update files fromSirsi, then# Remove deleted rec...
It’s More Than Code• …• Documentation• …
Documentation isn’tcheating.
Comments and OtherDocumentation•   Inform•   Explain•   Clarify•   Warn•   Need Maintenance!Use a comment to explain non-o...
README•   What is this?•   How do I install it?•   How do I get it running?•   How do I use it?    – Examples for most com...
To set up:1. create a yml config file for your collection going to aSolr index.See config/bnf-images.yml for an example.Yo...
It’s More Than Code• …• TESTS• …
Tests Should• demonstrate how code should work• be fast• contain their test data (or have it in the  test file, as close t...
Tests Should• …• be viewed as code:  readable, maintained …
It’s More Than Code• …• Continuous Integration• …
Continuous Integration• Builds Should  – Run tests  – Run test coverage  – Be triggered by new code• Failures Should  – Be...
KISSK eepItS impleS tupid  http://www.flickr.com/photos/alexdram/3368983298/
DRYD on’tR epeatY ourself       http://www.flickr.com/photos/deeanna/20357091/
Readable Code• Follow Conventions• Meaningful Names  – Variable  – Method  – Class  – File• Small, single purpose methods
Cleverness that reducesreadability isn’t clever.
Sources    Clean Code: A Handbook of Agile    Software Craftsmanship – Robert    Martin, Prentice Hall, 2008    Refactorin...
Errors and Corner Cases• Exceptions, not Error Codes• Test exception expectations it "should log a warning when it finds d...
Thank You!
Upcoming SlideShare
Loading in...5
×

"Hands Off! Best Practices for Code Hand Offs"

527

Published on

B

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
527
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
8
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

"Hands Off! Best Practices for Code Hand Offs"

  1. 1. HANDS OFF!Best Practicesfor Code HandoffsNaomi DushayndushayStanford University LibrariesCode4Lib 2013
  2. 2. Code Handoffs Aren’t Like This
  3. 3. Code Handoffs
  4. 4. Code Handoffs
  5. 5. Code Handoffs
  6. 6. I’m supposed to take over WHAT???http://www.flickr.com/photos/christinawelsh/3513582560/
  7. 7. Sources Clean Code: A Handbook of Agile Software Craftsmanship – Robert Martin, Prentice Hall, 2008 Refactoring: Improving the Design of Existing Code – Martin Fowler, …, Addison-Wesley Professional, 1999
  8. 8. “The ratio of time spent reading vs. writingis well over10:1” Reading Writing– Clean Code
  9. 9. The Truck Test“What if I were run over by a truck?”
  10. 10. Write code as if a strangerwill need to understand it.
  11. 11. My code doesn’t have to age long for me to be a stranger.
  12. 12. The Boy Scout Rule“Leave the code cleaner thanyou found it”paraphrased from Clean Code
  13. 13. “The code needs to be keptclean over time”- Clean Code
  14. 14. It’s More Than Code• Servers• Configurations• …
  15. 15. ServersConsider Naming By Purpose- bacon-dev: development- bacon-test: testing- bacon-prod: production
  16. 16. Config Files1. Inline documentation on what config file expects 1. purpose/use of value 2. syntax expected (examples!)2. Try to group settings likely to vary 1. e.g. server name, web service url, …
  17. 17. # Settings for BnF Images# You will want to copy this file and change the following settings:# 1. coll_fld_val# 2. log_name# 3. default_set (in OAI harvesting params section)# 4. blacklist or whitelist if you are using them# the value of the "collection" field in the Solr document# (a way to query this OAI harvest only); default is the default_setcoll_fld_val: bnf_images1# log_dir: directory for log file# (default is logs, relative to harvestdor gem path)log_dir: logs…
  18. 18. production config filesshould not point to boxesnamed "dev" or "test”
  19. 19. It’s More Than Code• …• Tools Chosen – Deployment – Automated Monitoring – Issue Tracking – User Feedback• …
  20. 20. It’s the Tools You Choose“I’m probably not the first person to …”- … Parse XML- … work with jpeg2000- … Write deployment scripts- … Parse MARC
  21. 21. When NOT to Roll Your Own- Is there already local expertise?- What solutions have your colleagues adopted?- Are there existing tools for this work in this context?- Which solutions are widely adopted?- Which solutions are under active development?
  22. 22. It’s More Than Code• …• Scripts• …
  23. 23. Scripts• Named Well – “harvest_set” vs. “get”• Begin With Comments Explaining Purpose, Arguments Expected, Results
  24. 24. #! /bin/bash# pullThenIndexSirsiIncr.sh# Pull over the latest incremental update files fromSirsi, then# Remove deleted records (per file of ids) fromindex and update index (with marc records in file)## updated for Naomis FORK of solrmarc 2011-01-23# Naomi Dushay 2010-04-09…
  25. 25. It’s More Than Code• …• Documentation• …
  26. 26. Documentation isn’tcheating.
  27. 27. Comments and OtherDocumentation• Inform• Explain• Clarify• Warn• Need Maintenance!Use a comment to explain non-obvious, or tricky, or warnings
  28. 28. README• What is this?• How do I install it?• How do I get it running?• How do I use it? – Examples for most common cases• How do I deploy it?• Where should I look for more info?
  29. 29. To set up:1. create a yml config file for your collection going to aSolr index.See config/bnf-images.yml for an example.You will want to copy that file and change the followingsettings:1. coll_fld_val2. log_name3. default_set4. blacklist or whitelist if you are using them…To run:./bin/indexer config/(your coll).yml
  30. 30. It’s More Than Code• …• TESTS• …
  31. 31. Tests Should• demonstrate how code should work• be fast• contain their test data (or have it in the test file, as close to test code as is practical)• …• be viewed as code: readable, maintained …
  32. 32. Tests Should• …• be viewed as code: readable, maintained …
  33. 33. It’s More Than Code• …• Continuous Integration• …
  34. 34. Continuous Integration• Builds Should – Run tests – Run test coverage – Be triggered by new code• Failures Should – Be addressed ASAP
  35. 35. KISSK eepItS impleS tupid http://www.flickr.com/photos/alexdram/3368983298/
  36. 36. DRYD on’tR epeatY ourself http://www.flickr.com/photos/deeanna/20357091/
  37. 37. Readable Code• Follow Conventions• Meaningful Names – Variable – Method – Class – File• Small, single purpose methods
  38. 38. Cleverness that reducesreadability isn’t clever.
  39. 39. Sources Clean Code: A Handbook of Agile Software Craftsmanship – Robert Martin, Prentice Hall, 2008 Refactoring: Improving the Design of Existing Code – Martin Fowler, …, Addison-Wesley Professional, 1999
  40. 40. Errors and Corner Cases• Exceptions, not Error Codes• Test exception expectations it "should log a warning when it finds direct non-whitespacetext content" do x = stuff @logger.should_receive(:warn).with("Found direct textcontent: mistake in page geeby-deeby") @rsolr_client.should_receive(:add) @parser.parse(x) end
  41. 41. Thank You!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×