Scherprechter neemt poolshoogte

(I decided to limit myself to one rant a year. This is it.)

Just saw this blog post (via Hacker News): Dear Python. In it, the author lists a number of complaints he has about Python.

There is so much wrong with this article that it’s like shooting fish in a barrel.

First of all, the post seems to imply that Python started out great, but then added inferior copies of features found in other languages:

But then you got jealous of the big players. You saw that others had things you didn’t have and you wanted to compete in a game that you were never destined to play. And who could blame you? The megaliths in the crowd like Java and c++ were beginning to overshadow the small guys and were even starting to overtake some of the oldest and wisest players: c, Fortran, lisp. What did they have in common? Objects.

Objects have been around since the very first public release of Python (0.9.1). They were not added because of “object envy”. Hell, Java didn’t even exist when Python first came out.

But you weren’t ecstatic about objects. You didn’t really like them and you didn’t trust them. So you decided to only give them a little. You cut corners. You made objects but you made them hard to use. That was a mistake.

That’s another odd argument… IMHO, Python’s objects are *much* easier to use than, say, Java’s, or C++’s, where you have to micromanage access (public? private? protected?), write (often superfluous) getters and setters, and deal with such niceties as as “final” classes, checked exceptions, abstract classes, interfaces, etc. In Python, I can just write the class, stick in it whatever I want, *use* it however I want, and move on.

There is no encapsulation. There are three tiers to OO. One of them is encapsulation. Having OO without encapsulation is about as nice as sawing a leg off a three legged stool. I can hear you yelling, “That third leg is completely unnecessary. We’re all consenting adults here. Just balance, like this…” *crash*.

I am assuming that by “encapsulation” the author means “data hiding”. Python’s philosophy here is that in order to separate interface from implementation, data hiding is not necessary. That’s where the “consenting adults” idea comes from; you are *supposed* to talk to the object using its interface (methods or properties, usually), but if you really have to, you can easily access any attribute. There are ways to make this harder, but (again, IMHO) they are not very Pythonic.

Also, the notion of “three tiers to OO” really depend on which definition you go by. Java, C++, C# and their ilk are neither the first word in OO, nor the last. Languages like Smalltalk, Self and Io have (sometimes radically) different ideas about what objects are and how they are handled.

Then, libraries:

However, these libraries are inherently static. This means that if the library doesn’t do what you want it to, you are screwed. There is no diagnosing or fixing errors in the library. If they happen, pack up and try a different language.

I’m not sure in what sense Python’s standard library is “static”… there are a few built-in modules written in C, but most of them are in pure Python, and the source code is readily available. You could change them if you must, but a better approach would be to subclass them and replace the offending features/bugs. (Note that there are no “final” classes and private attributes to get in your way here. :-)

(The httplib problem mentioned looks like it can be solved by setting a proper timeout value, by the way. I’ve written several web crawlers in Python, and never encountered this issue.)

Then there’s the tired old “explicit self” argument again:

[...] But sadly, this is exactly how python is. It doesn’t really take care of anything for you. You have to have “this” as the first argument to every function in a class. Once in a function, you have to use “this” to access any variables or other functions.

I’ve written about this before (in 2003!) so I’ll just links to those posts here, rather than repeating it:

And here’s what Guido himself has to say about it: Why explicit self has to stay.

The Java way is better. The implied this is easy to understand. Some IDE’s even highlight the class variables with a different color than the local variables, allowing an easy distinction. In the end you save tons of characters by having an implied “this”.

The implied this (in a method’s argument list) may be easier, but Java gets away with this because it doesn’t have actual functions. Python, as a multi-paradigm (god I hate that word :) language, does, and in fact methods are really just functions that you stick in a class.

Also, the “tons of characters” you save don’t mean much, when a typical Java method definition starts with stuff like “public static final void …”!

