Stop me if you’ve heard this one:
A Perl programmer and a Python programmer walk into a bar.
Python dev says “why are you using Perl, Python is much clearer”
“What do you mean”, says Perl dev, “how is it clearer?”
“It’s obvious innit,” says Python dev. It’s cleaner and better It’s got, er, objects and stuff.
C/C++ integration aside, has anyone got anything more meaningful than “cleaner and better” ? I’m genuinely curious.
I think it’s because TMTOWTDI became such a prevalent theme in Perl, so you had to learn more ways to read/write a program without thinking it’s wrong. Since python is more structured and less expressive, you have less to learn and if there’s anything people like, it’s learning less than you have to learn.
Of course, you also have to factor in that if there’s anything people like more than learning less, it’s following what’s trendy, and python became trendy at Perl’s expense.
A few things that I think contribute to this feeling:
The “batteries inside” approach of Python, meaning having a large standard library, let’s you write a lot of things without asking permission to install 3rd-party modules. It also means a lot of decisions were made for you, and people don’t like making decisions.
Python has the same syntax for a lot of similar tasks (e.g. iterating over strings, arrays (lists), hashes (dictionaries), files has the same syntax. It means less to learn both for writing and reading. It makes it easier to learn.
As everything is an object (even scalar values), it is easier to write an IDE that will show you “what methods are available for this thing”, which, again, makes it easier to learn.
I don’t know Python well enough to tell what are the disadvantages.
[FIXED spelling per comment below – Jared]
s/as the sam/has the same/
This is always the argument I hear too. Then again, I have recently been working in Python for work and there are two syntactically important uses for a trailing comma (print without newline, single element tuple), which I think is spectacularly ugly!
In the end, I think the root cause is this: Perl supports TIMTOWTDI, and Python is one of the ways so we don’t battle as much. On the other hand, Pythonistas tout one way to do it, which precludes Perl both because of TIMTOWTDI and more deeply since Python is available, it must be the one way to do it.
If you have half an hour to burn, watch Raymond Hettinger’s keynote at Pycon 2013: http://pyvideo.org/video/1669/keynote-3
His delivery style is like a cross between a used car salesman and a TV evangelist, and he gets (IMO) too excited about things that would be mere syntactic sugar in any language with proper scoping, but at about 8:30 in the speech he gets to the essence of your question. He says that in the year 2000, there wasn’t much difference between Python, Perl, and Ruby. Then he goes on to show the gains Python has made since then that (he feels) make it a big win for programmers in 2013.
Of course, if you don’t know any Python, you won’t know if you agree or disagree with him until you learn about the features he talks about, but it’s a place to start.
I do know some Python and even used it at $JOB back in the day. It was okay.
I know Python claims “there should be one—and preferably only one—obvious way to do it”, in an effort to be the anti-perl, but I’m not convinced. What is the one way to do web apps for example 😉 Even in the language itself, it’s got list comprehensions and generator expressions, lists and tuples, while and for …
@Gabor – not everything in Python is an object as anyone other than a Pythonista would understand the term.
“some objects have neither attributes nor methods… and not all objects are subclassable… But everything is an object in the sense that it can be assigned to a variable or passed as an argument to a function…”
@Joel – nice theory, but surely not applicable to Unix where Perl is always available 🙂
@Steve – any chance of a summary for those without half an hour to burn? 😉
Here’s a list taken right from the video, but it’s a just a bunch of stuff you’ve heard of before and you won’t be impressed. If you want to understand the appeal of Python to Python programmers, you’re going to have to sit through the long answer. “Tell my why Python is great but keep it brief” hardly seems fair.
1. Indentation
2. Iterator Protocol
3. Generators
4. List, set, & dictionary comprehensions
5. “Two-way” generators
6. Decorators
7. With-statement
8. Abstract Base Classes
I’m not a Python guy, but I have a lot of respect for what they’ve built. Several times I have considered learning Python deeply. So far, I’ve always been put off by “One Way to Do It” and by the community’s prissy whining about “beautiful code” (I don’t think “uncluttered” and “beautiful” are synonyms, but lots of Pythonistas seem to). While Python makes everything you’re *supposed* to do with it clean and easy, it makes a lot of things you may need or want to do very ugly. Oh, and I hate the word Pythonista.
But I still might become one some day.
I recently looked at decorators and was amused. They’re simply a special exception hard-coded in the language core to make up for lacking core syntax features.
Decorators are simply method modifiers *. But since basic language syntax limitations of python(no multiline lambdas), make it impossible to have the modifier declaration before the method body without having to mention the method name three times, they couldn’t be implemented in Python itself and had to be bolted on sideways.
* https://metacpan.org/module/Class::Method::Modifiers
Christian can you elaborate on your decorators comment? I’m not a Perl guy so I’m not sure what you mean by method modifiers. Decorators can modify classes, functions or methods… And you do usually declare the decorator first with a name (but only once) and then typically use the name to apply the decorator to the thing it’s decorating. I don’t know what you mean by “implemented in Python itself” – decorators are typically written by capturing the object to be wrapped in a functional closure and you certainly do write the decorator in Python…