SlideShare a Scribd company logo
You and your code
Charles Sutton
School of Informatics
University of Edinburgh
Why write programs?
• Want to know if your idea actually works!
• Typical case rather than worst case
• Especially true for “hard fields”
• Artificial intelligence: All interesting
problems
• Compilers / Program analysis: Most
problems Turing-complete
• Machine learning: No free lunch theorem
• You don’t really understand an algorithm
unless you can code it
• Feedback from error analysis drives new ideas
Theorists should program, too
Implementing your own algorithm is a good
way of checking your work. If you aren't
implementing your algorithm, arguably you're
skipping a key step in checking your results.
--Michael Mitzenmacher
http://mybiasedcoin.blogspot.com/2008/11/bugs.html
But don’t listen to me (I’m not a theorist):
Also, avoid attempting to prove false
statements!
Software Engineering
• Software engineering is a rich area of
research
• Commercial software development is
• Expensive
• Error-prone
• Unpredictable
• Incredibly important
• Many high-profile software failures, often
caused by small looking bugs
Methodology
• Much (not all) SE research focuses on
methodology
• Requirements
• Architecture
• Design
• Code
• The first three all have a documents attached.
The code is expected to be heavily
documented.
Why all this work?
• Customers do not know requirements initially
• Requirements change rapidly
• It is essential but often very hard to
understand the domain
• Teams contain dozens or hundreds of
developers, worldwide, over many years
• High turnover of software developers
• Documentation needed to avoid argument.
• Most of the cost is in maintenance
[adapted from Perdita Stevens]
Extreme Programming
• A reaction to the high overhead, bureaucracy
of traditional approach (all those documents)
• Idea is to be agile
• Do the simplest thing that will work
• Test-driven development
• Unit tests
• Pair programming
• Focus on refactoring
• Emphasis on quickly getting running code
Extreme Programming
• However, researchers lack the resources to do this all
the way
• Some ideas useful to pull out (unit tests definitely,
refactoring sometimes)
More info:
http://xprogramming.com/
Books by Kent Beck, Martin Fowler
These measures try to ensure product quality.
When you are a researcher, it is different:
The software is not your product
Your product is knowledge
• New algorithms
• New theorems
• New empirical characterization
of existing algorithms
4 Principles of Research Code
1.Your code is a means to an end.
Don’t really throw it away.
Disk is cheap; save everything.
Once the paper is done, you will throw it away.
4 Principles of Research Code
2. Unless you succeed.
Then everyone will want to try out your stuff.
Success is a pain in the a@#!
If you are lucky,
you will start getting emails from
(PhD students of) famous professors.
4 Principles of Research Code
3. You need to be able to trust your results.
You do not want to find a bug in your
baselines after you publish!
4 Principles of Research Code
4. You need a bespoke set of tools.
Invent as little as possible (but no less!)
This is true both in your code and in your
intellectual work.
N.B. All of these principles contradict each other.
Welcome to the real world!
Corollaries
• These principles should guide you in writing
code for your research
• Except that they contradict each other
• So let’s see how the principles are reflected in
real-world practice
Code is a means to an end
• Optimize for your time
• Except when your research requires your
code to be efficient (this happens)
• Efficient code can be competitive advantage
• Think of documentation as notes to yourself
• Push as much as documentation as
possible into identifier names
• Always ask why you are writing the code...
How will this fit into the eventual paper
Code is a means to an end
• Do not think that you know now where you will
end up
• Optimize also for flexibility
• The only design pattern that I like is the
strategy pattern
• Wherever possible, think about where you
might want to be clever later
• Design for your later cleverness
• You care about bugs that affect your
experimental results, not really about other
bugs
Unless you succeed
• Commit to reproduceable research
• Bench scientists have a lab notebook
• You need the equivalent
• You must use version control!
• Organization of files, directories
• “Connect” your code to the figures in the paper
Version Control
• Many examples: RCS, SCCS, CVS, SVN, hg,
git, arch
• For new projects you should use at least
Subversion, consider the distributed system
(e.g., hg, git)
• I version control everything that I care about
• My code, my research publications, my
personal bib file, my Web site
• If you ran an experiment on May 13 that you
need to reproduce two years later, reproduce
that exact state
Version Control
• Every file that is
• Text
• Related to your research
• Cannot be reproduced automatically
• ...should be under version control
• To do otherwise is courting disaster
Keep track of parameters
• Your experiments will have many parameters
to tune
• Which schedule algorithm you used
• Max queue size
• Which heuristics for X, Y, Z
• Learning rate
• Make these parameters of the “experiment
running scripts”
• Keep track of them in an organized way
Connecting your paper to your results
directories
• Bench scientists have a lab notebook. You need something similar
• You need a system where
• if you open up your paper file a year later
• you will know how to rerun all the code needed for Figure 3
• Key idea: Generate figures automatically via script
• Then you just need a map Figure => script file
• Could use text file
• Comments in LateX code
• Also need the version of your code
• Keep tarball
• Use version control
Example System
To start an experiment, run a shell script
sh scripts/test-tiny-heuristic.sh
This script contains the parameters of the experiment:
scripts/test-tiny-heuristic.sh
DIR=results/tiny-heuristic/airlockF/al2.7/
java uk.ac.ed.inf.csutton.HalMain 
--open-airlock FALSE 
--alpha 2.7 
--output-dir $DIR
Automating your driver
script
• Lots of times you will need to run a “parameter
sweep”
• Helpful to have a “driver script” that runs through
the parameter grid
• Interacts well with grid/cloud computing: Run
every parameter setting in parallel
Principles of experiment
running scripts
• 1. Automate as much as possible
• 2. Record as much as possible
• Text files are your friend!
• Some of my fancy systems friends use
databases
• Makefile’s are good for recording
preprocessing steps
• (use the filesystem to keep records for you)
• Another possibility (haven’t tried it): http://
neuralensemble.org/trac/sumatra
hg/
projects/
qneta/
papers/
nips10/
icml11/
experiments/
synthetic-expt/
code/
scripts/
real-data-expt/
results/
synthetic-expt/
graphs/
real-data-expt/
graphs/
Notes about dir structure
• Typically for me a “project” is a paper or two
worth of work. (May take more than one
submission.)
• Never quite sure where to put the results/
directory. Parallel to experiment dir?
Underneath? Outside of hg altogether
• Important: Everything in results/ automatically
generated
• code/ ==> implementation of the algorithms
• scripts/ ==> stuff that only matters for the
experiments I happened to run
Notes
• There are other ways to do this
• I can never decide myself what’s best
• The principle is:
• If a year from now you look at the results file
alone you can tell:
• What code you used to generate it
• With what parameters
Trust your results
• Unit tests are great
• Test a small part of your code
• The test code itself checks success, not
human
• They should be fast to run, so you can run
them after every major change
• Nip regression in the bud
Testing is hard
• Testing and debugging research code can
require ingenuity
• Often your algorithm is heuristic or
approximate
• If you expect it to fail 10% of the time, how
can you be sure it’s correct?
• Especially true in machine learning, etc
Creative testing
• Look for special cases
• Maybe if you set alpha = 0, your method
reduces to a simpler one
• Special case on which your approximation is
exact? e.g., Beam search on small state
space
• There’s more than one way to do it
• e.g., Check different approximation
algorithms against each other
Bespoke tools
OS, Standard library, etc
Domain frameworks: BLAS, Matlab, R, etc.
Your personal shared code
Research area A Research area B
Experiment
1
Experiment
2
Experiment
3
Experiment
4
Making a toolkit
• TinyOS http://www.tinyos.net/
• Jikes (research Java compiler) http://
jikes.sourceforge.net/
• SVMlight http://svmlight.joachims.org/
(machine learning)
• Festival (speech synthesis) http://
www.cstr.ed.ac.uk/projects/festival/
• Moses (machine translation) http://
www.statmt.org/moses/
Many times you see researchers making
software that many people use. A few examples:
Making a toolkit
• People more likely to use your ideas if they
don’t have to implement them
• Shared infrastructure: you can try ideas
quickly
• Other people can add components which you
then use
• Fame
Why would you do this? Seems to violate
every principle so far.
In any case, this is calculated risk.
Summary
• Remember the four principles
• Your code is an investment of your time
• Too little: Can’t trust results, Can’t reproduce
• Too much: You try too few new ideas
• Writing efficient code can give you a
competitive advantage as a researcher
• Good luck finding the balance!