To add insult to injury, python has no explicit support for member definition. A class’s members are created by setting them equal to something. There is no way to explicitly define them in the class definition. Anybody, anywhere, can add (or remove) members variables from a given object. Classes in Python are more like dictionary objects with functions attached than classes.

Um, yes, the lack of declarations is one of the factors that makes Python code shorter and more flexible. And indeed a class (or an object) is much like a dictionary with some special rules added. Hint: the same is true for languages like C++ and Java, except they hide that dictionary behind a ton of cruft, so you won’t notice it as much.

I agree that removing attributes from a class or object generally isn’t a good idea, but then again this doesn’t happen a lot, unless in special cases.

After much frustration at using your broken OO, I decided to give it a rest. Maybe python would make more sense if I just treated it as a flat procedural language. Then I noticed lambdas. [...] They can only be one line.

Agreed, Python’s lambda sucks compared to functional languages (and even Ruby). However, it was intended as a shorthand for simple functions, not as a full-fledged alternative to def.

Python, you are just like the little kid Peter. You see something others have, decide you must have it, and then you just stick it somewhere. To become a better language, you must outgrow this little kid copy cat phase.

If you want objects, implement objects all the way. This includes things like encapsulation and variable definitions. But if you don’t want objects, then don’t implement them at all. It is no help for anybody when you implement something that you don’t want people to use.

This really makes no sense. “Implement OO like Java, or don’t implement it at all”. Gee, go tell that to the authors of Smalltalk, Io, Self, CLOS, Simula, OCaml, even Ruby. Again, what “object oriented” means isn’t written in stone, and Java’s implementation of it certainly isn’t the gold standard. I don’t think the original inventors of OO intended the language to get in your way constantly, for starters.

~

Granted, Python has its problems. Over the years, these have become more clear to me. I am mostly infatuated with ultra-dynamic and/or functional languages at the moment (but that is a different story…). I don’t like the join method on strings, the fact that we have classmethods/staticmethods/etc now and all that drivel, and I would have liked the language to be more flexible, for example. But all of these criticisms are fairly minor. Python is still the language I am most comfortable with, and the language I reach for first in many cases.

So, yeah, I can understand people’s frustrations with the language, but this is just completely wrong. And what is this !@#$ about Python being a copycat language?! Yes, some features were borrowed from other languages — list comprehensions come to mind — but there aren’t that many examples of it, and it’s hardly the only language that does this. In fact, if I’m not mistaken, Java, C++ and C# all have grown features borrowed from dynamic languages… except such features tend to have limited use in a environment that is statically typed.

:: Comments (3)

Math vs programming (part I)

Wow, my previous post sure stirred up some controversy (by my blog’s standards at least ;-). As I write this, the comments are still pouring in. (Also see the Reddit thread, which is probably where all these new commenters come from.)

But really, what I was trying to say is quite simple:

  • I am a programmer.
  • I am *not* a mathematician (obviously :-).
  • If given a choice, I would much rather see the code sample (which I can understand) than the formula, although in an ideal situation you’d have both.

For some reason, some people seem to take “I don’t like to read mathematical formulas” to mean that I know next to nothing about math. This assumption is not necessarily true. Nowhere did I mention anything about my background, other than the fact that I am not a mathematician. (For the record, I studied economics in college.)

Anyway, whatever my background, seeing convoluted (and even not-so-convoluted) mathematical formulas tends to intimidate me (much like it intimidates *everybody else* who doesn’t have a strong grasp of this stuff). Not because I am inherently unable to, but because I lack the knowledge about what most of these symbols and constructs mean, in the given context. As I am a programmer rather than a mathematician, I prefer code samples.

Some people are apparently offended by this. Take, for example, this eloquent rebuttal. “How can you forget stuff like the meaning of Σ or Π as accumulators?” Gee, let me see… maybe because I have never needed it in my job as a programmer? You learn it. You don’t use it. You forget about it. (The formula, that is, not the concept.)

