Thoughts on Perl and Emacs, technology and writing

Why did Google choose Python?

I wouldn’t get into google (their interviews don’t select for my brand of genius). But that’s fine as I wouldn’t be able to write perl there anyway.

I was trying to think of a few reasons why Google would have chosen Python over Perl as their primary scripting language. A number of the ones I came up with are less relevant than they used to be.

Python integrates better with C++

Boost.Python promises seamless interoperability between the two languages. It has been a while since I’ve been tempted to embed a scripting language in my C++ apps so I’m not sure what the counterpart is in Perl if any.

Python "threads"

Back in the day, these were better than the Perl offering. More recently, on Unix at least; with Coro, AnyEvent, Twisted, etc. it’s a wash.

Windows Implementation

A few years ago, the various Perl Windows implementations were not very high quality. Strawberry Perl has changed all that though. It’s awesome.

Jython et el.

Was Jython around when Google was choosing Python? I guess it was.

Perl (5) hasn’t escaped its VM as well as Python and Ruby. Having said that, the Jythons and JRubys of the world are always second class citizens compared to the original C VM as no-one can be bothered to rewrite all the C extensions.

Easier to avoid making a mess as a secondary language?

Experts in either language can write clean, efficient code. But what about folks who are expert in C++ and Java and use either Perl or Python on the side and only occasionally?

I think such usage for a large system will result in unwieldy code in either language, unless the large system is curated by experts, but for small to medium systems in the absence of experts, python may have the edge.

Rabid anti-Perlism

Even smart folks I know seem to think Perl is lacking in some way in comparison to Python. I haven’t managed to get them to enumerate any reasons though so I figure they are speaking from a position of ignorance. This could have been the case for the folks making the decisions for google too or, more likely, they may have considered some of the other reasons on my list.

Well, why shouldn’t they have chosen Python? I obviously prefer perl myself, but you’ve got to standardize on something, right? At the time google got started, anti-perl snobbery was already pretty widespread in the CS world (as near as I can tell, they were grossly offended by Larry Wall’s suggestion that they didn’t know what they were doing, and overstated the counter-claim).

As for your Boost.Python question: I’m working in libperl++. It’s pretty good at embedding, but a bit fragile at extensions so far. Also the toolchain is rather immature, in particular on Windows. I’m still working on it but it’s more work than I had hoped for…

I think you’re missing “Assumption that Python and Java would replace Perl programmers.”

Which seems to be true more or less. You could also replace “Perl” with “C++.”

Instead of Python being the obvious winner, it’s highly fragmented with PHP probably being at the top of the numbers game – at least second compared to Java, followed perhaps by C#. In terms of the hotness factor, it seems to be Ruby.

Which reminds me of the joke about 10 million flies on a piece of cr*p…

I’m not happy when some products/APIS are only exposed on python or java.

Also google API/frontend changes are… just like… python :), today works with today code, do not try to run yesterday one, and do not forget to update tomorrow changes on tomorrow version. 24/7/52. paid support. like canonical, oracle and fills, etc. consumerism strategies, at a side of open-looking-blablabling-never-end-working-fine-without-support.

Give a ninja a Perl interpreter, and will make the job of a hundred classes of monkeys. Not too enterprise, without the nine numbers labor budgets and the logos, but will do it .

@Joseph – the question why shouldn’t they have chosen Python isn’t really interesting to me. And sure, there are advantages to standardizing. But there are advantages to accepting a number of languages too – you don’t need to turn away a Marc Lehmann or an Adam Kennedy or a Dave Rolsky (or, I dunno, an Ian Bicking), if you allow Perl *and* Python usage. The downside is that you need to implement your infrastructure accessing libraries once for each language.

@tempire – ah yes, the language advocate. I should have included that in my list.

@Leon – thanks. I was hoping someone would come up with a perl equivalent to Boost.Python. I’ve amended the link in your comment.

@Terris – that’s another good suggestion I missed. Although I would say that Java had clearer advantages (and disadvantages) over C++ than Python had/has over Perl.

It’s an interesting thought that Perl has benefitted because it is not easy to re-implement the VM so it was saved from fragmentation. Perhaps that’s true.

@Poisonbit – me too. I’ve been able to use Perl extensively at the jobs I’ve had so Google using Python is a bit meh. Lack of access to their APIs is a bit annoying though.

Good stuff, but I think the most important reason is the powerfullness of pythons efficiency, you can finish writing a web bot with under 50 lines of code, or programming a n-gram algorithm within several hours in Python, also as mentioned Python integrates perfectly with c or c++ which are used for high performance or concurrency stuffs.

