My personal Python mind set

Friday 18 November 2005

I was talking to a fellow Python enthusiast the other day, and the topic came up of Python's great dynamic nature. I said that I didn't think it had had that big an effect on me. He was surprised. "You don't like dynamic typing?" he asked. It's not that. Looking back over my experience with Python, it's not the dynamic typing that has affected me most. Let me explain:

Python fits my expectations: the dynamic typing was simply what my primitive monkey coding brain expected. There's a strong contrast to C++'s static-typing friction, and include file hell, but because of my mental expectations, that contrast feels like a point taken from C++, not a point given to Python.

When working in C++, the Python thing I miss more than dynamic typing are the easy to use built-in data types like lists and dictionaries. The amount of noise you have to introduce into your code when using the STL is just staggering. It's a true impediment to progress. Let's say I have an A and want a B, and there's a simple mental path between the two (string to split array, array to joined string, and so on). In Python (and most other "scripting" languages), it's a simple expression that makes sense. In C++ or Java, it's three or four lines of idiomatic yet still not memorizable code. I find myself having to go and find the last place I did it in the code, and copying.

Also, I haven't yet used a lot of Python's deeper mysteries: metaclasses, decorators, and so on. I've benefited from them in other people's code (like SQLObject's magic), but I haven't made use of them myself. I've built much larger systems in C++ and Java than I have in Python, so I haven't yet needed some of the raw power in Python.

But if I had to pick the biggest effect Python has had in me as a programmer, it's been about testing. My experience writing automated tests in Python projects is that I am freed from fear. I don't have to worry about forgotten corners of the code. I've tried to apply that mind set in non-Python projects. The change in philosophy about testing is a much bigger change in me because I can apply it outside of Python. I wrote code differently, and approach development differently. And I can use those concepts in C++ code, whereas dynamic stuff is left behind with the Python.

So no, Python's dynamic nature is not its defining characteristic for me. And to be perfectly honest, I have a lot of static typing habits that I'm still trying to break.


Joe W. 11:45 AM on 18 Nov 2005

A big change for me has been access to the python shell. I'd never programmed in a language with an interactive shell before and it can be really useful. Mostly I use it for testing functions as I write them, but it's also nice to use some of the python introspection tools to learn about new modules.

Jay P. 12:58 PM on 18 Nov 2005

I think I used to be where you feel you are now. The most important benefit for me was the fantastic built-in datatypes, and the testing tools. I didn't really get into a lot of the other dynamic properties.

Then I read PJE's "Java Is Not Python/Python Is Not Java" series, and my mind opened up. Specifically, his explanation of the property() function introduced me to a whole new world in Python I'd never thought of.

I was always writing getters/setters, doing things in a C++/Java style, with the benefit of great datatypes. Now I see a whole world of new possibilities, and using that new world over the last year has been a great experience.

Ian Bicking 4:08 PM on 18 Nov 2005

It always surprises me how strongly people react to the shell. Coming from Smalltalk (and other dynamic languages before that, all the way back to Logo and GW-BASIC), I spend much *less* time in an interactive Python environment in comparison.

I suppose when you compound the lack of a shell with the delayed feedback of a compile cycle, it must get really painful, and hence the shell seems like a tremendous freedom.

Ben Finney 5:17 PM on 18 Nov 2005

Hear hear. I've known about unit testing (and even xUnit style frameworks) for a while, but Python was the first language where I felt it was simple enough to just go ahead and do the tests up front.

Consequently, I'm now able to easily do test-driven development, and it doesn't feel like the waste of time it appeared to be with other languages.

Allister Sanchez 10:08 PM on 19 Nov 2005

For me, it's the way python groups its scopes. I've been so into C/C++/Java style of { } scopes. Python's interactive nature is quite familiar with me since I learned a lot about programming using CINT in the ROOT ( toolkit.

Add a comment:

Ignore this:
not displayed and no spam.
Leave this empty:
not searched.
Name and either email or www are required.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.