Python is a voluntary language

by John on October 26, 2011

People who write Python choose to write Python.

I don’t hear people say “I use Python at work because I have to, but I’d rather be writing Java.” But often I do hear people say they’d like to use Python if their job would allow it. There must be someone out there writing Python who would rather not, but I think that’s more common with other languages.

My point isn’t that everyone loves Python, but rather that those who don’t care for Python simply don’t write it.

Since Python isn’t a common choice for enterprise software projects, it can resist the pressure to be all things to all people. Having a “Benevolent Dictator for Life” also helps Python maintain conceptual integrity. Python is popular enough to have a critical mass of users, but not so popular that it is under pressure to lose its uniqueness.

I don’t know much about the Ruby world, but I wonder whether the increasing popularity of Ruby for web development has created pressure for Ruby to compromise its original philosophy. And I wonder whether Ruby’s creator Yukihiro Matsumoto has “dictatorial” control over his language analogous to the control Guido van Rossum has over Python.

Related posts:

Plain Python
Ruby, Python, and science

{ 1 trackback }

Frattanto nella blogosfera #38 « Ok, panico
10.28.11 at 02:21

{ 27 comments… read them below or add one }

1

Alejandro Weinstein 10.26.11 at 17:04

May be related:

http://www.paulgraham.com/pypar.html

The Python Paradox, by Paul Graham

2

Florian Gilcher 10.26.11 at 17:53

To answer your question about Matz and Ruby: its pretty much the same situation. If a feature/change doesn’t fit Matz idea of the language, it won’t be accepted. He is pretty strict about such things as well.

3

John Venier 10.26.11 at 18:40

Full disclosure: I have written very little Python.

I like a lot of things about Python, but one design decision that still makes my skin crawl is that the amount of whitespace is syntactically meaningful. I suppose with a decent editor / IDE this is not a big deal, but ugh. Even FORTRAN77 with the magic columns had the good sense to avoid this. Perhaps I’m showing my age (or decrepitude) but I believe my visceral reaction is Pavlovian.

Of course, I dislike the syntactically meaningful whitespace in makefiles, as well, and for similar reasons don’t like a particular language’s “feature” (which may be mercifully eradicated by now) which made the underscore character shorthand for assignment, so you could avoid the onerous burden of typing two characters instead of one.

But come on, can’t we learn from mistakes? Anyone want to use APL these days?

4

Shrutarshi Basu 10.26.11 at 18:41

Python also has made significant inroads into academia, both for research and education — much more so than Ruby. And there I think it’s seen as a more flexible alternative to Java. A lot of students I’ve spoken to prefer Python over Java unless they need the infrastructure that Java is noted for.

5

John 10.26.11 at 18:57

John: The whitespace thing sounds like a big deal until you try it. Python only requires you to indent your code the way almost every C++ or Java programmer already does. So as long as you follow conventional formatting, the braces add no value. With Python, unconventional formatting is illegal, preventing bugs of the sort that come up in C++ due to misleading indentation.

Makefiles are evil because invisible distinctions matter, i.e. a tab character versus spaces. You can use tabs in Python source, and Python has clever rules for handling them, but nearly everyone just uses spaces.

Python doesn’t have the issue Fortran had with column numbers. You don’t have to squint at a file and check whether a character is in column 6 or 7. The spacing is relative. For example, the instructions that belong to an if block have to be indented more than the if condition, and all indented the same amount, but it doesn’t matter how much they’re indented.

6

Craig 10.26.11 at 19:35

I’ve been in the Python camp for a long time. Wanted to learn Ruby for a while, mainly for Rails. Decided this week that Django is it for me. :)

I found there great Python articles today.

http://bit.ly/sdJ4w0 (decorators), http://bit.ly/uQ4Q0v (metaclasses), http://bit.ly/up3Cth (generators/yield). I had not previously dealt with decorators or metaclasses. Cool stuff indeed.

I write C++ at work!!!

7

Janne 10.26.11 at 20:11