@avazu: Thanks for the pointless pro-Python FUD and advocacy. People can program n-gram algorithms or web bots in Perl just fine using similar amounts of code and time, or do you think not having to type braces saves that much?

@avazu – if powerfullness (sic) was the primary concern, perl would have been chosen over python. It had more and better libraries and a larger community. Over time, it has closed the gap but, TIOBE not withstanding, is still behind.

I would agree that in fact a programming language and the results it yields are determined by the people using it. I think both, Perl and Python are very good choices. Pick one, and try to get the best out of it …

The reason why Google is using Python certainly has to do with “how powerful” a language is (how many lines do you need to implement foo) and how it integrates to other languages e.g. C++.

>>> if succinctness == power:
… print(‘You are using Python’)
…
…
You are using Python
>>>

“Boost.Python promises seamless interoperability between the two languages. It has been a while since I’ve been tempted to embed a scripting language in my C++ apps so I’m not sure what the counterpart is in Perl if any.”

Well, have a PhD student with no experience in programming write a program in Python, and I can actually read and debug it without too much effort. And he/she’s likely to understand what I did, as long as I refrain from using too esoteric structures (which in Python are actually harder to do than the clear ones – most of the time at least).

That’s where I see a clear advantage of Python: It’s readable by default.

Very late entry into this thread, but I thought I could shed a little light on a couple of interesting points. First, Google hired Guido van Rossum long after they became a big Python shop so he wasn’t the internal advocate who originally got them started using it. I don’t have a clue as to who it was that pushed them to use it.

Second, many programmers started moving from perl to Python several years ago because Python really is that much easier to use. I myself used to use perl exclusively in my job as a systems/network admin but moved over to Python for most tasks a long time ago.

The best article I ever read on the differences between perl and Pyhon was written by Eric S. Raymond back in 2000:

* “In order to scale to hundreds of millions of Web pages, Google has a fast distributed crawling system. A single URLServer serves… URLs to a number of crawlers… Both the URLServer and the crawlers are implemented in Python.”

The folks at Google chose Python, probably because that is what they learned while at the University. You can write extremely good applications in any programming language, provided you put the required effort in testing and quality measures.

This is like asking in what language can you write the most beautiful love letters, in English, German or Spanish ?

Particular applications will come out faster or better if they have had better versions available at the start time.

I believe the human kind should work more on sharing the good ideas and methods and less in comparing which method is better.

Eric Raymond says it best:
Perl code is just a mess when you look later at it, it is hard to know what you did there, unless you are one heck of a master programmer that does nothing else in life. For me this is a question of new against old. Perl is the old, Python is the new. I am amazed of how easy Python code is to read and I am strictly not a programmer, have never been good at it, but with Python I am writing code and even build GUIs that work. The time effort required is also ok. I did not think such a thing would be possible, after looking at Java, VisualBasic, bash scripting, C and Perl, that Python could be so different, but it is. Things might be different if you are highly invested in Perl, but as a newby that did not know neither Perl or Python, Python is definitely the better choice. I applaud that Google chose Python, as many companies have a Perl only policy and for me this is a little “we have always used it and will always use it”, so tradition against new stuff.
And Perl can become a huge nightmare, especially for larger projects, when Spaghetti code tries to strangle you.

The kicker for me is ctypes, I’ve done XS in perl, and I know there’s some work being done on a Perl Ctypes, but it’s not yet as straightforward or as polished as the Python implementation. Makes it painless to prototype in Python and kick functions down into C as necessary.

Where Python wins over Perl, for me, is interoperability with C. That is crucial. It sucks in Perl, it is arcane and hard, and to this days, the Perl community has not given a shit about it.
As far as language design goes m odern Perl, with stuff like Moose, makes it much more advanced than Python. The fact is, Perl is faster and more powerful than Python, which has serious design flaws. Today’s Perl object system is almost as advanced as Common Lisp’s (which is the more advanced object oriented system out there).
But if your language plays well with others (C, C++) then you get network effects.

To me, the single reason is that python is a cleaner and better programming language. At google, I doubt it has anything to do with C++ and Java. I do not know other google projects in C++, but for the few I know, they even do not use STL, let alone the more complicated boost. Jython is a much worse implementation in comparison to CPython. I have not seen any of my python/java fellows considered Jython.

One factor not mentioned is extension into the mobile world of Android and iPhone devices. I hate to write it, but AFAIK, from what I understand, Perl as a compiler is much more complex and harder to implement in a resource-constrained device than is Python. I haven’t looked lately, but Python for Android is available, whereas Perl for Android?
In general, it is best to (be able to) develop in one language for all platforms (e.g. Java).