More Related Content

Similar to You and your code.pdf

An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
Blue Elephant Consulting
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tipsBill Buchan
 
Extreme Programming (XP): Revisted
Extreme Programming (XP): RevistedExtreme Programming (XP): Revisted
Extreme Programming (XP): Revisted
Mike Harris
 
Mr. Burhan Khalid - secure dev.
Mr. Burhan Khalid - secure dev.Mr. Burhan Khalid - secure dev.
Mr. Burhan Khalid - secure dev.nooralmousa
 
Secured Development
Secured DevelopmentSecured Development
Secured Development
Burhan Khalid
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 
PHP - Introduction to PHP Bugs - Debugging
PHP -  Introduction to  PHP Bugs - DebuggingPHP -  Introduction to  PHP Bugs - Debugging
PHP - Introduction to PHP Bugs - Debugging
Vibrant Technologies & Computers
 
Building a custom cms with django
Building a custom cms with djangoBuilding a custom cms with django
Building a custom cms with django
Yann Malet
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
Inductive Automation
 
Case study
Case studyCase study
Case study
karan saini
 
QA and scrum
QA and scrumQA and scrum
QA and scrum
clintonbosch
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
Benjamin Baumann
 
Random thoughts and dev practices / advices to build a great product
Random thoughts and dev practices / advices to build a great productRandom thoughts and dev practices / advices to build a great product
Random thoughts and dev practices / advices to build a great product
Guillaume POTIER
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to code
Alan Richardson
 
