Best practices in scientific programming Software Carpentry, Part I. Pietro Berkes, Brandeis University

Similar documents
Intro to scientific programming (with Python) Pietro Berkes, Brandeis University

Deep Agile Blending Scrum and Extreme Programming. Jeff Sutherland Ron Jeffries

Research Data Management CODING

Unit testing: Why I write more test code than regular code

Agile processes. Extreme Programming, an agile software development process. Extreme Programming. Risk: The Basic Problem

Agile processes. Extreme Programming, an agile software development process

Agile Development and Testing Practices highlighted by the case studies as being particularly valuable from a software quality perspective

Extreme Programming, an agile software development process

Extreme Programming, an agile software development process

Continuous Integration

Software Development Methodologies

XP and Design. Paulo Caroli & Sudhindra Rao. ThoughtWorks

Test-Driven Development

Basic Trends of Modern Software Development

An Introduction to Extreme Programming

Agile So)ware Development

Code Qualities and Coding Practices

XP and TDD. Extreme Programming and Test Driven Development. Bertrand Meyer, Manuel Oriol Andreas Leitner. Chair of Software Engineering ETH Zurich

Development Techniques. CSE301 University of Sunderland Harry R. Erwin, PhD

A Quick Overview of Software Engineering. Paul Klint

EXTREME PROGRAMMING AGILE METHOD USED IN PROJECT MANAGEMENT

Ingegneria del Software Corso di Laurea in Informatica per il Management. Agile software development

Embracing Change with Squeak: Extreme Programming (XP)

How To Model In An Agile World

Test Driven Development

XP & Scrum. extreme Programming. XP Roles, cont!d. XP Roles. Functional Tests. project stays on course. about the stories

Rapid software development. Ian Sommerville 2004 Software Engineering, 7th edition. Chapter 17 Slide 1

Copyright. Network and Protocol Simulation. What is simulation? What is simulation? What is simulation? What is simulation?

Extreme Programming. Sergey Konovalov and Stefan Misslinger. May 23, 2006

Software Development Practices in Project X

Agile Testing and Extreme Programming

IF The customer should receive priority service THEN Call within 4 hours PCAI 16.4

Rapid Software Development

Game Programming. Bachelor of Software Engineering. Course Components

MANAGEMENT S ROLE 1/16/ Copyright 2001, Net Objectives

Scrum a tester s perspective

CSE 4415 / SWE 5415 Software Testing 2 Fall 2004 Olin Engineering Building, Room 128 Credits: 3.00

Making Architectural Design Phase Obsolete TDD as a Design Method

Best Practices, Development Methodologies, and the Zen of Python

Chapter 1 Programming by Intention

Agile Methodologies XP and Scrum

Software Configuration Management Best Practices for Continuous Integration

How To Develop Software

Introduction to Automated Testing

Introduction. Motivational Principles. An Introduction to extreme Programming. Jonathan I. Maletic, Ph.D.

Topics covered. Agile methods Plan-driven and agile development Extreme programming Agile project management Scaling agile methods

Software Configuration Management Best Practices

An Introduction to text-based test automation and the TextTest tool

Agile Software Development and Service Science

Quality Assurance Plan

Functional and LoadTest Strategies

BEHAVIOR BASED CREDIT CARD FRAUD DETECTION USING SUPPORT VECTOR MACHINES

Software Development Life Cycle (SDLC)

Build your Project using Extreme Programming #2 of a Series, by Pavan Kumar Gorakavi, M.S., M.B.A, G.M.C.P, C.A.P.M.

RANKING REFACTORING PATTERNS USING THE ANALYTICAL HIERARCHY PROCESS

Large Scale Systems Design G52LSS

ANALYTICS CENTER LEARNING PROGRAM

Improving database development. Recommendations for solving development problems using Red Gate tools

In the IEEE Standard Glossary of Software Engineering Terminology the Software Life Cycle is:

Fall 2012 Q530. Programming for Cognitive Science

Methodology: Agile development of safety critical systems Annex D1.1.d to deliverable D1.1

Agile with XP and Scrum