A do use Python because my work requires it — it has become the standard scripting language for computational neuroscience. If I had a choice, though, I’d work in Ruby.

Even after years of using Python I’m still not comfortable with the whitespace thing. And it’s less discoverable than Ruby; I still have to constantly look up stuff to recall how to do particular things. Why on earth, for example, do you have to do len(s) to find the length of a string, not s.len()? There’s even a method s.__len__() (quick, is that one or two underscores on each side?) that does it, but the natural way of finding it is missing.

Yes, I am happy it’s Python and not Java, C or Forth. Given a choice, though, I’d still rather use something else.

8

John 10.26.11 at 20:20

Alejandro: Thanks for the link to Paul Graham’s article. I agree that it’s important to look for evidence that a programmer candidate actually enjoys programming and takes the initiative to learn things that aren’t absolutely required.

Janne: I heard an explanation for why len is a function rather than an object method or property, but I can’t recall it. I guess I wasn’t convinced or else I’d remember the reasoning.

One quibble I have with Python is abbreviations like “len.” Why not use three more characters and say “length”? Oh well.

9

Christopher Allen-Poole 10.26.11 at 23:10

Python, to me, is the most mathematically pure language in common usage today. Along with Lisp, it is one of the true realizations of the definition of “function” as outlined in “The Calculi of Lambda Conversion” — if you read McCarthy’s history of Lisp he comments how “the only thing he understood” (yea, right) was the definition of a function f(x,y,z) as really f(g(h(z)y)x), this lead to the creation of the “inner most evaluation” which Lisp is known for. A major reason I view Python as so elegant is that it realizes the other definition proposed by Church in that treatise. The function f(x,y,z) can be described as f(*t*) where *t* is the tuple (x,y,z).

I believe that this similarity in ideology is a primary reason that both of these languages place very little difference between the idea of a closure and the broader ideas of object-orientation. It is the reason that generators and continuations are so similar… I could go on.

Python, for me, represents the second language construct which I have sat down and actually admired the language (Lisp being first, C being third). It is truly a thing of beauty and elevated van Rossum to my relatively short list of true heroes.

10

Christopher Allen-Poole 10.27.11 at 02:18

John: On the other hand, abbreviations like “len” are incredibly common in code in other languages. For example, I will generally use the variable name “len” as a part of a for loop to avoid re-calculating it every time. I’ll also use “ret” to mean “returned value”, etc. I don’t really see how this is any different.

For that matter, why shouldn’t C/C++/Java require “integer” and not “int”?

11

James McKay 10.27.11 at 02:27

Just thought I’d weigh in on the whole whitespace thing.

As far as I can see, whitespace being syntactically significant in Python is a good thing for the simple reason that it enforces code hygiene in terms of indentation and code formatting. There are some very good practical reasons why it’s important to be consistent with regards to indentation: diffing and merging in source control is one such example. Another is being able to speed-read your code and see where your code blocks begin and end: if you’ve ever had to make sense of a codebase with inconsistent indentation you’ll know exactly what I mean.

12

Scott Pierce 10.27.11 at 07:50

I like the whitespace rules. I find that I do it naturally in any other language anyway. Of course, that could be a matter of having been conditioned by 12 years of coding in Python.

13

Christopher Allen-Poole 10.27.11 at 08:00

Personally, I think that anyone who’s ever decided to learn Python has had reservations about whitespace… until we start using it on a regular basis. Actually, I have had the thought, “Man, these {} are really a complete waste of time.” since then.

The inclusion of “whitespace is significant” is actually something which was not a simple engineering decision (I’ve read at least one author who said that it actually causes some rather intricate problems), but it was very purposeful. It went along with the desire to make Python a very readable language and it works.

14

Craig 10.27.11 at 08:08

@Christopher

Yeah it’s funny everyone’s Python code has a certain way of looking the same. It’s a nice side effect of whitespace is significant. It certainly lowers the bar where reading other people’s code is concerned.

With “{}” languages style and readability are so varied, so much in some cases as to make reading anyone’s code very difficult, even before you start trying to understand what it’s trying to do.

15

