SlideShare ist ein Scribd-Unternehmen logo
1 von 41
HANDS OFF!

Best Practices
for Code Handoffs

Naomi Dushay
ndushay
Stanford University Libraries
Code4Lib 2013
Code Handoffs Aren’t Like This
Code Handoffs
Code Handoffs
Code Handoffs
I’m supposed
                                          to take over
                                           WHAT???




http://www.flickr.com/photos/christinawelsh/3513582560/
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
“The ratio of time spent

 reading vs. writing
is well over
10:1”            Reading   Writing
– Clean Code
The Truck Test
“What if I were run over by a truck?”
Write code as if a stranger
will 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 than
you found it”

paraphrased from Clean Code
“The code needs to be kept
clean over time”

- Clean Code
It’s More Than Code
• Servers
• Configurations
• …
Servers
Consider Naming By Purpose




- bacon-dev:    development
- bacon-test:   testing
- bacon-prod:   production
Config Files
1. 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, …
# 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_set
coll_fld_val: bnf_images1

# log_dir: directory for log file
# (default is logs, relative to harvestdor gem path)
log_dir: logs
…
production config files
should not point to boxes
named "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 deployment scripts
-   … Parse MARC
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?
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 from
Sirsi, then
# Remove deleted records (per file of ids) from
index and update index (with marc records in file)
#
# updated for Naomi's FORK of solrmarc 2011-01-
23
# Naomi Dushay 2010-04-09
…
It’s More Than Code
• …
• Documentation
• …
Documentation isn’t
cheating.
Comments and Other
Documentation
•   Inform
•   Explain
•   Clarify
•   Warn
•   Need Maintenance!

Use a comment to explain non-
obvious, or tricky, or warnings
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?
To set up:
1. create a yml config file for your collection going to a
Solr index.
See config/bnf-images.yml for an example.
You will want to copy that file and change the following
settings:
1. coll_fld_val
2. log_name
3. default_set
4. blacklist or whitelist if you are using them
…
To run:
./bin/indexer config/(your coll).yml
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 to test code as is
  practical)
• …
• be viewed as code: readable,
  maintained …
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 addressed ASAP
KISS
K eep
It
S imple
S tupid
  http://www.flickr.com/photos/alexdram/3368983298/
DRY
D on’t
R epeat
Y ourself

       http://www.flickr.com/photos/deeanna/20357091/
Readable Code
• Follow Conventions
• Meaningful Names
  – Variable
  – Method
  – Class
  – File
• Small, single purpose methods
Cleverness that reduces
readability isn’t clever.
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
Errors and Corner Cases
• Exceptions, not Error Codes
• Test exception expectations

 it "should log a warning when it finds direct non-whitespace