Improving the accuracy and reliability of data analysis code
Improving the accuracy and reliability of data analysis codeImproving the accuracy and reliability of data analysis code
Improving the accuracy and reliability of data analysis code
Johan Carlin
 
It's XP Stupid (2019)
It's XP Stupid (2019)It's XP Stupid (2019)
It's XP Stupid (2019)
Mike Harris
 
Software testing
Software testingSoftware testing
Software testing
Nico Heidtke
 
Reproducible research concepts and tools
Reproducible research concepts and toolsReproducible research concepts and tools
Reproducible research concepts and tools
C. Tobin Magle
 

Similar to You and your code.pdf (20)

An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1An Introduction To Software Development - Test Driven Development, Part 1
An Introduction To Software Development - Test Driven Development, Part 1
 
Dev buchan 30 proven tips
Dev buchan 30 proven tipsDev buchan 30 proven tips
Dev buchan 30 proven tips
 
Extreme Programming (XP): Revisted
Extreme Programming (XP): RevistedExtreme Programming (XP): Revisted
Extreme Programming (XP): Revisted
 
Mr. Burhan Khalid - secure dev.
Mr. Burhan Khalid - secure dev.Mr. Burhan Khalid - secure dev.
Mr. Burhan Khalid - secure dev.
 
Secured Development
Secured DevelopmentSecured Development
Secured Development
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
PHP - Introduction to PHP Bugs - Debugging
PHP -  Introduction to  PHP Bugs - DebuggingPHP -  Introduction to  PHP Bugs - Debugging
PHP - Introduction to PHP Bugs - Debugging
 
Building a custom cms with django
Building a custom cms with djangoBuilding a custom cms with django
Building a custom cms with django
 
Design Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best PracticesDesign Like a Pro: Scripting Best Practices
Design Like a Pro: Scripting Best Practices
 
Case study
Case studyCase study
Case study
 
QA and scrum
QA and scrumQA and scrum
QA and scrum
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Eurosport's Kodakademi #2
Eurosport's Kodakademi #2Eurosport's Kodakademi #2
Eurosport's Kodakademi #2
 
Random thoughts and dev practices / advices to build a great product
Random thoughts and dev practices / advices to build a great productRandom thoughts and dev practices / advices to build a great product
Random thoughts and dev practices / advices to build a great product
 
If you want to automate, you learn to code
If you want to automate, you learn to codeIf you want to automate, you learn to code
If you want to automate, you learn to code
 
Improving the accuracy and reliability of data analysis code
Improving the accuracy and reliability of data analysis codeImproving the accuracy and reliability of data analysis code
Improving the accuracy and reliability of data analysis code
 