Paulo Matos 10.27.11 at 08:19

Here’s a data point: I write Python at work but I would rather not…

16

Christopher Allen-Poole 10.27.11 at 10:02

@Paulo

I had a friend from High School who is into serious doctoral work (RNA combinatorics or something to that effect). He works a lot in Perl and Python. When I asked him his favorite language he replied, “whichever one I’m not using”.

17

Paulo Matos 10.27.11 at 10:11

@Chris, that is certainly my feeling sometimes but not with Python. I really dislike Python. However, it is the language of choice for scripting in the company where I work. Most of my other work is with Assembler and C. In my free time I make myself happy by writing some Racket.

18

Paulo Matos 10.27.11 at 10:14

@Chris, I re-read my last email and it feels like I dislike my job. Actually it is quite the opposite. I have never been happier with a job. I like 95% of it. That’s the part that doesn’t involve writing scripts in Python. :)

19

Daniel Nilsson 10.27.11 at 11:30

@Christopher, if you appreciate LISP and Python for being “mathematically pure”, be sure to check Haskell out. I love all three languages (and I tend to write Python-code most) but when it comes to purity and consistency Haskell is in a league of its own.

20

Christopher Allen-Poole 10.27.11 at 13:28

@Daniel I’ve heard, and trust me, it is on my list of “need to learn”. Unfortunately, I am still tempered by use case — given the choice I would love to spend more time in something more functional or academic, but I have a career to mind and, for now, Python seems to hold the most elegance while still being useful in the business world.

21

Sol 10.27.11 at 14:48

I’ve never done any significant work in Python, so this is not an attack on that language. But I will tell you what scares me about significant whitespace.

I’ve been programming for nearly thirty years now. In that time, I’ve managed to smash the whitespace in a section of my code probably hundreds of times. If you’ve got braces, that’s just an inconvenience. It seems like it would be a much bigger issue in Python.

Now, of course, given the modern-day world with undo and version control, that’s probably a very minor issue. But old prejudices die hard.

22

Greg Corrigan 10.27.11 at 20:32

We’re knee deep in a PHP project. I’m sneaking in Python with support services and scripts wherever I can, but the more time I spend in PHP, the more I enjoy Python.

I agree with @Christopher, all these { }’s are really annoying. Well, PHP as a whole is pretty incoherent and a hideous mess.

23

Christopher Allen-Poole 10.27.11 at 20:45

@Greg HEY! Don’t Be Hatin’ PHP

Yes, it is in-elegant at times, but PHP is a very practical language and it is really good at the things which fall within its problem domain.

24

James Thiele 10.28.11 at 10:28

I used python on a project that was integral to the electronics of Boeing’s new 787. We used it to interface with and maintain the database that held all of the physical (wire and fiber) and logical (messages) interfaces between all the electronics. I don’t know if you call that “enterprise” software, but it will have to be maintained for the lifetime of the 787 fleet which will be decades.

25

John 10.28.11 at 10:45

James: I’m not saying Python isn’t used in enterprise applications. Only that it’s nowhere near as common as, say, Java or C# for such projects.

26

Christopher Allen-Poole 10.28.11 at 10:47

@James & @John:

Reminds me of my favorite van Rossum quote:

Bill Venners: I once asked James Gosling about programmer productivity. His answer, which I consider to be the strong-typers view of weak typing, was, “There’s a folk theorem out there that systems with very loose typing are very easy to build prototypes with. That may be true. But the leap from a prototype built that way to a real industrial-strength system is pretty vast.”

Guido van Rossum: The leap is also a folk theorem as far as I can tell. That the leap from prototype to system is so big is just as poorly documented as the ease of prototyping.

27

Joe 10.31.11 at 18:52

John: Is this the article on `len` that you were thinking of?

http://lucumr.pocoo.org/2011/7/9/python-and-pola/

If not, it’s still an excellent article on the principal of least astonishment in Python and its rationale for such exceptions. Also, as someone who writes in Python because I very much enjoy it, thank you for sharing these thoughts. As always, a great read.

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>