====== Python tools for software carpentry ====== Lecturer: Pietro Berkes, {{:materials:software_carpentry_cheatsheets_v1_1.pdf|Download the cheat sheets}} for all the tools and methods discussed in the lecture! ===== Course material ===== Slides: {{:materials:software_carpentry_slides_v3.pdf|Download slides}} Exercises: * {{:materials:day1_exercises_v3.pdf|day1_exercises.pdf (exercise sheet)}} * {{:materials:day1_exercises_final.zip|day1_exercises.zip (source code)}} * {{:materials:day1_solutions_final.zip|day1_solutions.zip (source code)}} * On masterbaboon.com there's {{http://www.masterbaboon.com/2010/09/solving-the-game-set/|an article about writing an efficient solver for Set}} Outline of the lecture (2h): - Unit testing * unittest * testing with numpy arrays * what to test and how for scientific programming * code coverage (coverage.py) - Debugging * pdb - Profiling * timeit * cProfile - Other useful tools * documenting: pydoc, doctest * static checking: pylint Many live demos, music and dances! ===== Good programming practices ===== ==== Software carpentry in general ==== Two comprehensive software carpentry courses: [[http://software-carpentry.org/|University of Alberta]] [[http://itb.biologie.hu-berlin.de/~zito/teaching/SC/|Tiziano's course]] at the Bernstein center in Berlin The classic book about software carpentry: [[http://pragprog.com/titles/tpp/the-pragmatic-programmer | The pragmatic programmer]] ==== Coding standards ==== [[http://www.python.org/dev/peps/pep-0008/|PEP8]], the official Python style guide [[http://www.logilab.org/857 | pylint ]], tool to check coding standards ===== Test suites ===== [[http://docs.python.org/library/unittest.html|unittest]], the standard Python test framework [[http://codespeak.net/py/dist/test/test.html|py.test]], an alternative framework that simplifies writing tests and allows for extension and customization of test experience [[http://somethingaboutorange.com/mrl/projects/nose/0.11.1/|nose]], another popular alternative [[http://docs.python.org/library/doctest.html | doctest]], write tests inside of docstrings ===== Debugging ===== [[http://docs.python.org/library/pdb.html|pdb]], the standard python debugger [[http://winpdb.org/download/|winpdb]], a graphical interface for ''pdb''. It's platform-independent despite its name. [[http://www.gnu.org/software/ddd/|DDD]] (DataDisplayDebugger), graphical general-purpose debugger. Python IDEs often have a built-in debugger. ===== Profiling ===== [[http://docs.python.org/library/profile.html|cProfile]], the batteries included Python profiler [[http://docs.python.org/library/timeit.html|timeit]], built-in Python module to measure the execution time of small code parts [[http://www.vrplumber.com/programming/runsnakerun/|RunSnakeRun]], a wxPython-based visualization of profiling results -- very intuitive!