Datamaker for Skytap. Provide full-sized environments filled with up-to-date test data in minutes

WHITEPAPER. Improving database development

The GAMP Guide s1 definition of the system

GLM, insurance pricing & big data: paying attention to convergence issues.

Extreme Programming: Strengths and Weaknesses

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Advanced Test-Driven Development

Simplifying development through activity-based change management

THE SOFTWARE DEVELOPMENT LIFE CYCLE *The following was adapted from Glencoe s Introduction to Computer Science Using Java

Software Testing with Python

Introduction to extreme Programming (XP)

An Approach to Agile Automation Testing. QAANOVA September 16, 2008 Frank Hurley, Technical Manager

Automating Business Processes Using SharePoint Designer

Upping the game. Improving your software development process

Secrets to Automation Success. A White Paper by Paul Merrill, Consultant and Trainer at Beaufort Fairmont, LLC

General Framework for an Iterative Solution of Ax b. Jacobi s Method

Test Driven Development of Embedded Systems Using Existing Software Test Infrastructure

An Overview of Quality Assurance Practices in Agile Methodologies

UC Santa Barbara. CS189A - Capstone. Christopher Kruegel Department of Computer Science UC Santa Barbara

Software Engineering and Scientific Computing

Augmented Search for Software Testing

Chapter 13: Program Development and Programming Languages

Bad code smells Refactoring Example

The Public Policy Process W E E K 1 2 : T H E S C I E N C E O F T H E P O L I C Y P R O C E S S

Co-Presented by Mr. Bill Rinko-Gay and Dr. Constantin Stanca 9/28/2011

WINDOWS AZURE AND WINDOWS HPC SERVER

Test Driven Development Part III: Continuous Integration Venkat Subramaniam

MEng, BSc Computer Science with Artificial Intelligence

A Framework For Software Quality Assurance Using Agile Methodology

QUALITY ASSURANCE IN EXTREME PROGRAMMING Plamen Balkanski

Nine Common Types of Data Mining Techniques Used in Predictive Analytics

Software Development Methodologies

Getting Started With Automated Testing. Michael Kelly

XP with Acceptance-Test Driven Development : A rewrite project for a resource optimization system

Learning and Coaching Agile Methods. Görel Hedin Computer Science Lund University, Sweden

Agile Software Development and Service Science

BPM, EDA and SOA: How the Combination of these Technologies Facilitates Change. Dr. Neil Thomson, Head of Group Development, Microgen plc

Bioinformatics for programmers

Transcription:

Best practices in scientific programming Software Carpentry, Part I Pietro Berkes, Brandeis University

Outline Part I Agile development for scientists Good programming practices Test driven development, late optimization, refactoring This part is not specific to any programming language Part II Python tools Version control systems Testing, debugging, profiling Focus on standard, out-of-the box Python tools 2 Software carpentry - Part I

Modern programming practices and science Many of us have to routinely write computer programs, but few of us have been trained to do so Good programming practices can make a lot of difference Development methodologies have been introduced for the development of commercial software, but we can learn a lot from them about making science 3 Software carpentry - Part I

Scenarios Lone scientist, coding up a model or data analysis tool for a research project Small team of scientists, working on a common library The bottleneck is developing speed, not execution speed Need to try out different ideas: rapid prototyping, re-use code, identify common patterns and use known solutions 4 Software carpentry - Part I

Requirements for scientific programming Every scientific result (especially if important) should be independently reproduced at least internally before publication (DFG, 1999) Translation: there must be guarantees that the source code works as advertised (testing frameworks, pair programming) Increasing pressure for making the source code used in publications available online (especially for theoretical papers) Translation: you shouldn t be embarrassed of publishing your code Your code must be readable and easily reusable 5 Software carpentry - Part I

Agile development Generic name for set of more specific paradigms, most influential extreme Programming (XP), formulated in the 90s by Kent Beck, Ward Cunningham, and Ron Jeffries Set of good programming practices, from design of software to development to maintenance Particularly suited for small teams (<10 people) facing unpredictable or rapidly changing requirements (sounds familiar?) 6 Software carpentry - Part I

