My Python May

Ville
10 min readJun 9, 2016

--

I spent the entire month of May learning and writing Python for at least 30 minutes everyday and this is the why, how & what I did and what I learnt…apart from some Python

Why?

Late last year I released a project called CodeHalf which I created to help me track my habit of writing code every day, shortly after I wrote an article here on Medium about what I’d learned from doing it.

In the last 6 months I’ve missed maybe a handful of days, and these were only due to becoming a Dad so I think that was only to be expected. In that time I have managed to get far more done than I have ever before really. Even my public Github profile thinks so:

My Github public contributions

This was great and exactly what I’d had always wanted to do but something wasn’t quite right. I was spending lot of time on ton of different kinds of projects but it was almost as thought I was getting fatigued by the need to constantly find things to do.

This was ironic in that I’d never had as many projects on the go at the same time.

Ordinary month of disparate projects

For some time I’d had also thought I’d like to learn a new language again, I played around with Elixir and Phoenix recently but they were too similar to Ruby and Rails that I spent most of my time writing.

I went through a great deal of language choices from C to Scala to Rust to Java to Lisp and back, annoying my friends in the meanwhile trying to decide what to try next.

Finally I settled on Python, it was a language I’d already fancied looking into it in the past, I’d recently listened to couple of good podcasts by Programming Throwdown on it, TensorFlow & OpenAI use it for machine learning, I knew projects like PyGame existed, lot of Raspberry Pi & IoT projects are using and tons of other buzz about it.

How & What?

So I fancied learning some Python: Having seen the great improvements in productivity I’d had with the CodeHalf model and being fatigued by deciding what to do next I decided to try something a bit different.

I would park all my other projects and strictly spend my minimum 30 minutes per day just learning Pythony stuff. Any time I had left after that I could spend on doing other projects like bug fixing CodeHalf or merging pull requests. This decision happened towards end of April so I decided May would be Python May.

Here’s roughly what took place and the resources I used:

Day 1 — Following “The Hitchhiker’s Guide to Python” I Installed the latest Python 2.x and played through first couple of levels of the CodeSchool Try Python course which is free

Day 2 — Finished the CodeSchool course, read through bunch of pages at LearnPython.org to supplement the CodeSchool course and wrote my first attempt at FizzBuzz, you can find the Github Gist here

Day 3 — Learnt about: Generators, Dictionaries and other data structures from the official python docs. Read some StackOverflow conversations about “Pythonic” ways of doing certain things. First attempt at the built-in map function and Lambdas. 2nd attempt at FizzBuzz with added Pythonic practises here

Day 4 — Battled with installing PyGame and wrote a simple GUI thing with a green dot moving slowly to the right side of the black screen.

Days 5 to 8 — Wrote a simple snake game with PyGame, spent a Saturday evening live casting working on it in Twitch with a hope that someone would correct me with my unpythonic ways but only got couple of “Cool”s instead. Source on Github here and it looks roughly like this:

Snake game with PyGame

Day 9 — Installed Django and started working through the official “Writing your first Django app” tutorial. Made a note regarding Django feeling like Rails 2 and just being arduous to do anything with.

Day 10 and 11 — Installed TensorFlow machine learning library, played through some of the tutorials on the site. Decided the actual amount of Python learning was suffering due to needing to spend significantly more time understanding the underlying mathematics and theory.

Day 12 and 13 — Spent couple of days reading the excellent sections on “Code organisation” and “style guides” in the Hitchhiker’s Python guide I mentioned earlier. Started feeling much better about Python as a language (more on this later).

Day 14 — Learning bunch about Python GTK+ 3 from these excellent docs in order to write some desktop GUI applications. Also learning about the PyCrypto package. Created a simple desktop app to generate an RSA key and save it to a file locally and load it on next startup.

Day 15 and 16 — Learning about and using Protocol Buffers and then shortly after gRPC. Wrote a simple client server project to send end-to-end encrypted messages between clients.

Day 17 and 18 — Reading more about Python modules and packages from variety of sources such as the official docs and general Googling. Read great deal of PEP8 The Style Guide for Python Code. Refactored my project from previous days with new found module and package comprehension.

Day 19 to 21 — Learnt about Flask the Python web microframework and Redis datastore and integrated them into my encryption project.

Day 22 and 23 — Learnt about unit testing in Python from the Hitchhiker’s guide. Wrote yet another FizzBuzz, this time with tests and extendable rule set. Code can be found here. This was mainly to learn more standard lib and put the testing learnings into practise.

Day 24 and 25 — Revisiting the functional parts of Python like map and filter. Another attempts at lambdas and list comprehensions. Wrote a yet another silly 1 liner FizzBuzz to really explore the above. Code here

Day 26 to 31 — Writing a Tetris clone using PyGame. Mostly finished code can be found here

Yay I made it!

Completed Python May in CodeHalf

So what did I learn?

I learnt some Python and I learnt about some really cool projects and libraries for Python but that much was to be expected, the rest of it is bit tricky:

Learning a new language in a month is complicated

If you already know a similar programming language or languages it’s really quick to get going as you don’t have to learn about many of the concepts, just the syntax. This also means that you’ll probably hit a plateau quite quickly with your learning.

There were several times during the month where I’d be learning a library and working with it and I would make a conscious effort to stop as I felt the learning was more leaning towards the library or it’s concepts than Python itself.