Python is good for people who are not professional programmers, likewise php, and need a trivial task to get done. But if you are a professional and need a real functional programming language with full-features (closures, call-backs, lexical, local differences, full-access to the symbol-table and so on) perl is the best choice.

Interesting read (comments as well). The main insight I haven’t seen mentioned yet is the entirely different philosophies between the two languages. Perl’s attitude allows many methods/styles to accomplish tasks, and frequently uses assumptions/context sensitivity to make things easier to one fluent in the language (makes sense as Wall is a linguist). This results in a larger model to keep in your head when programming Perl, which equates to having more to relearn if you aren’t using it full-time.

Python’s attitude is to keep things minimal and to assume nothing. Python presents a consistent model that requires less memorization. There are fewer ways to do something, sure, but doing things in a transparent way that is maintainable is the point of software engineering vs. “hacking”. The point of the code is to convey your ideas to other human units, not merely to make the computer do things with stuff.

Python is kind of a subset of Perl in that Python is more of a technical and organized language where clarity and precision are required. Perl is like non-technical human language (more or less) with a great degree of expressiveness and terseness (think poetry, philosophy). On a large engineering project the technical subset is a requirement, so why not literally use a different language instead of putting forth extra effort to reduce the more powerful one?
Simply put, Perl is for hacking, and Python is for engineering (a subset of hacking).

–Just my 2-cents as an embedded guy who doesn’t work high-level enough to warrant learning all of Perl (but who wishes he could justify learning it).

quote:
———
Python is kind of a subset of Perl in that Python is more of a technical and organized language where clarity and precision are required. Perl is like non-technical human language (more or less) with a great degree of expressiveness and terseness (think poetry, philosophy).
————————-

I would not agree with that statement of Python being a subset of Perl.

Well, that would explain a lot that the creator was a linguist. That would explain why Perl is such a mess and to state that human languages are properly and clearly organized and tidy is a gross error. Human languages are a gigantic mess, often grown and extended, full of contradictions and outright errors and things that do not make sense in any shape or form. They can be seen as beautiful, but beautiful like a labyrinth in the way that it is overly complex and twisted, not organized and efficient.
I’m a linguist in that I speak 6 languages fluently and I tell you it was a huge pain and gigantic effort to learn them all, I spend most of my life doing it.
But my logic mind really hates the mess these languages contain. The advantage of a programming language is that it is more mathematical and clean and structured. And it makes sense to me now why Perl is such a unreadable mess and takes a lot more effort than Python to create larger projects with and for code maintenance.

Esperanto, as the most widespread artificial language shows how beautiful a human language can be, how clean and organized, how devoid of contradictions and exceptions, how easy to learn and use.

But then I guess beauty is in the eye of the beholder:
Some might like a tangled mess of cables that organically blend together and look like something out of nature. But then there are others that want their cables untangled and cleanly arranged and easy to manage.

I’ll address your comments in English so others can read them. I should clarify that I mean Python is conceptually or philosophically a subset of Perl (in syntax, not in power). Python is intentionally restrictive so that it suits “formal” coding 100% of the time, whereas Perl lets you use slang, contractions, context, and other features which are nice when you are doing one-liners but unruly when you are trying to make a large program.

I’m no linguist, but I know enough about various languages to know that they are all very difficult to become proficient at. Even Esperanto is more difficult than they would have you believe (but several orders of magnitude easier than a national language). Perl is nowhere near as irregular or disorganized as a natural language (a computer can understand it just fine), but the traits it inherits from them make it more suitable for “everyday” scripting tasks than for organized software projects.

One reason to avoid (or pursue if you like that kind of stuff) Perl is that you can have a program with source code organized (garbled) in the shape of a few beer bottles that runs and prints the entire “99 bottles of beer on the wall” song. Impressive, but I try to avoid black magic. (It’s actually made with a program that takes advantage of Perl’s ability to run code within regular expressions from my understanding).

I’ve been programming for 20 years, and have read hundreds of thousands of lines of c, c++,perl, python, ruby, java(script) code. IMO: the statements about how “more organized” and “easier to understand” python is is rubbish. The primary factor in readability is the effort of the developer to make things readable. I’ve seen plenty of unreadable, un-maintainable python code written as a tangles of factories, classes and libraries. I’ve seen the same mess in perl, c/c++, ruby and (maybe more often than the rest?) java. Structure is everything. And a framework doesn’t count.