How I came to learn Python
It has been a nifty tool for my research work too: starting with stackoverflow to openstreetmap data. Python provides easy-to-use tools for data cleaning, processing and graphing; some of its libraries are a sheer pleasure to use: matplotlib, networkx, scipy, numpy etc. More importantly, I can write my full processing stack in Python without having to resort to other languages or tools. Although, there are speed and memory consumption trade-offs; overall, it’s been a pretty good bargain.
The Good Parts of Python
- The language has an almost non-existent learning curve; it’s soooooo easy to learn.
- Comes in handy when you want to write a script or solve a little problem.
- An awesome community, nice package management and great libraries – examples include scientific libs (matplotlib, numpy, scipy) SQLAlchemy, PyTables, Sage, networkx.
- Cross-platform and supports full-stack development.
- Great readability, high expressiveness and a very simple grammar – almost reads like English at times.
- Allows returning multiple values from a method.
- Some cool supported operations in Python:
- Swapping: x, y = y, x
- Floor division: 5.0//2 = 2.
- Comparisons: if 3 > x > 1: print x; I don’t know of any other language that has this feature.
- Iterating through two lists simultaneously using the zip keyword.
- List comprehensions are super-awesome.
The Bad Parts of Python
- Speed; Python is slow :(.
- Memory consumption; you can’t explicitly free memory and it’s not suited for situations requiring extremely small memory footprints.
- Inadvertent overwriting of default functions or settings. For example, I once did this str = “blah blah blah”; Python raised no objections, it meekly overwrote the str() function.
- Multi-threading support is not too good.
- Scoping issues: variables fall out of scope so it’s essential to choose unique names.
- .3/.1 = 2.99999999999999996. The floating point issue rears its ugly head again.
The Other Parts
- The indentation can be a pain if your editor gets it all messed up. Use a good editor (vim/Emacs) and make sure your tabs are converted to 4 spaces.
- IDE support ain’t that great since it’s a dynamic language and there are lots of ways to do the same thing.
- Weird syntax for the ternary operator : True if condition else False
- Installing libraries can be a really painful operation if you get it all wrong.
- Since it’s not a statically typed language, typos aren’t detected until your program goes KABOOM!
- How do you declare private variables in classes? I still don’t know.
- Explicit addition of self all the time; I think it is needed to know the current execution scope but still….
- There is no switch statement in the language; workarounds exist though.
Tips for Starting with Python
Do it! Just jump into the language, learn the pythonic way and slowly you’ll come to see its beauty. It might feel weird if you come from a ‘braceful‘ language (i.e. Java et. al. ) and some concepts might initially perplex you.
However, once you get used to the language, I bet you’ll wonder how you managed to get stuff done in other languages. The sheer expressiveness is amazing at times: you write so little and achieve so much. I think it’s fantastic for data processing, little scripts and heavy lifting ( provided you have enough memory and processing power; some libraries allow you to leverage highly optimized C/FORTRAN code so it’s not totally bad)
Also learn to use the interpreter (you can also try ipython if you’re just starting out) – I use it a lot to speed up my development process and for debugging.
One of the easiest languages to learn and use for scripting needs and comes in handy for rapid prototyping. Extra bonuses include loads of great libraries, support for OOP and functional programming. Sure, it has a few issues but what language is perfect?
Python will probably make you lazy but why do more if you can get the same results with less? :)
UPDATE: Thanks to a reader for clarifying my wrong assumption about Python’s ternary operation support.