Let’s take the vector example in the original article. Some seem to think it’s ridiculous that I would prefer the code over the formula. But tell me… why in the world should I know vector notation? Or why would I want to, in the first place? I’ve been programming since 1985, and I have *never* needed vectors. I guess I haven’t been doing any real work!

For some reason I never needed differential equations either when I was trying to debug a GUI app or write an SQL query. And all this time I thought I was an actual programmer! Silly me!

Now, I am not trying to downplay the importance of computer science, or the importance of math in computer science. There are certain areas of programming that are strongly math-related, and wouldn’t exist without it. I also believe that having a decent grasp of math makes one a better programmer. 1) It’s important… but not to the point where you have to be a math major in order to be a competent programmer!

Many (or even most) areas of math are completely irrelevant to my day-to-day work. While this is not true for everyone, it is true for the vast majority of programmers. So I don’t like to read mathematical formulas. How does that affect my skills in designing a GUI, writing an object system, debugging a database, optimizing a query, writing unit tests with good coverage, refactoring a code base, …?

Anyway, in my next post I’ll react to some of the more reasonable replies to my post. :-)

1) And so does a decent grasp of philosophy, sociology, linguistics, art, organization skills, emotional intelligence, …

:: Comments (2)

I suck at networking

Not just in the “sucking up to people hoping to reap the rewards later” sense of the word, but especially the computer-related sense. I tried to make the G3 clamshell talk to my MacBook, or vice versa. Should be a piece of cake, with File Sharing and all that. It isn’t. Reason unknown. They see each other in the “Network” tab alright, but when trying to access I get “The server may not exist or it is not operational at this time. Check the server name or IP address and try again.” Makes no sense. All settings seem OK. I used to be able to connect without problems from Windows, but that machine is borked. Oh well. I’m going to call it a day now, I already wasted a few days last week trying to set up communication between Windows PC and the 1541-II.

This wouldn’t be really worthy of a post, if I had not had this problem for as long as I can remember. Networking & I don’t mix.

[Update 2008-03-02] OK, maybe I don’t suck *that* much after all. I knocked the Wii from my network, and suddenly things started working. Apparently there have been cases where the Wii interfered, although the reports are scattered and vague.

:: Comments off

Breaking out in hyves

With friends like these: Interesting article, or rather a rant, about FaceBook and similar sites. (via)

I dislike sites like FaceBook too, and especially MySpace, but largely for personal reasons. <rant> Somebody I know likes to abuse these sites to spread lies about her homelife and pretty much anything else. This behavior actually seems to be fairly common, probably because said sites tend to be infested with teenagers. They’re not really my favorite demographic, mostly because many of them profile themselves as cam whores, attention seekers, and/or emo kids. 1) Unsurprisingly, this is closely related to the stupidity level of these sites… full of “surveys”, polls, gossip, and valuable info about who is going out with whom. Also, MySpace encourages butt-ugly designs, and annoying stuff like music embedded in web pages. 2) </rant>

OK, so I wanted to vent a little bit. :-) And yeah, I’m aware that bloggers could be considered attention whores too. ^_^'

However, I actually don’t have much of a problem with the other issues mentioned in the article. (Although I skipped over the capitalist stuff.) I am also not surprised that these sites exist. “What was wrong with the pub?” the author asks. Well, not everyone is an extrovert who likes to be around people all the time. Before teenagers took over the internet, talking to people online was actually a great way to find new friends. (Or wives… ;-) Plus, you get to meet people that you would never have talked to otherwise (e.g. because they’re shy or live far away).

And yeah, the internet in general makes it easy to have many superficial friendships. But it’s not like that wasn’t possible before. (In fact, the anonymous person mentioned before thrives on such contacts.) Some of my best friends I have never met in person (or at least, not yet). My experiences may not be typical, but the possibility of lasting friendship is very real.

1) I say that, and yet my best friend happens to be a teenager… :-)

2) At least FaceBook, and hyves.nl (a Dutch MySpace clone) are bit cleaner looking.

:: Comments off