It's XP Stupid (2019)
It's XP Stupid (2019)It's XP Stupid (2019)
It's XP Stupid (2019)
 
Software testing
Software testingSoftware testing
Software testing
 
Reproducible research concepts and tools
Reproducible research concepts and toolsReproducible research concepts and tools
Reproducible research concepts and tools
 

Recently uploaded

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 

Recently uploaded (20)

Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 

You and your code.pdf

  • 1. You and your code Charles Sutton School of Informatics University of Edinburgh
  • 2. Why write programs? • Want to know if your idea actually works! • Typical case rather than worst case • Especially true for “hard fields” • Artificial intelligence: All interesting problems • Compilers / Program analysis: Most problems Turing-complete • Machine learning: No free lunch theorem • You don’t really understand an algorithm unless you can code it • Feedback from error analysis drives new ideas
  • 3. Theorists should program, too Implementing your own algorithm is a good way of checking your work. If you aren't implementing your algorithm, arguably you're skipping a key step in checking your results. --Michael Mitzenmacher http://mybiasedcoin.blogspot.com/2008/11/bugs.html But don’t listen to me (I’m not a theorist): Also, avoid attempting to prove false statements!
  • 4. Software Engineering • Software engineering is a rich area of research • Commercial software development is • Expensive • Error-prone • Unpredictable • Incredibly important • Many high-profile software failures, often caused by small looking bugs
  • 5. Methodology • Much (not all) SE research focuses on methodology • Requirements • Architecture • Design • Code • The first three all have a documents attached. The code is expected to be heavily documented.
  • 6. Why all this work? • Customers do not know requirements initially • Requirements change rapidly • It is essential but often very hard to understand the domain • Teams contain dozens or hundreds of developers, worldwide, over many years • High turnover of software developers • Documentation needed to avoid argument. • Most of the cost is in maintenance [adapted from Perdita Stevens]
  • 7. Extreme Programming • A reaction to the high overhead, bureaucracy of traditional approach (all those documents) • Idea is to be agile • Do the simplest thing that will work • Test-driven development • Unit tests • Pair programming • Focus on refactoring • Emphasis on quickly getting running code
  • 8. Extreme Programming • However, researchers lack the resources to do this all the way • Some ideas useful to pull out (unit tests definitely, refactoring sometimes) More info: http://xprogramming.com/ Books by Kent Beck, Martin Fowler
  • 9. These measures try to ensure product quality. When you are a researcher, it is different: The software is not your product Your product is knowledge • New algorithms • New theorems • New empirical characterization of existing algorithms
  • 10. 4 Principles of Research Code 1.Your code is a means to an end. Don’t really throw it away. Disk is cheap; save everything. Once the paper is done, you will throw it away.
  • 11. 4 Principles of Research Code 2. Unless you succeed. Then everyone will want to try out your stuff. Success is a pain in the a@#! If you are lucky, you will start getting emails from (PhD students of) famous professors.
  • 12. 4 Principles of Research Code 3. You need to be able to trust your results. You do not want to find a bug in your baselines after you publish!
  • 13. 4 Principles of Research Code 4. You need a bespoke set of tools. Invent as little as possible (but no less!) This is true both in your code and in your intellectual work. N.B. All of these principles contradict each other. Welcome to the real world!
  • 14. Corollaries • These principles should guide you in writing code for your research • Except that they contradict each other • So let’s see how the principles are reflected in real-world practice
  • 15. Code is a means to an end • Optimize for your time • Except when your research requires your code to be efficient (this happens) • Efficient code can be competitive advantage • Think of documentation as notes to yourself • Push as much as documentation as possible into identifier names • Always ask why you are writing the code... How will this fit into the eventual paper
  • 16. Code is a means to an end • Do not think that you know now where you will end up • Optimize also for flexibility • The only design pattern that I like is the strategy pattern • Wherever possible, think about where you might want to be clever later • Design for your later cleverness • You care about bugs that affect your experimental results, not really about other bugs
  • 17. Unless you succeed • Commit to reproduceable research • Bench scientists have a lab notebook • You need the equivalent • You must use version control! • Organization of files, directories • “Connect” your code to the figures in the paper
  • 18. Version Control • Many examples: RCS, SCCS, CVS, SVN, hg, git, arch • For new projects you should use at least Subversion, consider the distributed system (e.g., hg, git) • I version control everything that I care about • My code, my research publications, my personal bib file, my Web site • If you ran an experiment on May 13 that you need to reproduce two years later, reproduce that exact state
  • 19. Version Control • Every file that is • Text • Related to your research • Cannot be reproduced automatically • ...should be under version control • To do otherwise is courting disaster
  • 20. Keep track of parameters • Your experiments will have many parameters to tune • Which schedule algorithm you used • Max queue size • Which heuristics for X, Y, Z • Learning rate • Make these parameters of the “experiment running scripts” • Keep track of them in an organized way
  • 21. Connecting your paper to your results directories • Bench scientists have a lab notebook. You need something similar • You need a system where • if you open up your paper file a year later • you will know how to rerun all the code needed for Figure 3 • Key idea: Generate figures automatically via script • Then you just need a map Figure => script file • Could use text file • Comments in LateX code • Also need the version of your code • Keep tarball • Use version control
  • 22. Example System To start an experiment, run a shell script sh scripts/test-tiny-heuristic.sh This script contains the parameters of the experiment: scripts/test-tiny-heuristic.sh DIR=results/tiny-heuristic/airlockF/al2.7/ java uk.ac.ed.inf.csutton.HalMain --open-airlock FALSE --alpha 2.7 --output-dir $DIR
  • 23. Automating your driver script • Lots of times you will need to run a “parameter sweep” • Helpful to have a “driver script” that runs through the parameter grid • Interacts well with grid/cloud computing: Run every parameter setting in parallel
  • 24. Principles of experiment running scripts • 1. Automate as much as possible • 2. Record as much as possible • Text files are your friend! • Some of my fancy systems friends use databases • Makefile’s are good for recording preprocessing steps • (use the filesystem to keep records for you) • Another possibility (haven’t tried it): http:// neuralensemble.org/trac/sumatra
  • 26. Notes about dir structure • Typically for me a “project” is a paper or two worth of work. (May take more than one submission.) • Never quite sure where to put the results/ directory. Parallel to experiment dir? Underneath? Outside of hg altogether • Important: Everything in results/ automatically generated • code/ ==> implementation of the algorithms • scripts/ ==> stuff that only matters for the experiments I happened to run
  • 27. Notes • There are other ways to do this • I can never decide myself what’s best • The principle is: • If a year from now you look at the results file alone you can tell: • What code you used to generate it • With what parameters
  • 28. Trust your results • Unit tests are great • Test a small part of your code • The test code itself checks success, not human • They should be fast to run, so you can run them after every major change • Nip regression in the bud
  • 29. Testing is hard • Testing and debugging research code can require ingenuity • Often your algorithm is heuristic or approximate • If you expect it to fail 10% of the time, how can you be sure it’s correct? • Especially true in machine learning, etc
  • 30. Creative testing • Look for special cases • Maybe if you set alpha = 0, your method reduces to a simpler one • Special case on which your approximation is exact? e.g., Beam search on small state space • There’s more than one way to do it • e.g., Check different approximation algorithms against each other
  • 31. Bespoke tools OS, Standard library, etc Domain frameworks: BLAS, Matlab, R, etc. Your personal shared code Research area A Research area B Experiment 1 Experiment 2 Experiment 3 Experiment 4
  • 32. Making a toolkit • TinyOS http://www.tinyos.net/ • Jikes (research Java compiler) http:// jikes.sourceforge.net/ • SVMlight http://svmlight.joachims.org/ (machine learning) • Festival (speech synthesis) http:// www.cstr.ed.ac.uk/projects/festival/ • Moses (machine translation) http:// www.statmt.org/moses/ Many times you see researchers making software that many people use. A few examples:
  • 33. Making a toolkit • People more likely to use your ideas if they don’t have to implement them • Shared infrastructure: you can try ideas quickly • Other people can add components which you then use • Fame Why would you do this? Seems to violate every principle so far. In any case, this is calculated risk.
  • 34. Summary • Remember the four principles • Your code is an investment of your time • Too little: Can’t trust results, Can’t reproduce • Too much: You try too few new ideas • Writing efficient code can give you a competitive advantage as a researcher • Good luck finding the balance!