The basic agile development cycle Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 7 Software carpentry - Part I

Planning Story-based planning Writing tests before actual code helps designing the interface Use spike solutions to test approaches (i.e., write a toy implementation / proof-of-concept) Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 8 Software carpentry - Part I

Test-driven development Tests are crucial for modern programming. Tests become part of the programming cycle and are automated Write test suite (collection of tests) in parallel with your code External software runs the tests and provides reports and statistics Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 9 Software carpentry - Part I

Testing benefits Encourages better code and optimization: code can change, and consistency is assured by tests Faster development: Bugs are always pinpointed Avoids starting all over again when fixing one part of the code causes a bug somewhere else Installation check for users if you plan to distribute your code To reviewers: I know my code works, because it passes these tests Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 10 Software carpentry - Part I

What to test and how Test with simple (but general) cases, using hard coded solutions E.g., test that sum(2, 3) = 5 Test general routines with specific ones E.g., test polyomial_expansion(data, degree) with quadratic_expansion(data) Test special or boundary cases E.g., test has_prefix(string, pfx) for pfx="" Test that the code raises meaningful errors when wrong data is passed Relevant when writing scientific libraries Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 11 Software carpentry - Part I

Example: eigenvector decomposition Consider the function values, vectors = eigen(matrix) Test with simple but general cases: use full matrices for which you know the exact solution (from a table or computed by hand) Test general routine with specific ones: use the analytical solution for 2x2 matrices Test with boundary cases: test with diagonal matrix (is the algorithm stable?) test with a singular matrix Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 12 Software carpentry - Part I

I m writing a learning algorithm / probabilistic algorithm. How can I possibly test it? Turn your validation cases into tests Think of simple, artificial cases Probabilistic becomes deterministic with lots of data or disappearing noise Test all sub-parts of the algorithm 13 Software carpentry - Part I

Start simple Write small, testable chunks of code Write intention-revealing code Separate testable parts from main application Do not implement a general problem-solving framework for a specific problem unnecessary features are not used but need to be tested and maintained Do not try to write complex, efficient code at this point Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 14 Software carpentry - Part I

The whole point of my research is implementing an efficient algorithm The algorithm should be efficient, not its first implementation Re-use standard data types Do not use optimization tricks Do not vectorize if a for-loop will do 15 Software carpentry - Part I

Collaborating Pair programming One programmer sits at the computer and does the coding, the other looks and keeps an eye on the big picture Pairs are fluid Code must be formatted to agreed coding standards (Python: PEP8) Write intention-revealing code (comments should be mostly not necessary) Keep your code documented (docstrings!) Use Version Control Systems to handle shared code Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 16 Software carpentry - Part I

How to handle bugs 1. Isolate the bug Test cases should already eliminate most possible causes Use a debugger, not print statements 2. Add a test that reproduces the bug to your test suite 3. Solve the bug 4. Run all tests and check that they pass Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 17 Software carpentry - Part I

Optimization Usually, a small percentage of your code takes up most of the time 1. Identify time-consuming parts of the code (use a profiler) 2. Only optimize those parts of the code 3. Keep running the tests to make sure that code is not broken Write tests to check your code Write simplest version of the code Run tests and debug until all tests pass Optimize only at this point 18 Software carpentry - Part I

When should I stop optimizing? As soon as it s fast enough When all the obvious optimizations are implemented Consider also alternative forms of optimization: running remotely on a faster machine, having multiple runs in parallel,... 19 Software carpentry - Part I

Adding new functionality 1. Implement new functionalities as in basic development cycle 2. Refactor the code Re-organize your code without changing its function E.g., remove duplicated code, break down complex functions in simpler parts, rename variables and functions to make intention clearer Series of recipes for these common operations: how to do them without breaking the code Do it in small steps, keep testing Many modern IDEs have refactoring tools 20 Software carpentry - Part I

Final thoughts on Part I Do not underestimate these practices Adapt these techniques to your needs, but try to keep in mind the basic principles Never stop testing 21 Software carpentry - Part I

22 Software carpentry - Part I

23 Software carpentry - Part I