Learn Core Python in a Week – My Way
@curphey on Twitter and on Google Plus
I took a week off of work this week to learn Python. Truth is I have been trying to learn Ruby (and) or Python on and off for the last 18 months or so but work and kids (and the “dog ate my homework” syndrome) have always found priority and I made little meaningful progress. After a big release at work I checked my vacation balance, bit the bullet and booked this week off work. I told everyone I was going dark. It’s Friday and so far I am feeling like I have really got to grips with the basics of the core of the language. I am now in a place where I can be productive writing code and solving my own problems. I think I now have the basic level of knowledge to continue learning and overtime actually become a half-decent decent Python developer. In this post I share how I approached getting my results so far.
If you want to know why I wanted to learn a language and why I want to learn Python in particular there is of course a short story. I got involved in computer security via formal education (cryptography and mathematics). As my career progressed through start-ups and financial services companies I became good at managing technical projects and managing technical teams. Through personal interest I steered towards running software security programs and running teams of developers building software security tools. For the last five years I have been more interested in “software” than “software security” and while I am no pointy-haired boss (I have picked up a lot along the way) I have never been formally trained as a computer scientist or worked as a commercial software developer (code contributing developer). When I turned forty, two years ago I had the classic mid-life crisis. I took up distance running and evaluated my long term career plans. Many people start off their careers as highly technical individual contributors and slowly morph into spreadsheet crunching people managers. Power, money and (pseudo) respect in most corporate structures is understandably aspirational for some people but having been there and done it, I made a conscious decision to morph my career back the other way. I won’t ever stop wanting to lead teams of smart motivated and passionate people but I want to be a grass roots technical contributor creating meaningful software. I could write a very long post indeed on how I think the very nature of software teams is changing way beyond Agile and how I think the future is very small self-contained teams operating in an eco-system but perhaps for another day. The short summary is that I decided I wanted to be the member of a rock band and not a member of an orchestra and want to lead software teams from within.
Why Python? With the huge choice of languages and having explored a number over the years (Java, Ruby, Perl, C#) I decided to pick one with a view to becoming proficient in it rather than try and become a “jack of all trades” in a few. I view JavaScript and CSS as base knowledge for any modern developer so didn’t include those in the scope of my decision. You have to know them regardless if you want to build web applications. I have always been passionate about open source software and so one pre-requisite that there was a strong open source community (online, local meetings etc.) and eco-system (tools, components etc.) behind my language choice. At college in ’97 I first played with Java back when it was all about applets, then later when I ran the software security program at Charles Schwab between 2001 and 2003 we were all about EJB so Java might have been a natural choice and the eco-system is clearly very strong, but for some reason the community around Java doesn’t excite me. For me it essentially boiled down to Ruby vs. Python and to cut a long story short Python won. While Ruby has stronger test support with Cucumber (and friends) and of course a first class web framework in Rails, the developer community felt arrogant. Hang out on a ruby language mailing list for a week and you will know what I mean! Python on the other hand has a very strong scientific community behind it with a wider range of libraries for a broad spectrum of science things like bio-informatics. There is a great MVC framework called Django and in recent years Google has adopted it as one of its formal language for both use internally and on the Google App Engine. There is no real science behind my choice and it is very much personal preference but simply put it feels like a decent choice at this time.
Of course there will be a lot of code, a lot of learning and a lot of time before I will be a competent developer, if you are like me and want to learn Python (and have a day job that seems to get in the way) here is what has worked for me that you may want to consider.
1. Book a dedicated week – This is by far and away my number one tip. I took last Friday off to deal with the inevitable bow-wave of mail from work so I could enter this week 100% clear of any work issues. I structured my day with a 5 – 6 mile run every morning (obviously optional) followed by 4 hours of dedicated coding time. I take a break for the afternoon and then follow-up in the evening for a few hours (no fixed length) to cover any loose ends, extra reading and preparing for tomorrow. I created a bow-wave of learning so I wasn’t going into this week cold by starting tutorials a few weeks ago. This allowed me to focus this week on exploring important concepts and not understanding basic theory. I knew what I needed to learn going into this week and what success looked like for me so created my plan for the week (see below) ahead of time.
2. Agile Planning – I scoped out my work using Agile planning techniques. This maybe overkill but got me into the right mind-set. I used the community edition of Rally and set up a backlog and daily iterations. I even entered exercises as tests to prove my knowledge to myself. I have been able to look at my backlog, add stories and tasks and get better at estimating my velocity as the week wen’t along. Other decent free options for this include Pivotal Tracker or Agile Zen.
3. There is no substitute for writing code – You can read as many book as you want and write code in your mind but there is no substitute for writing code on your computer. It really is the only way you will learn syntax, semantics and how things really work. Don’t fool yourself into reading a chapter of a book or watching a video, writing code is what teaches you to write code. There is nothing more to say on that topic. Zed Shaw’s “Learn Python the Hard Way” echoes this. Use the Python shell as much as you can to experiment. iPython gives you a great extended shell to play with.
4. Hire (pay) a good instructor – Having a good mentor / instructor is essential. I was lucky enough to have a very smart friend (who is very, very good developer) last year agree to meet me for coffee every other week and teach me some Ruby. I never really made progress. Reason? I wasn’t committed. I never had to pay him, I would meet and catch up on a social level and our relationship was based on friendship and not on learning. This time I did some Googling, found out that the local University (University of Washington) ran an extension class and emailed the lecturer asking for private lessons. I met him for coffee first to make sure there would be a social fit and that his style would match what I was looking for. It’s not cheap (although all up will probably be 50% of the cost of doing a formal class like this) and has allowed me to operate at my own pace and on topics I want to cover. We can get side-tracked when we want. The lecturer (Brian Dorsey) is great and I look forward to meeting. During this seven day sprint we planned to meet three times and every Friday for a few weeks before and afterwards.
5. Use the Right Learning Material – Over the years I have bought a lot of language books. They range from step-by-step instructional books like the APress or Head First series to less structured books like the O’Reilly language series. While I have gotten a lot from them I have either found them to be “draw by numbers” or not organized in the way I wanted to learn. Bryan suggested “Python for Software Design – How to Think Like a Computer Scientist” which is what the UW course is based on. You can get a free PDF version here. The book has been a perfect fit for me as it talks about computer science in terms of recursion and stack diagrams and has exercises to build fractals and solve math problems. It is an an academic level that I can relate. The right material has really had a significant impact on my learning this week.
6. Use an IDE – Many purists will expose that using a text editor like TextMate (which I own) or TextWrangler is the best way to learn but for me using a fully fledged IDE has been a serious benefit. I use PyCharm and for the most part love it. When you are exploring an API you can see the functions it supports and syntax errors are highlighted as you type. While this could indeed make you lazy I think it helps you get up to speed faster so that the syntax becomes second nature. For me it’s like the difference between using a text editor or word processor to write a story.
7. Use good development practices as you learn – All week I have put my code into revision control. I generally use Git so also took the opportunity to learn Subversion this week (my only real violation of my next tip but it was so simple that …). I comment all my code no matter how trivial the example and even took to running it through the Python style guide PEP-8. Towards the end of the week I have even taken to writing unit tests for all code. Python Koans are great for learning testing in Python.
8. Just Learn the Language, Nothing Else – It’s very tempting to also learn Django at the same time as learning Python. If you want to build web apps you will need a framework to build on but I think it has been very valuable to separate the two. Apart from separating the complexity and scope it forces you to focus on the language only and not how to use the language to drive a framework.
That’s it for now. If I can think of more I will add it and I would love to hear others tips and tricks.
Useful References
A Jump Start for Learning Python
33 projects that make developing django apps awesome
http://learnpythonthehardway.org/
-
Dipankur
-
http://www.breakthesecurity.com Blackstar
-
http://www.roxberry.pro Mark Roxberry
-
Nitish
-
http://pytools.codeplex.com sean
-
Mike
-
http://epeus.blogspot.com Kevin Marks
-
Sebastian
-
http://accidentalhacker.com Rob Sobers
-
Scott
-
matelot
-
http://www.guidovo.com Guido
-
Aputsiaq
-
Pete Clarke
-
Kolya Miller
-
Anonymous
-
Iltaren

