When was the last time I vented about C++? The answer for that is always:
"TOO LONG AGO".
When was the last time I vented about C++? The answer for that is always:
"TOO LONG AGO".
I was recently assigned to a new project at work. Like any good software engineer I started writing the pseudocode for the modules. We use C++ at work to write our programs.
I quickly realized it's not easy to translate programming ideas to English statements without a syntactic structure. When I was whining about it to Vijay, he told me to try prototyping it in Python instead of writing pseudocode. Intrigued by this, I decided to write a prototype in Python to test how various modules will come together.
Surprisingly it took me a mere 2 hours to code up the prototype. I can't emphasize enough, how effortless it was in Python.
Dynamically typed language:
Python doesn't require you to declare the datatype of a variable. This lets you write a function that is generic enough to handle any kind of data. For eg:
def max_val(a,b): return a if a >b else b
This function can take integers, floats, strings, a combination of any of those, or lists, dictionaries, tuples, whatever.
A list in Python need not be homogenous. This is a perfectly good list:
[1, 'abc', [1,2,3]]
This lets you pack data in unique ways on the fly which can later be translated to a class or a struct in a statically typed language like C++.
class newDataType { int i; String str; Vector vInts; };
Rich Set to Data-Structures:
Built-in support for lists, dictionaries, sets, etc reduces the time involved in hunting for a library that provides you those basic data-structures.
Expressive and Succinct:
The algorithms that operate on the data-structures are intuitive and simple to use. The final code is more readable than a pseudocode.
For example: Lets check if a list has an element
>>> lst = [1,2,3] # Create a list >>> res = 2 in lst # Check if 2 is in 'lst' True
If we have to do it in C++.
list lst; lst.push_back(3); lst.push_back(1); lst.push_back(7); list::iterator result = find(lst.begin(), lst.end(), 7); bool res = (result != lst.end())
Python Interpreter and Help System:
This is a huge plus. The presence of interpreter not only aids you in testing snippets of code, but it acts as an help system. Lets say we want to look up the functions that operate on a List.
>>> dir([]) ['__add__', '__class__', '__contains__', '__delattr__', '__delitem__', '__delslice__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__setslice__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort'] >>> help([].sort) Help on built-in function sort: sort(...) L.sort(cmp=None, key=None, reverse=False) -- stable sort *IN PLACE*; cmp(x, y) -> -1, 0, 1
Advantages of prototyping instead of pseudocode:
I finally ordered a new Macbook air for myself. One of my friends remarked at the fact that this is the first brand new laptop that I've ordered for myself. Since I'm a bit of a Linux fanatic, I tend to restore old computers and install a linux distro and make them useable. So I always get old laptops for cheap for myself. But this time I decided it's time to checkout Mac OS X. So I'll be replacing my Netboook (yep!) with the Macbook air. Anyone need a Lenovo S10 netbook :). I will even do a clean-install of Ubuntu or your choice of Linux distro.
This new Macbook air will be my primary development machine. Let's hope it can take the abuse.
A typical conversation between my wife and I:
Tmux is an awesome replacement for Screen. I have a couple of standard terminal layouts for programming. One of them is show below.
I have a small tmux script in my ~/.tmux/pdev file that has the following lines
selectp -t 0 # Select pane 0 splitw -h -p 50 'bpython' # Split pane 0 vertically by 50% selectp -t 1 # Select pane 1 splitw -v -p 25 # Split pane 1 horizontally by 25% selectp -t 0 # Select pane 0
In my tmux.conf file I have bound <prefix>+P to sourcing this file. So now anytime I want to launch my python dev layout, I hit <prefix>+<shift>+p.
bind P source-file ~/.tmux/pdev