3

Perl and Python are often compared to each other (let's not forget Ruby), and almost always those discussions will come to the conclusion pretty much anything you can do in one or the other.

Without going into that, I've noticed that Python however, is often used as an implementation language (uhmm, maybe the term here is incorrect technically - a language you use to, for example, enable some degree of scripting in a large application ... Tecplot, Rhinoceros etc.; these are from the scientific area; there are others surely) and Perl never (well, to my knowledge at least).

So I was wondering - what makes Python more suitable for something like that? What particulars make a language more suitable to be implemented as part of a larger app. for scripting in general? Is it only that that wasn't so common 10 years ago (scripting in applications), and Python is just at its peak at the moment, ... or something else?

5
  • 1
    My experience (probably out-of-date, ~10 years ago) suggests embedding Perl is not that easy, some details can get pretty hairy. Maybe Python is better in that regard?
    – StasM
    Commented Dec 18, 2010 at 1:18
  • @StasM - I hear you. But, Python was not really that popular 10 years ago, so that also should be taken into account (it came on my radar, some, maybe 5 years ago, tops). But anyways, I would be interested in the technical side of things also.
    – Rook
    Commented Dec 18, 2010 at 1:45
  • 2
    Just to add to your knowledge: Perl is a cornerstone in the DNA sequencing community. See How Perl saved human genome
    – mouviciel
    Commented Dec 4, 2014 at 8:17
  • For history, I can tell you that (a) python 1.5.2 final was released in 1999 and (b) python 1.5.2 compatability was a big issue for a long time because 1.5.2 was used in a bunch of distro-internal stuff in Redhat for a long time. At least I saw a lot of second hand mentions of the latter a while back. .... For Perl, I have heard people compare it to line noise and call it a write only language, but I know it gets used a ton and I haven't gone there so hard to say. I do remember thinking it was like INFORM (interactive-fiction lang) which I also felt was line noise, at first glance >.>. (#TADS)
    – Weaver
    Commented Dec 4, 2014 at 8:39
  • I'm voting to close this question as it's primarily opinion-based; this is shown by the answers we're getting which are basically just "I like X because Y" with no evidence that Y is actually significant in the industry. Commented Dec 10, 2020 at 9:04

6 Answers 6

11

Python is pretty easy to embed and has good documentation on how to do it.

Also, Python has a pretty approachable syntax, even for new users. Perl tends to have obtuse syntax making it less approachable for new users.

Another common language for embedding is Lua. It is known to be fairly easy to embed and has low operating overhead.

Python is well known and used in the Scientific community thanks to SciPy and NumPy, which may influence your particular observations.

3
  • Python sucks at multi-threading.
    – Job
    Commented Dec 18, 2010 at 5:01
  • 3
    @Job I'm not really sure how CPython's lack of true multithreading has anything to do with this answer... And I say CPython specifically because it's the only Python implementation with the GIL. Jython and IronPython both have true multithreading.
    – jsternberg
    Commented Dec 18, 2010 at 5:47
  • 7
    How does python suck at multi-threading? If you are building a CPU-bound application in python, then you are doing it wrong. Although Beazley did show a pathological case with mixed CPU-bound and IO-bound threads. (The Gil only exists in cpython, btw)
    – rox0r
    Commented Dec 18, 2010 at 6:56
6

If you're talking specifically about application scripting, it may simply be that Python is more approachable than Perl to a casual programmer, and thus the developer of the application decides Python would be a better experience for the application's users. Lets face it, Perl, while powerful, can be... cryptic... at times.

VBScript is also used a lot in Windows applications for this reason. Its something end users, not programmers, can cobble a small script together in without too much trouble.

1
  • That is surely one of the important reasons. Do you think the decision was based mostly on the ease on newcomers?
    – Rook
    Commented Dec 18, 2010 at 12:16
4

The term you are after is one of the following, they are (relatively fungible)

  • Embedded language
  • Application scripting language
  • Extension language

Lua, JavaScript and Python seem to be some of the most common of these, mainly due to the fact that there is a lot of support for embedding them, and their syntax is considered by many as simple and quite easy to learn.

A few other notable examples of extension languages, Java, used in Eclipse and JetBrains IntelliJ based IDEs. VimL / VimScript in Vim. Emacs Lisp in GNU/Emacs. (GNU also promote Guile, a Scheme variant as it's extension language of choice.)

At the moment, it's hard to say which language is most commonly used as Extension language, but Lua is extraordinarily easy to embed, JS and Python are relatively difficult (by comparison) but still not especially hard. MRuby has been developed specifically to be embeddable, however it drops a large part of the standard library as a result.

Within the Microsoft ecosystem, (since the introduction of .Net) CLR languages are all able to extend popular MS apps, VS, MS Office etc.

0
1

Is Python really more used than other languages?

It depends.

Let's have a look.

In OSS web applications PHP dominates the installations: WordPress, Typo3, Joomla, Magento, ShopWare, Moodle. Maybe the simple templates are a reason for it.

Don't forget that C/C++ is still the gold standard for libraries and system programming.

In academic science, the topics I'm interested in (AI, image recognition, language processing), most projects use C++, Java and/or Python.

Python is mostly used as a glue language just calling libraries. Or there are toolboxes and utilities in some areas (e.g. NLTK, font-utilities) making it convenient to use them out of the box.

In some fields Python is the dominating scripting language. Font making is one of them, where nearly all state of the art tools use Python. Maybe this is caused by history as FontForge supported Python. Nearly all font makers use Python now, also the ones using Perl in the past.

My personal point of view:

  1. as an admin of a web-server farm:

Python, Ruby and Java are a pain. Whatever the reason is, they make problems. PHP since version 7 is also a pain.

  1. as an application developer:

Perl is my preferred language. Robust, simple for simple problems, complex problems are easier to implement than e.g. in Python or PHP. Perl still has the best Unicode and Regex support. Sure, more keystrokes (~20%) are needed compared to Python, PHP or JavaScript.

  1. as a scientist

I still prototype in Perl (and port later some parts to JavaScript or C99). My project is mainly implemented in Perl. Either I can use other packages written in Python or whatever without change, or I port "academic quality" Perl/JS/C.

But the pain not using Python grows.

1

As a well-known Perl person, I have a few thoughts, and almost none of them are related to one language being better than another. Perl and Python, in the hands of skilled practitioners, can basically do the same things.

You mentioned the perhaps perl hasn't been embedded in anything. I know of or use embedded perls in apache, postgres, nagios, and exim. There are probably many others, but they aren't in the same problem domains that Python dominates.


So, let's think about that a bit more.

First, things take hold often by accident. Perl was initially popular in the biotech community because someone wrote some useful software and other people wanted to use it. If that first person had chosen some other language, people would probably still want to use that initial software. I've often found people will use the most convenient tool without caring too much about the language it's in.

Second, once something get a foothold, it benefits form a virtuous cycle. Someone builds a useful tool in some language and people start using it. Those people are probably going to stay with that particular language just because it's easier than switching or combining several languages within a project. People only have so much time to think about things. I don't mind working in many languages, but it does take a bit of mental work to switch from one to the other during the day.

Now, as for Perl versus Python, I've been thinking about this for an article for Perl.com (so if you want to tell me about your cool Python stuff, please do!). In my long experience with Perl, I've noticed that we tend to build things for other programmers or what we now call DevOps. There are some turnkey applications out there, but there's much more in the module/framework space to allow you to make applications. This tilts the Perl community toward the hard-core, full-time developer space and lots of backend development.

On the Python side, there are some amazing tools for "normal" people for non-programming tasks. For example, there's youtube-dl, a Python program to download videos. I can't think of that many turnkey Perl things I use that aren't programming tools. Exiftool maybe, but that still seems sysadminy to me? It's not that some other language would have trouble doing this, but the group of people that gravitated to a particular language decided to work on more user-facing things.

Some people don't like Perl's syntax, which is fine, and those people probably aren't the sort that spend quite a bit of time doing shell or systems programming. Perl makes a lot of sense if you come from a unix-heavy background, and if you haven't seen some of those concepts things appear weird (and this is where I like to geek out in my Learning Perl classes). Perl is this beast of a language that pulls in C, awk, sed, shell, BASIC, and anything else Larry Wall thought was useful for getting sysadminy work done. Many of the people I've worked with as Perl programmers work in several languages. That's neither virtue nor vice, just that Perl is the sort of language that attracts that sort of person.

Guido Rossum wasn't designing a language to run the world. He had worked on the teaching language ABC and came up with an evolution of that. The items in the Zen of Python make a lot of sense if you are thinking about classrooms and instructional design. Sometimes those languages escape their initial uses (heck, Macs used to use Pascal!). Since they tend to be simpler or more straightforward, people tend to like them for shorter tasks. I see it similar to how PHP displaced Perl from the CGI webspace. It was a simpler tool that completely satisfied the people doing that stuff.

1
0

Python is easy to embed in C programs and it is easy to add C modules to python. Python has a lot of inroads in scientific computing with sci.py and numpy, so it is a natural fit for scientific apps.

2
  • 2
    Although true, I don't know how much that matters practically. Usually all such needs are covered by the language in which the app was written in originally, so pyth. is used solely for scripting (handling of data mostly). Very rarely users use it to handle computations. But yes, that is also one advantage.
    – Rook
    Commented Dec 18, 2010 at 12:19
  • @rook - Sure, it is possible to do anything in an equivalent Turing language. Manipulating a subset of the application doesn't require the low-level features of C. And by choosing a higher level language for scripting, user scripts can be cross-platform and the user doesn't need to worry about memory management.
    – rox0r
    Commented Dec 20, 2010 at 15:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.