17
Everything you need to know about programming Without any programming Danny Mulligan [email protected]

Austin Python Learners Meetup - Everything you need to know about programming except the programming

Embed Size (px)

DESCRIPTION

Slides from a presentation at the Austin Python Learners Meetup on Tue 26 Feb 2013

Citation preview

Page 1: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Everything you need to know about programming

Without any programming

Danny [email protected]

Page 2: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Overview• Editors/IDEs• Revision Control• Testing• Debugging• Common errors• Performance

• Libraries• Documentation• Getting help• Practicing• Q&A

Page 3: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Editors/IDEs• Use what you already know• Use something simple• Use something that everybody else is using• Learn to walk before you learn to run• The right choice for an expert is probably not

the right choice for you (at least right now)

• Learn to type• Learn keyboard short cuts

Page 4: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Editors/IDEs• Common editor choices

– Textedit (standard on Macs)– Notepad (standard on Window)– EMACS http://emacsformacosx.com/– vim https://code.google.com/p/macvim/– Notepad++ http://notepad-plus-plus.org/– BBEdit http://www.barebones.com/products/bbedit/index.html– TextMate http://macromates.com/

• IDEs and other stuff you might try– Eclipse http://www.eclipse.org/– Pycharm https://www.jetbrains.com/pycharm/– Spyder IDE https://code.google.com/p/spyderlib/– iPython http://ipython.org/ (iPython notebooks are great!)– iTerm 2 http://www.iterm2.com/ (Replacement for Mac’s terminal)– 10 Fast Fingers http://10fastfingers.com/

Page 5: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Revision Control• Absolutely essential for teams• A good idea for you• Unfortunately, not the simplest stuff to master

• Popular tools: GIT, Hg, SVN, CVS, Perforce, Visual SourceSafe

• GitHib https://github.com/– Allows you to share code easily– Windows app http://windows.github.com/– Mac app http://mac.github.com/

• Related #1: when was your last backup?• Related #2: bug tracking is important too (especially for teams)

Page 6: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Testing• How do you know if you code has any bugs?

– Easy = it has bugs, you haven’t found them yet

• Writing tests is every bit as important as writing code– Pro move = write the tests FIRST!

• Keep the test code after you’ve written it• Unit tests & regression tests• Write defensive code (use assert statements)• Testing your code is a HARD problem, don’t underestimate it• Dividing coding and testing between multiple people can

help

Page 7: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Example of unit tests

Page 8: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Debugging• Print statements – show you what’s going on• Assert statements – verify your assumptions• Fancy debuggers – less useful than you’d think• Write documentation on your code• Code reviews - explain the code to someone else• Avoid putting the bugs in in the first place– Shorter code has fewer bugs– Simpler code has fewer bugs– Code that’s not there has 0 bugs = use the libraries

Page 9: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Common Errors• Off by 1 errors (AKA fencepost errors)• = vs. ==• Logical (and, or) vs. bitwise (&, |) operators, (use logical almost always)• integers vs. floats

a = 5/(1/3) # a should be equal to 15, or is it?

• Integer or float?a = 1/3; b = 3/9; c = a/b; print c # c is equal to 1, right?

• Floats are imprecisea = 2.15*3; b = 6.45; print (a == b) # True or False?

• Division by zero• Logic errors – easy to make mistakes with nested if statements• Are you working with a copy, or the original object?

colors = [‘red’, ‘green’, ‘blue’]b = colors; b[0] = ‘black’print colors # Did colors change?

• Inadequate or no error handling• Complexity is the enemy of correctness

Page 10: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Performance• Your performance matters a LOT more than

the computer’s performance• So don’t worry about performance

Page 11: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Performance optimization• Simple is usually faster• Use library functions whenever you can• Use the pareto principle, AKA the 80/20 rule– Profile first, optimize later– “premature optimization is the root of all evil”

• If you MUST optimize for performance– Do easy optimizations first– Your brain is the best optimization tool– Make sure you don’t break your program in the

process

Page 12: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Libraries• Learn what is in the standard library• Get the documentation• Some important libraries:– Python Standard Library: by far the most important– Python Image Library: image manipulation– Matplotlib: charts & graphs– Numpy: high performance data processing– Django: web framework– Scikit-learn: machine learning– Pandas: data analysis– NLTK: natural language

Page 13: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Python Standard Library• string – Common string operations• re – Regular expression operators• math – Mathematical functions• csv – CSV File Reading and Writing• datetime – Basic data and time types• random – Generate pseudo-random numbers• itertools – Functions creating iterators for efficient looping• collections – High-performance container datatypes• os – Miscellaneous operating system interfaces• threading – Higher-level threading interface• pdb – The Python Debugger• profile & cProfile – Profiling tools• test – Regression tests package for Python

Page 14: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Documentation• Python docs online at

http://docs.python.org/2/library/• I keep PDFs of the Python docs on my laptop

http://docs.python.org/2/download.html• The standard docs include a nice Tutorial• “The Python Library Reference” is by far the

most useful doc– 1,457 pages, but do not read (except the ToC)– Look up what you need when you need it

Page 15: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Getting help• Read the docs, read other people’s code• Google your question, look for similar code• When you google, you will often end up on StackOverflow

– Best site for programming questions http://stackoverflow.com• Watch tutorials on YouTube - examples

– 3 hour iPython tutorial https://www.youtube.com/watch?v=2G5YTlheCbw

– 83 video playlist from PyCon 2012 https://www.youtube.com/playlist?list=PL2814D3290BAA8837

– 30 minute overview of Pandas https://www.youtube.com/watch?v=qbYYamU42Sw

– 3 hour tutorial on Pandas https://www.youtube.com/watch?v=w26x-z-BdWQ

Page 16: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Practicing• How do you get better at golf?– Read a book or play golf?

• How do you get better at programming?– Use it in your job– Solve some real world problems– Read other people’s code

• Some real world programming exercises– Coding Bat http://codingbat.com/python– Project Euler https://projecteuler.net/

Page 17: Austin Python Learners Meetup - Everything you need to know about programming except the programming

Q&A