This very much came to a point on Day 26 when I couldn’t think of an effective source to learn more about Python itself and then spent the next week working on the Tetris clone as at least it would have me writing Python code and whilst not necessarily optimal for learning would give me familiarity.

I found some books on advanced Python topics but they really weren’t suitable for my purposes here given the timeframe.

From experience I know that some of the best learning comes from working with large codebases. I considered finding a well established Open Source Python project on Github but from experience I knew it would take a disproportionate amount of time to get familiar enough with the project to contribute.

Python is…OK

One of the things that drove me potty from the beginning was the need to accept the instance of the object in question as the first argument for instance methods.

Spending the month with the language I still don’t get why this a thing, admittedly I didn’t dig too deep into it to find out the reasoning but it seems wholly unnecessary and the benefits it appears to provide have been solved in my opinion in far more elegant ways in other languages.

The indentation system and it’s conventions was a mixed bag for me. I get that you almost need to use 4 spaces for indentation when you are using it as part of your language but coming from Ruby’s 2 spaces it just looks unnecessary at first. Initially I was also annoyed by the need for keywords like `pass` to enable creating empty methods, something which you are likely to do routinely as part of TDD.

The module and package system was confusing at first and strange at best when I learnt more about it, practises such as creating empty files with awkward names like __init__.py in folders seemed weird.

Lambda syntax seemed restricted and awkward compared to Ruby, the functional parts like map and filter didn’t seem very elegant and it appeared they weren’t used much either by the community (from my brief reading).

By the end of the month I felt kind of OK about the language itself and the conventions, I wouldn’t say there was anything that was markedly better than any of the languages I’d used in the past or even really Ruby for that matter except for one thing: List comprehensions! Love em!

Admittedly it could well be that there’s a whole world of lovely things I didn’t find during my month. I loved the idea of things being explicit rather implicit in theory but the implementation of that left a lot to be desired for me. It felt explicit like Java or XML not explicit like say Elixir’s Phoenix framework.

The eco system is amazing

The varied eco system around Python is just WOW!

Especially when comparing to Ruby, which is I’d probably guess 80%+ Rails. There’s non Rails Ruby projects for sure but they tend to have poor adoption and the communities tend to be tiny. This is pretty evident when you search for Ruby answers in StackOverflow and at least half the recommended solutions are actually from ActiveSupport — a Rails library, not from the Ruby standard library.

There’s some great libraries like PyCrypto, NumPy, SciPy, PyGame, various GTK binding libraries etc, all very mature and or feature rich.

Great stuff like Protocol Buffers, gRPC, TensorFlow, OpenAI which I believe all have best supported libraries for Python.

And I didn’t even get to the whole world of Raspberry Pi and IoT development which as far as I know have really strong Python support with heaps of excellent libraries and projects.

Also worth a mention is the documentation, which for most projects is excellent, not always the nicest looking but very thorough and complete, especially when compared to packages and libraries for other languages in general.

Fear Of Missing Out

Having decided to spend my minimum 30 minutes per day session on just Python most of the time that is all I had time for and the fear of missing out on other things really started to creep in.

Should I be spending more time looking into bots which are getting a huge deal of attention right now? Should I be learning more Elixir? Am I doing myself a disservice by not looking into every latest piece of tech/library/language/concept/technique that comes through my newsfeed daily? Probably not but it definitely felt like it, at least initially.

I had to keep telling myself that a month is really not a long time, and even though it may seem like it at times the industry really isn’t moving that fast after-all that I wouldn’t be able to take a month out.

Another interesting observation under this heading is that much like when I go on holiday without a laptop; I’ve never had so many “good” ideas for new side projects & start ups come up.

At the same time I was hesitant to pursue them with Python as it may steal focus away from learning Python and besides I haven’t made up my mind yet whether I’d want to keep working on the project in case it did take off…Silly I know but a thought process I kept having nonetheless.

Conclusion

Do I think it was time well spent? Absolutely! I had a blast and I learnt enough Python that I’d be confident to start reading through a bigger project and know how to learn more or to dare I say even tackle writing a small to medium sized project in Python.

Am I going to continue my Python journey? Too early to say, I’ve already decided I’m going to have a bitty month of June to work on things I feel I’ve neglected.

Would I do something like this again with another language? Possibly, although depending on the language I might either cut the time a bit shorter or I’ll be better prepared by having the materials at the ready to help me get through the plateau, probably by buying an excellent intermediate to expert level book.

Would I recommend doing something like this to others? Oh yes! If you don’t currently have a habit of writing code for yourself and learning every day this’ll be a great way to start. If you are already doing that then yes I’d urge you to challenge yourself to see how far you can get in a fixed period of time such as a month.

Pro tip: Keep a daily diary of your progress that day, the links you found helpful and where to pick up the next day to not waste precious time. I used CodeHalf to track these for myself but pen and paper/Google doc etc should work just fine as well.

If you’ve undertaken similar challenges in the past, or you’re in the middle of one right now or even just planning doing one I’d love to hear from you. You can reach me on twitter @efexen

I hope this has inspired you to learn something new, or at the very least provided a healthy list of links if you’re interested in learning Python ;)

Any feedback is much appreciated and if you enjoyed this article do recommend it and share it with others in hopes that they’ll get inspired.

--

--

Ville

Freelance Developer • Founder of @CodeHalf • Rubyist • Elixir Alchemist • Wannabe Data Scientist • Dad