Friday, April 18, 2008

Away from the dark side - Python

Our Python guy is off sick, so I've spent a week hacking the language. I had looked at Python a few years ago, but this time its personal.

So these are the impressions of a novice - and someone coming from Perl at that. I will probably come-up with justifications and solutions for the shortfalls as I learn, they are probably a mark or my ignorance rather than anything wrong with Python. Having said that, I was surprised how many things are missing.

The good
1. Forced code formatting
2. No stupid sigils
3. OO built-in
4. Default variables in a function are not global
5. Documentation
6. OS specifics are removed from the core
7. Excellent string handling
8. Intuitive file IO
9. Method calls on built-in types instead of weird system variables
10. No GOTO

The bad (IMHO)
1. No constants
Even True and False can be altered!
2. No scoping within loops and 'if' statements
All variables outside functions are globals
3. No interpolation - an effect of the lack of sigils I guess
4. Comparisons between numbers and strings give unexpected results, and NO WARNINGS! A poor and surprising feature
5. I know ++, --, +=, etc. are arguably poor coding, but I missed them.

Still, 10 good and only 5 bad.


Paddy3118 said...

"All variables outside functions are globals"

- Not really, Python has a powerful module system as well as classes that have their own namespaces.

Welcome to Python :-)

- Paddy.

Clive said...

Thanks for the welcome.

"Python has a powerful module system as well as classes that have their own namespace"

That'll be just like Perl then - except that is not what I meant.

The criticsm is that the level of scope of a function is too course. C and Perl have block level scope. This is difficult for Python to achieve since (so far as I can tell) there is no variable declaration syntax.

Clive said...

+= is now supported
Python 3 resolved the problem of comparing different types - an exception is raised, as it should.