Sunday, May 21, 2006

Use the right style

One of the things I have learned is that there is great value in being familiar with more than one programming language. The value of being 'multi-lingual' increases if the languages are from different families as well. Without digressing too much - programming language trees are usually horribly incorrect. I saw one where VB.Net was pictured as a derivate from VB 6, and not from C#, what it effectively is (may with a dotted line coming from VB6?).
I never realized the style issue until I got better at writing Python code. Before that, the only languages I knew where Pascal, Visual Basic, Javascript, and C++ - and there is, quite honestly, not much difference in coding style between VB and C++. The possibilities might be different, but the chosen solutions are conceptually the same. After all, they're both Algol-like languages.
It took my a while to figure out why I had such a hard time with larger Python projects: I was trying to design them as Algol-like solutions. Not that Python is completely Lisp-oriented, but once I started to think of tuples as basic variable primitive object types, solutions became elegant instead of just efficient.
Forcing good practice or habits from one language into another is not only dumb, it prevents you from writing efficient code. For example, unlike most languages, VB doesn't exit a function when the return value is assigned. Which is convenient, because it allows cleanup before exiting the function (DAO recordsets have a history of leaking when not explicitly closed). If you're unaware of this, or you force yourself do do an exit function immediately after assigning the return value 'because any other language does it this way', then you'll end up with storing the return value in a temporary variable, cleaning up, and returning the temp. value. And probably showing off your ignorance by telling all your 'coderz' friendz how uncool VB is.

No comments: