Sunday, May 18, 2008

Culture Clash with Python

I first looked at Python around 1997, for reasons lost to my ever failing memory, but already being a rather big perl-head by then, I didn't go much past the "Hrm, neat" stage.

I've since decided to give it a real go and am studying a bit from online sources. On one hand there are aspects I really like (large extensive library, big support, stable; and even some aspects of the Python "way", since sometimes, but not always, TMTOWTDI is a PITA.

There is one aspect though that just really clashes with me; the community is VERY quick to point out how you're wrong. It doesn't matter about what, it's just you're wrong. I've found that most of the time, I am, but there's this absoluteist tone that I sense that makes me completely understand why the community has the "Pythonista" term applied.

For example, if you want to join a list with a delimeter, the way to do that is like so: string_delimeter.join(<list, tuple, etc.>) # i.e. ", ".join([1, 3, 4, 7, 10])

Ok, that's just a bit backwards from what I'm used to. I want to join THE LIST with the delimeter. It's a small cognitive dissonance, but it's there. When looking at the FAQ about this, it says ... I'm wrong. No, that's not what I want to do. The exact quote is:

The second objection is typically cast as: “I am really telling a sequence to join its members together with a string constant”. Sadly, you aren’t.

Well, yes, yes I am. Like I said, a small nit, but it could have been phrased in less absolutist verbiage, (and the counter example of "split" is inconsistent with what it's saying, but I digress). Ok, so I get past that. (And there is another less odd looking, but less "OOish" way of doing that if I find I can't stand it. So Python ISN'T just 1 way to do it for everything after all!)

So, playing around, I wonder what happens when I try to join a list, err, sorry, "telling my delimeter to iterate my list and insert itself" (rolls eyes), when it contains the equavalent of a null, namely Python's "None".

", ".join(['a', None, 'b']) # => a,,b?

Nope. Exception. Ok, I can accept that None has no default conversion to a string, and I can accept that there's no easy way to do it (Is there? If there is, IRC folk didn't know, and told me I was wrong for even deigning to ask), but I find this behavior a bit irritating. What was the result when I mentioned this? Not that I'm expecting the wrong thing (I am), or even that I was quick to jump the gun to find this irritating (I was), but rather, I don't find it irritating. Excuse me? I'm pretty sure that I do. "Nope, you don't."

Then there's the PEP standard that calls for no more than 80 character lines. I've been programming professionally awhile, and 132 was all the rage almost 30 years ago. There does seem to be some debate about this, and going over my latest java project my line length averages 37 chars (over some 100k lines of code) so I doubt this would really affect me in any meaningful way, and too, I doubt I'm going to be putting any code into Python's already outstanding standard library, but the discussion around it was just what I've come to find out as typical.

I happened to come into IRC when this debate was going on, and although it was mostly good natured, one of the reasons for 80 is that anything over 80 is unreadable. Not, "*I* find it hard to read over 80 character lines.", or even "GUIDO hates it", but >80 is just absolutely unreadable, for anyone. Questioning that, or even mentioning that YOU can do fine with 132, 150, 180, 250 character lines just about has you burned at the stake since you obviously do not, and cannot float like a small stone.

Lastly, and this is probably confirmation bias, but whenever I come across a blog post comparing, contrasting, teaching, explaining, or anything with a programming language, there is almost inevitably the "Why don't you try it in Python?", "X sucks, you should do this in Python", "Python does this all better, see?" set of bleats and whines. It is the same tenor as the nice young men in their white shirts and black ties coming to my door trying to push their version of God on me. Actually, now that I write that I DO realize that what I'm feeling with some of this community has strong similarities to fundamentalist religious methods of conversion. Hrm, interesting.

So, I'll continue learning as I do find the language very interesting, although I haven't really found it to do things in any sort of way other languages cannot with as much or more expressiveness.

3 Comments:

At May 18, 2008 at 11:53 PM , Blogger Anonymous said...

Hi there. I am an editor of The Python Papers, a journal covering Python topics. I think you'll find the attitudes you mention all over the internet, not just in Python fora. We have included some articles on how communities can be very competitive and even combative in their communications styles. I would simply say that there are some people who are very committed to the Python "way" and some of those people are pretty forceful about it. On the other hand, I think there really *is* merit to the Python "way", largely because it helps to flatten the learning curve. It means that you can't just do things the way you want, but it also means that a lot of common coding tasks are done pretty much the same way everywhere.

My favourite things about the Python way are:
semantic whitespace
reasonable list comprehension
"consenting adults" approach to inheritance
duck typing

My least favourite things about the Python way are:
80-character line limit
when people hijack the "Python way" to advance their own position

 
At May 19, 2008 at 3:27 AM , Blogger Paddy3118 said...

1. Welcome to Python :-)
2. Ditch that IRC.
3. Try comp.lang.python!

I have come to realise that a community is built on compromise, and if you are late to the community, past compromises have already become rules.
The folks on comp.lang.python tend to be very accommodating to new-comers (especially if you are polite - often if you are not).

Your specific issues may well have been debated several times in the past - but that is no reason for the IRC people to be impolite), try a blog search. On that 80 line rule then if you don't like it - break it. The style guide was formed after much discussion between people of strong opinion who realised that theneed for *one* standard for library code outweighed the fact that it may not be *their* preferred way to do things. (Welcome to that club).

A lot of what I write is for me so I have the luxury of being able to stray from the style guide - I am particularly fond of a two spaces indent scheme - but I find that things go better on blogs with smaller line lengths, and functions that fit in 60 lines by eighty characters do fit nicely in my editor. On the string.join thing then yes it may not be intuitive, (for me as well), I have been around when the community has discussed it in the past and take the opinion that Python gets it right more often than not. Decisions are discussed at certain times when it is much easier to get things changed. There *is* useful later discussion on language design whhere it is rightly harder to get things changed - but things can get changed.

Woops - work becons.

Please persevere with Python, but change your community?!

- Paddy.

 
At May 22, 2008 at 9:35 AM , Blogger Calvin Spealman said...

I am an op over at #python in Freenode and fully admit to more than my fair of what I like to call "aggressively helpful" behavior.

Look at it from our side, where all these questions you've faced with aggravated responses are brought to us every single fucking day. And we want to help. We do. Really. That's why we stick around. But we get so worn out dealing with the same trivial things over and over and over again, just waiting for the few interesting things to come along.

I could attack your direct complaints (like how join is a method of strings because you can join far more than just lists and, personally, when I use join, I'm usually using it on something that isn't a list. Every developer of an iterable shouldn't have to support that same method when it can be implemented just once on strings).

Also, you can't join a sequence containing ANY non-strings, and not because we can't imply a conversion to string (because str(None) works just fine), but because we want to make sure you know what you're doing. Rather than imply the conversion, we let you ensure you really are building what you intended. Explicit is better than implicit, as the rule goes.

But about the community itself, I understand the stress when new users come in and we can be a little aggressive. But, we're usually right, too. Is that a fair trade? I remember being endlessly frustrated with this when I first learned Python, and now I'm one of the most aggressively helpful people around. Sure there are some negative reactions, some people even leaving, but the overall result of this attitude is that most newbies quickly become good developers, so we're doing our job (for free, i might add).

I piss people off, but they walk away smarter.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home