text content" do
     x = stuff
     @logger.should_receive(:warn).with("Found direct text
content: 'mistake' in page geeby-deeby")
     @rsolr_client.should_receive(:add)
     @parser.parse(x)
   end
Thank You!

Weitere ähnliche Inhalte

Was ist angesagt?

Datat and donuts: how to write a data management plan
Datat and donuts: how to write a data management planDatat and donuts: how to write a data management plan
Datat and donuts: how to write a data management planC. Tobin Magle
 
Data Management for librarians
Data Management for librariansData Management for librarians
Data Management for librariansC. Tobin Magle
 
Natural Language Search in Solr
Natural Language Search in SolrNatural Language Search in Solr
Natural Language Search in SolrTommaso Teofili
 
Data Archiving and Sharing
Data Archiving and SharingData Archiving and Sharing
Data Archiving and SharingC. Tobin Magle
 
Powerpoint versiebeheer there is no such thing as a final version 1
Powerpoint versiebeheer there is no such thing as a final version 1Powerpoint versiebeheer there is no such thing as a final version 1
Powerpoint versiebeheer there is no such thing as a final version 1Hugo Besemer
 
Neural Architectures for Named Entity Recognition
Neural Architectures for Named Entity RecognitionNeural Architectures for Named Entity Recognition
Neural Architectures for Named Entity RecognitionRrubaa Panchendrarajan
 
Email Capture at the Radical Archives of Philadelphia
Email Capture at the Radical Archives of PhiladelphiaEmail Capture at the Radical Archives of Philadelphia
Email Capture at the Radical Archives of Philadelphiaarchivistsbeingawesome
 
Text prospecting
Text prospectingText prospecting
Text prospectingsingingfish
 
Names, Things, and Open Identifier Infrastructure: N2T and ARKs
Names, Things, and Open Identifier Infrastructure: N2T and ARKsNames, Things, and Open Identifier Infrastructure: N2T and ARKs
Names, Things, and Open Identifier Infrastructure: N2T and ARKsJohn Kunze
 
Building a real time, solr-powered recommendation engine
Building a real time, solr-powered recommendation engineBuilding a real time, solr-powered recommendation engine
Building a real time, solr-powered recommendation engineTrey Grainger
 
Rocky2010 roeder full_textbiomedicalliteratureprocesing
Rocky2010 roeder full_textbiomedicalliteratureprocesingRocky2010 roeder full_textbiomedicalliteratureprocesing
Rocky2010 roeder full_textbiomedicalliteratureprocesingChris Roeder
 
ANTLR - Writing Parsers the Easy Way
ANTLR - Writing Parsers the Easy WayANTLR - Writing Parsers the Easy Way
ANTLR - Writing Parsers the Easy WayMichael Yarichuk
 
score based ranking of documents
score based ranking of documentsscore based ranking of documents
score based ranking of documentsKriti Khanna
 
3.15.17 DSpace: How to Contribute Webinar Slides
3.15.17 DSpace: How to Contribute Webinar Slides3.15.17 DSpace: How to Contribute Webinar Slides
3.15.17 DSpace: How to Contribute Webinar SlidesDuraSpace
 
0x3E9 Ways To DIE
0x3E9 Ways To DIE0x3E9 Ways To DIE
0x3E9 Ways To DIEynvb
 
Apache Tika: 1 point Oh!
Apache Tika: 1 point Oh!Apache Tika: 1 point Oh!
Apache Tika: 1 point Oh!Chris Mattmann
 
Open nlp presentationss
Open nlp presentationssOpen nlp presentationss
Open nlp presentationssChandan Deb
 
AIMS Workshop Case Study 3: Arrangement and Description Case Study - Stephen ...
AIMS Workshop Case Study 3: Arrangement and Description Case Study - Stephen ...AIMS Workshop Case Study 3: Arrangement and Description Case Study - Stephen ...
AIMS Workshop Case Study 3: Arrangement and Description Case Study - Stephen ...AIMS_Archives
 

Was ist angesagt? (20)

Datat and donuts: how to write a data management plan
Datat and donuts: how to write a data management planDatat and donuts: how to write a data management plan
Datat and donuts: how to write a data management plan
 
Data Management for librarians
Data Management for librariansData Management for librarians
Data Management for librarians
 
Natural Language Search in Solr
Natural Language Search in SolrNatural Language Search in Solr
Natural Language Search in Solr
 
Data Archiving and Sharing
Data Archiving and SharingData Archiving and Sharing
Data Archiving and Sharing
 
Powerpoint versiebeheer there is no such thing as a final version 1
Powerpoint versiebeheer there is no such thing as a final version 1Powerpoint versiebeheer there is no such thing as a final version 1
Powerpoint versiebeheer there is no such thing as a final version 1
 
NAMED ENTITY RECOGNITION
NAMED ENTITY RECOGNITIONNAMED ENTITY RECOGNITION
NAMED ENTITY RECOGNITION
 
Neural Architectures for Named Entity Recognition
Neural Architectures for Named Entity RecognitionNeural Architectures for Named Entity Recognition
Neural Architectures for Named Entity Recognition
 
Email Capture at the Radical Archives of Philadelphia
Email Capture at the Radical Archives of PhiladelphiaEmail Capture at the Radical Archives of Philadelphia
Email Capture at the Radical Archives of Philadelphia
 
Text prospecting
Text prospectingText prospecting
Text prospecting
 
Reproducible research
Reproducible researchReproducible research
Reproducible research
 
Names, Things, and Open Identifier Infrastructure: N2T and ARKs
Names, Things, and Open Identifier Infrastructure: N2T and ARKsNames, Things, and Open Identifier Infrastructure: N2T and ARKs
Names, Things, and Open Identifier Infrastructure: N2T and ARKs
 
Building a real time, solr-powered recommendation engine
Building a real time, solr-powered recommendation engineBuilding a real time, solr-powered recommendation engine
Building a real time, solr-powered recommendation engine
 
Rocky2010 roeder full_textbiomedicalliteratureprocesing
Rocky2010 roeder full_textbiomedicalliteratureprocesingRocky2010 roeder full_textbiomedicalliteratureprocesing
Rocky2010 roeder full_textbiomedicalliteratureprocesing
 
ANTLR - Writing Parsers the Easy Way
ANTLR - Writing Parsers the Easy WayANTLR - Writing Parsers the Easy Way
ANTLR - Writing Parsers the Easy Way
 
score based ranking of documents
score based ranking of documentsscore based ranking of documents
score based ranking of documents
 
3.15.17 DSpace: How to Contribute Webinar Slides
3.15.17 DSpace: How to Contribute Webinar Slides3.15.17 DSpace: How to Contribute Webinar Slides
3.15.17 DSpace: How to Contribute Webinar Slides
 
0x3E9 Ways To DIE
0x3E9 Ways To DIE0x3E9 Ways To DIE
0x3E9 Ways To DIE
 
Apache Tika: 1 point Oh!
Apache Tika: 1 point Oh!Apache Tika: 1 point Oh!
Apache Tika: 1 point Oh!
 
Open nlp presentationss
Open nlp presentationssOpen nlp presentationss
Open nlp presentationss
 
AIMS Workshop Case Study 3: Arrangement and Description Case Study - Stephen ...
AIMS Workshop Case Study 3: Arrangement and Description Case Study - Stephen ...AIMS Workshop Case Study 3: Arrangement and Description Case Study - Stephen ...
AIMS Workshop Case Study 3: Arrangement and Description Case Study - Stephen ...
 

Ähnlich wie "Hands Off! Best Practices for Code Hand Offs"

The Final Frontier
The Final FrontierThe Final Frontier
The Final FrontierjClarity
 
Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Red Gate Software
 
Navigating the Mess of a Shared drive Migration to SharePoint
Navigating the Mess of a Shared drive Migration to SharePointNavigating the Mess of a Shared drive Migration to SharePoint
Navigating the Mess of a Shared drive Migration to SharePointJoanne Klein
 
Static Code Analysis and AutoLint
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLintLeander Hasty
 
Designing and Implementing Search Solutions
Designing and Implementing Search SolutionsDesigning and Implementing Search Solutions
Designing and Implementing Search SolutionsFindwise
 
Software Analytics - Achievements and Challenges
Software Analytics - Achievements and ChallengesSoftware Analytics - Achievements and Challenges
Software Analytics - Achievements and ChallengesTao Xie
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...panagenda
 
Entomology 101
Entomology 101Entomology 101
Entomology 101snyff
 
Silicon Valley Code Camp 2016 - MongoDB in production
Silicon Valley Code Camp 2016 - MongoDB in productionSilicon Valley Code Camp 2016 - MongoDB in production
Silicon Valley Code Camp 2016 - MongoDB in productionDaniel Coupal
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandonMaslowB
 
Team-based Development with Version Control
Team-based Development with Version ControlTeam-based Development with Version Control
Team-based Development with Version ControlRed Gate Software
 
Software Analytics: Data Analytics for Software Engineering and Security
Software Analytics: Data Analytics for Software Engineering and SecuritySoftware Analytics: Data Analytics for Software Engineering and Security
Software Analytics: Data Analytics for Software Engineering and SecurityTao Xie
 
DEEPSEC 2013: Malware Datamining And Attribution
DEEPSEC 2013: Malware Datamining And AttributionDEEPSEC 2013: Malware Datamining And Attribution
DEEPSEC 2013: Malware Datamining And AttributionMichael Boman
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional ProgrammerDave Cross
 
IT 150 Agenda for 11-14-16.pptx
IT 150 Agenda for 11-14-16.pptxIT 150 Agenda for 11-14-16.pptx
IT 150 Agenda for 11-14-16.pptxMattMarino13
 
Babysitting your orm essenmacher, adam
Babysitting your orm   essenmacher, adamBabysitting your orm   essenmacher, adam
Babysitting your orm essenmacher, adamAdam Essenmacher
 
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malwareDefcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malwareDaveEdwards12
 
WTF is Penetration Testing v.2
WTF is Penetration Testing v.2WTF is Penetration Testing v.2
WTF is Penetration Testing v.2Scott Sutherland
 

Ähnlich wie "Hands Off! Best Practices for Code Hand Offs" (20)

The Final Frontier
The Final FrontierThe Final Frontier
The Final Frontier
 
Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City Part of the DLM story: Get your Database under Source Control - SQL In The City
Part of the DLM story: Get your Database under Source Control - SQL In The City
 
Navigating the Mess of a Shared drive Migration to SharePoint
Navigating the Mess of a Shared drive Migration to SharePointNavigating the Mess of a Shared drive Migration to SharePoint
Navigating the Mess of a Shared drive Migration to SharePoint
 
Static Code Analysis and AutoLint
Static Code Analysis and AutoLintStatic Code Analysis and AutoLint
Static Code Analysis and AutoLint
 
Designing and Implementing Search Solutions
Designing and Implementing Search SolutionsDesigning and Implementing Search Solutions
Designing and Implementing Search Solutions
 
Software Analytics - Achievements and Challenges
Software Analytics - Achievements and ChallengesSoftware Analytics - Achievements and Challenges
Software Analytics - Achievements and Challenges
 
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
Way #5 Don’t end up in a ditch because you weren’t aware of roadblocks in you...
 
Entomology 101
Entomology 101Entomology 101
Entomology 101
 
Software Design
Software DesignSoftware Design
Software Design
 
Silicon Valley Code Camp 2016 - MongoDB in production
Silicon Valley Code Camp 2016 - MongoDB in productionSilicon Valley Code Camp 2016 - MongoDB in production
Silicon Valley Code Camp 2016 - MongoDB in production
 
Metaprogramming by brandon
Metaprogramming by brandonMetaprogramming by brandon
Metaprogramming by brandon
 
Team-based Development with Version Control
Team-based Development with Version ControlTeam-based Development with Version Control
Team-based Development with Version Control
 
Software Analytics: Data Analytics for Software Engineering and Security
Software Analytics: Data Analytics for Software Engineering and SecuritySoftware Analytics: Data Analytics for Software Engineering and Security
Software Analytics: Data Analytics for Software Engineering and Security
 
DEEPSEC 2013: Malware Datamining And Attribution
DEEPSEC 2013: Malware Datamining And AttributionDEEPSEC 2013: Malware Datamining And Attribution
DEEPSEC 2013: Malware Datamining And Attribution
 
The Professional Programmer
The Professional ProgrammerThe Professional Programmer
The Professional Programmer
 
IT 150 Agenda for 11-14-16.pptx
IT 150 Agenda for 11-14-16.pptxIT 150 Agenda for 11-14-16.pptx
IT 150 Agenda for 11-14-16.pptx
 
Babysitting your orm essenmacher, adam
Babysitting your orm   essenmacher, adamBabysitting your orm   essenmacher, adam
Babysitting your orm essenmacher, adam
 
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malwareDefcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
Defcon 22-wesley-mc grew-instrumenting-point-of-sale-malware
 
Enterprise PHP
Enterprise PHPEnterprise PHP
Enterprise PHP
 
WTF is Penetration Testing v.2
WTF is Penetration Testing v.2WTF is Penetration Testing v.2
WTF is Penetration Testing v.2
 

"Hands Off! Best Practices for Code Hand Offs"

  • 1. HANDS OFF! Best Practices for Code Handoffs Naomi Dushay ndushay Stanford University Libraries Code4Lib 2013
  • 6. I’m supposed to take over WHAT??? http://www.flickr.com/photos/christinawelsh/3513582560/
  • 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. “The ratio of time spent reading vs. writing is well over 10:1” Reading Writing – Clean Code
  • 9. The Truck Test “What if I were run over by a truck?”
  • 10. Write code as if a stranger will need to understand it.
  • 11. My code doesn’t have to age long for me to be a stranger.
  • 12. The Boy Scout Rule “Leave the code cleaner than you found it” paraphrased from Clean Code
  • 13. “The code needs to be kept clean over time” - Clean Code
  • 14. It’s More Than Code • Servers • Configurations • …
  • 15. Servers Consider Naming By Purpose - bacon-dev: development - bacon-test: testing - bacon-prod: production
  • 16. Config Files 1. 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. # 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_set coll_fld_val: bnf_images1 # log_dir: directory for log file # (default is logs, relative to harvestdor gem path) log_dir: logs …
  • 18. production config files should not point to boxes named "dev" or "test”
  • 19. It’s More Than Code • … • Tools Chosen – Deployment – Automated Monitoring – Issue Tracking – User Feedback • …
  • 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. 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. It’s More Than Code • … • Scripts • …
  • 23. Scripts • Named Well – “harvest_set” vs. “get” • Begin With Comments Explaining Purpose, Arguments Expected, Results
  • 24. #! /bin/bash # pullThenIndexSirsiIncr.sh # Pull over the latest incremental update files from Sirsi, then # Remove deleted records (per file of ids) from index and update index (with marc records in file) # # updated for Naomi's FORK of solrmarc 2011-01- 23 # Naomi Dushay 2010-04-09 …
  • 25. It’s More Than Code • … • Documentation • …
  • 27. Comments and Other Documentation • Inform • Explain • Clarify • Warn • Need Maintenance! Use a comment to explain non- obvious, or tricky, or warnings
  • 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. To set up: 1. create a yml config file for your collection going to a Solr index. See config/bnf-images.yml for an example. You will want to copy that file and change the following settings: 1. coll_fld_val 2. log_name 3. default_set 4. blacklist or whitelist if you are using them … To run: ./bin/indexer config/(your coll).yml
  • 30. It’s More Than Code • … • TESTS • …
  • 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. Tests Should • … • be viewed as code: readable, maintained …
  • 33. It’s More Than Code • … • Continuous Integration • …
  • 34. Continuous Integration • Builds Should – Run tests – Run test coverage – Be triggered by new code • Failures Should – Be addressed ASAP
  • 35. KISS K eep It S imple S tupid http://www.flickr.com/photos/alexdram/3368983298/
  • 36. DRY D on’t R epeat Y ourself http://www.flickr.com/photos/deeanna/20357091/
  • 37. Readable Code • Follow Conventions • Meaningful Names – Variable – Method – Class – File • Small, single purpose methods
  • 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. Errors and Corner Cases • Exceptions, not Error Codes • Test exception expectations it "should log a warning when it finds direct non-whitespace text content" do x = stuff @logger.should_receive(:warn).with("Found direct text content: 'mistake' in page geeby-deeby") @rsolr_client.should_receive(:add) @parser.parse(x) end