Schwuk makes reference to a post of Rory’s on why Python is no good. As Schwuk says, I might get annoyed by this, and he’s pretty much correct here.
You see, I think that a reasonable proportion of Rory’s complaints are a bit lacking. Take his complaint that you have to explicitly pass “self” to methods:
Sure, having to add self to a parameter list once isn’t any big deal, but three-hundred methods later, when the ink is worn off the S, E, L, and F keys, you might be thinking differently about it.
Take a glance at your close-curly-bracket key:
}. Has the ink worn off that? If it has, then I’ll start to listen to your complaint more. If it hasn’t then, well, obviously extra unneeded characters, like C’s curly brackets, aren’t that big a deal, eh?
I would have respected a choice to have ditched all 1.x hacks, but instead they were carried over to 2.x, so now we had the choice of doing things procedurally or Object Orientedally (yeah – I made that word up – bite me). What a bloody mess! Let’s see… Do I want to work with functions on my strings, or do I want to work with members of the string object? I hate that kind of crap.
I utterly don’t agree here. OO gives you the power to write decent proper applications; I entirely agree, and I pretty much find that anyone writing anything even vaguely substantial in Python uses OO to do it. But constricting the user to write in OO style is a
massive pain in the arse when you just want to throw out a quick script. I find myself doing things like
grep "some regexp" /some/file | \
python -c "import sys;print '\n'.join([x.split()[3] for x in sys.stdin.readlines if x.split()[6] == 'word'])"
If I had to wrap that in a load of OO bullshit it’d be loads more complex for
no reason. Similarly, a lot of the Python I write is short scripts to, say, grab an
RSS feed and rip some data out of it (the thing that reposts my SitePoint articles here is like that). Again, this is a quick procedural script: start at the top and work through the lines. They quite often don’t even use functions. If I had to swaddle that in OO bollocks it’d be more complex and slower to write and I would derive no benefit from it.
Notate bene primus: Perl people are saying “what’s all that sys.stdin.readlines() shite? This is what perl -n is for!” They’re right; Perl is even better at this sort of thing than Python is. I find that Python hits the sweet spot between the two; others differ.
Notate bene secundus: yes, I suppose I could do similar stuff with a sed/awk pipeline without going into Python. Fuck off.
Notate bene tertius: “orientedly“.
He’s right about all the underscores, though. Constructors being called __init__ is a pain in the arse.
In short, I disagree. However, each to their own and all that…
Update: further discussion on Schwuk’s original post.
I think you misunderstood my argument (or I simply didn’t communicate it well enough).
What I don’t like is the either/or approach. Python can maintain all its simplicity and strip itself of the Old World without having to go down some convoluted path.
Just as C#/Java apps have the concept of Main() (or main()), Python could have something similar.
The difference here is that you guys are talking about scripting, and the given example is very short. Mixing styles in such a short example isn’t a big deal, but would get pretty complicated pretty quickly for a full-blown app.
I guess it’s just that I think Python would be more useful if it didn’t have this duality to it.
I don’t think there are two alternative Python styles, procedural and object oriented; rather there are two layered OO styles, just using objects or defining classes and methods before using objects, and Java always requires the latter for no good reason.
Simple programs like the split/join one-liner in the example need only classes from existing libraries and complex programs need their own abstractions; but Python is completely object oriented in all cases, even when fancy features like comprehensions and generators are used.
The influence of dumbed down languages like Java has convinced people that
class Example{
public static void main(String[] args){
System.out.println("Hello world");
}
}
is more object oriented and better than
print "Hello world"
or
#include <stdio.h>
int main (int argc,char**argv){
printf("Hello world");
}
but the three programs do the same thing with the same object (the string) and vary only in the amount of additional cruft.
In fact the Java version, with its two useless classes Example and System, is a worse style of OOP than the unencumbered C version.
OO is bollocks period :-).
(But then I don’t write python anyway)