
Olaf Alders - https://perladvent.org/2024/2024-12-23.html
Table of Contents
There’s More Than One Way To Do It
Perl is a programming language created in 1987 by Larry Wall. The name “Perl” is not an official acronym and is often interpreted as “Practical Extraction and Report Language,” although this definition is a backronym (assigned after the name was created). Larry Wall himself has said that Perl should not be referred to as “PERL” in capital letters but simply as “Perl”.
The language was born as a practical tool for system administrators, especially for text and file manipulation, with a philosophy of making simple things easy and difficult things possible, summarized in the motto TMTOWTDI (There’s More Than One Way To Do It).
Perl’s Strengths
Technically, Perl‘s power is undeniable. Some of its strengths include:
- Powerful text processing and built-in regular expressions: Perl is renowned for its ability to manipulate text very efficiently and flexibly, with native support for complex regular expressions, which facilitate search, replacement, and data extraction from formats such as XML, CSV, JSON, and more.
- Dynamic typing and context sensitivity: Perl allows for very concise and flexible code, adapting to the context in which an expression is used, making it easy to write fast and powerful scripts.
- Versatile data structures: It supports scalars, arrays, and hashes, including complex and nested data, useful for managing organized information efficiently.
- Cross-platform compatibility: Perl code is highly portable and can generally run on UNIX, Linux, Windows, and macOS systems without significant modification.
- Vast CPAN ecosystem: CPAN is a huge and well-organized library of modules that cover virtually any need.
- TMTOWTDI (There’s More Than One Way To Do It) Philosophy: Perl allows developers to choose between different approaches to solving a problem, ensuring maximum flexibility and adaptability to personal programming styles or specific requirements.
- Powerful File and Input/Output Management: Perl has powerful and simple commands for reading/writing files, managing input/output, and manipulating data streams, directly integrated into the language. It is considered one of the most effective scripting tools for this very reason, making it an excellent choice for automation scripts and text analysis, such as logs.
- Extensibility and Object-Oriented Programming Support: Perl can be extended with C/C++ code for performance needs and supports multiple paradigms, including object-oriented programming through dedicated modules.
- Context Control: Perl has a native “scalar context” vs. “list context” system that allows expressions and functions to behave differently depending on the context, an advanced technical feature that allows very compact and powerful scripts without external additions.
- Unicode and Multilingual Support: It is suitable for managing multilingual texts and international projects.
- Stability, Reliability, and Maturity: With decades of development and production use, Perl is considered stable and reliable for critical tasks.
In summary, Perl is highly regarded for its powerful text manipulation, flexibility, rich module ecosystem, and portability across platforms, making it a versatile tool for scripting, system administration, web development, and much more. On Linux operating systems, it is installed natively with the system. I use it almost daily: when I need to write a script of more than 10 lines, I prefer it to alternatives like Bash scripting.
Beyond its technical virtues, Perl has also been a historically important language. Early dynamic web development and the integration of scripts with relational databases, based on CGI (Common Gateway Interface) or cgi-bin technology on the web server, were done in Perl.
Perl’s Weaknesses
However, despite being a powerful programming language, it has never become as widespread as other modern languages. Some historical and technical reasons for this are:
- Complex and unreadable syntax: Perl‘s power allows for many things to be written in different ways, but this excessive flexibility easily leads to code that is difficult to read and maintain, especially in collaborative or large projects. This has earned Perl a reputation as “write-once, read-never”.
- Slow and confusing evolution: Perl attempted to maintain backward compatibility (for example, between Perl 5 and Perl 6, later renamed Raku), which slowed the language’s evolution and created uncertainty among users. Many developers waited too long for Perl 6, shifting interest to alternative languages like Python and Ruby, which grew rapidly during the same period.
- Competition from simpler languages: Python, in particular, has won over the community with its simple syntax, ease of learning, and readability. Although often less efficient at string manipulation than Perl, its clarity and rich ecosystem have attracted both new programmers and companies.
- Poor community organization: Perl‘s meteoric rise in the 1990s led to a lot of code being produced without solid development standards, resulting in poorly maintainable projects and reinforcing the language’s bad reputation, despite its technical qualities.
- Technical and performance issues: Although powerful, Perl is an interpreted language and sometimes slower than other compiled languages. It consumes more resources in certain situations, lacks a robust exception system, and for years its object-oriented programming was considered “odd” or inelegant compared to that of more recent languages.
- Limitations in the web and shared hosting environment: Integration via mod_perl, while powerful, is less secure and less suitable for shared hosting environments than mod_php, limiting Perl‘s use in standard web hosting.
- Lack of a robust static type system: Unlike many modern languages, Perl has dynamic typing, which can make it more difficult to prevent compile-time errors, which is important for large projects and extended teams. It is not a strongly typed language.
- Lack of modern development tools: Perl lacks sophisticated IDEs and effective static code analysis tools like those available for newer languages, making debugging and getting started more difficult for new programmers. This point, which is widely heard in the developer community, I disagree with: there’s always Emacs, which with plugins like LSP (Language Server Protocol), effectively transforms into a powerful IDE suitable for Perl.
- Less focus on concurrency and parallelism: Perl lacks a natively modern concurrency model comparable to languages like Go, Rust, or even Python and its libraries, which limits the efficient management of programs that must scale on multicore systems.
- Competition with broader ecosystems: Languages like Python offer up-to-date libraries for AI, machine learning, data science, web and mobile development, fields where Perl is less present and less supported.
Despite these challenges, Perl is successfully used in system administration, bulk text manipulation, and legacy infrastructure management. However, it remains, especially today, a niche choice compared to more modern languages for web and enterprise development.
Why Perl Didn’t Catch On
I believe that, given Perl‘s technical nature, its lack of widespread adoption cannot be fully explained by the critical issues highlighted above. I think much of the blame lies with the delays in the development of version 6, released but not universally adopted, not even by Perl programmers themselves (Linux systems still natively install Perl, but version 5).
The Perl 6 project was officially announced on July 19, 2000, at the Perl Conference, with Larry Wall discussing it in his State of the Onion 2000 speech, signaling the start of a complete rewrite and reorganization of the language.
However, the first official and stable version of Perl 6 was not released until much later, in December 2015. Throughout the 2000s, Perl 6 suffered numerous delays and development problems, which meant that the language took over a decade to take shape. Some beta versions were planned as early as 2002, but a full version was never released at the time. Perl 6 was renamed Raku to distinguish it from Perl 5.
Lately, the advent of artificial intelligence has required robust and powerful software libraries from developer communities. Perl, in my opinion, would have been a highly suitable language for these purposes, but by the time the need arose, Perl had long been out of the picture. So the choice we all know was made: Python.
Epistemology of Software Development: The Subjectivity of the Better/Worse Dichotomy. When Old Is Discarded for Non-Objective Reasons
I miss that now prehistoric era when Perl‘s motto still held true, when there were so many ways to do the same thing and solve problems. A true strength for me, but a professional attitude that’s now falling into disuse. Younger generations of programmers (not all) grew up and were educated in an environment where standardization reigns supreme: a kind of globalization that has also reached the world of software development.
This standardization has led to problems being solved in very few ways, using very few programming languages for very few problems. Even the editors and IDEs used in development have become standardized. Today, not using Python in the field of artificial intelligence conveys an impression of inadequacy and even incompetence. This is an attitude that I find increasingly unbearable.
Don’t be misunderstood. Python is a great language. In machine learning, for example, it allows for simple manipulation and visualization of data sets. But this virtue comes from the Python ecosystem, not from the Python core. I’ll return to this point later.
The downside is that if I want to work on these problems, I’m “forced” to use Python; otherwise, I’d struggle to write the code needed to do the same thing in another language. So, my personal preferences become irrelevant, and the luxury of being able to make a choice is no longer an option. As our technical choices become limited, and I believe this is true in any human field, creativity and programming style become flattened.
I’ll use a metaphor inspired by ecology. A lesson I learned while working on computational procedures: genetic algorithms (GAs). Why is it important to preserve and stimulate biodiversity (or population diversity in a GA)? Because each individual represents the solution to a problem: that of subsistence in a given environment. Different individuals solve the problem differently, and this heterogeneity allows all ecological niches to be filled. If the population becomes too homogeneous, if diversity decreases beyond a certain critical limit, then genetic recombination does not produce significant variations, leading to a state in which the problem is essentially always solved in the same way. Under these conditions, evolution slows down or even stops, resulting in a suboptimal population. In this situation, if the environment changes, individuals may be unable to produce the improvements necessary to keep pace. Diversity is the key requirement for enabling adaptation.
Every tool we have, developed over time, is the right tool to apply in specific fields or to solve particular problems. If we embrace Richard Stallman’s philosophy and consider software a form of knowledge that must remain freely available to all humanity, then even “old” or little-used tools must be preserved. They may still be useful in certain contexts, but even if they aren’t, they constitute human knowledge that must be protected.
An example is the Vi editor, the first version of which, developed by Bill Joy in 1976, was already so advanced and had such sophisticated memory management that it could handle files of any size. Imagine what more recent versions can do. Compare this technical feature with the equivalent available in simpler and more intuitive editors popular today when we need to work with huge files.
Vi, along with Emacs, is the alternative offered to programmers who still work the old way, like me, and both editors have evolved to accommodate contemporary technologies, such as LSP. But we must not forget that this technological leap was possible because these tools were developed by giants in the late 1970s and early 1980s, with such a solid and cutting-edge architecture that they could be integrated virtually without limits. And all without knowing what might come next. If modern editors can be compared to modern buildings, then Vi and Emacs are the Colosseum, standing for 2,000 years.
Vi and Emacs are niche tools, and you’d have to try them to understand their power. Why haven’t they become widespread? Because they’re considered difficult to configure and get working optimally, which is true. But the criteria for choosing technological tools should be based on technical potential, not ease of use, especially considering that those who use them are primarily programmers, people accustomed to complexity. If this criterion had been adopted in the choices made over the last 30 years, I am convinced that we would be using different technologies and programming languages than those most widely used today.
Another example is the native multiuser capability of Unix since its first release (and we’re talking about 1969). However, Unix evolved into Linux, which allowed for the mass diffusion of this operating system, and this is less clear than the example we gave of Vi.
Another example is Fortran, the first version of which dates back to 1954. The Fortran compiler architecture allows for object code optimized for the underlying hardware, making it a very fast language suitable for numerical and scientific computation. It’s so fast that not even C is faster. Proof of its performance is provided by the Netlib repository, the famous Fortran library for numerical computation. Over the years, it was rewritten in C thanks to the development of the f2c program, which allowed for automatic conversion between the two languages. Fortran is an example of an “old” but relevant language, with much to offer.
Like many other technologies.
Perl vs. Python
My impression is that Python‘s main strength over Perl (and many other interpreted languages) lies not so much in its native functionality but in its widespread adoption and community support, which has led to the creation of a vast ecosystem of additional modules and libraries. These modules cover virtually every area of programming (from AI to the web, from data science to robotics) and make Python extremely versatile and productive, even with a less comprehensive standard library than Perl.
If you exclude external modules and limit yourself to the language’s “bare” functionality, Perl remains technically superior in several contexts, especially for text manipulation, system scripting, and syntactic flexibility. Python has focused entirely on simplicity, modularity, and the idea that “less is more”, but the real revolution has been the community and the richness of its ecosystem, which today makes the difference and makes it preferable almost everywhere. Even when, on a purely native technical level, it is not the most powerful language. Its simplicity is a solid and objective strength, and it helped tip the scales in its favor.
Neither language has its add-on modules’ core developed entirely in its language. When power, speed, and efficient memory management are needed, one relies on C, C++, or Fortran. Python, for its AI extensions, uses these languages for the modules’ kernel and computation. Only the interface to these libraries is written in Python. The same goes for Perl.
Therefore, the power of Python‘s extensions, which are one of its strengths, is not derived from its intrinsic or native features. They are simply available, and we use them for that reason. Why they were developed in Python and not Perl is partly due to the simplicity of the former and the abstruseness of the latter (as well as the endless series of errors committed throughout the project’s history), but the choice cannot be attributed to Perl‘s technical incompleteness.
It is fair to base these considerations on a direct comparison between the two languages. Here’s a list of technical features I’ve identified:
- Text manipulation: Perl has a powerful and integrated system of regular expressions and string manipulation capabilities, which is considered more sophisticated and faster than Python in this native context. This makes Perl an extremely efficient language for parsing, extracting, and manipulating text and data in various formats. This allows for analysis, search, replacement, and string manipulation with more advanced syntax and capabilities without the need for external modules. Python introduced regex support later, but it remains less straightforward than Perl in this context.
- Syntax and readability: Perl allows for great flexibility in writing code, with multiple ways to achieve the same result, using complex operators and abbreviations. This provides power and versatility, but the syntax is often difficult to read and can be very complex. Python, on the other hand, was created with the goal of a clean, uniform, and easily readable syntax, which promotes clarity, especially in collaborative projects.
- Typing: Both languages are dynamically typed, but Perl has weak typing (with implicit type conversions), while Python is strongly typed, albeit dynamically. This can impact the way native data is handled. Perl supports scalars, arrays, hashes (dictionaries), and references to complex structures without the need to define explicit classes or types. This versatility is native and allows for the representation of complex data structures. Python has similar types, but some advanced structures typically require a bit more code.
- Performance and memory management: Perl is generally considered more efficient in terms of speed and memory for native text manipulation and system scripting. Python, while optimized and improved over time, can be more memory-intensive, primarily due to designs that focus on simplicity and code consistency.
- Programming paradigms: Both support imperative and object-oriented programming, but Perl has native functional programming features and more versatile data types, while Python strives for greater simplicity in its native data model. Functional programming is possible in Python but less “natural”.
- Unicode and string handling: Perl has had well-integrated native Unicode support since its most recent releases, although Python has greatly improved it. However, for advanced multilingual text manipulation, Perl still has its native strengths.
Conclusions
Despite trends and the objective strengths of other technologies, Perl‘s technical solidity remains, offering us a versatile and incredibly powerful tool for solving problems. I would have loved to see a motivated community creating Perl modules and libraries for AI. Python is a brilliant tool in this field, but I have serious doubts that it would have been able to hold its own against Perl.
In this world, unfortunately, the best rarely wins (should we revive the perennial Windows/Linux comparison?). But compared to other interpreted programming languages considered simpler and more elegant, like Python, Perl has built-in features that, while not technically perfect and complete compared to the state of the art in programming language design, are, for me, in a different league.
I believe that Perl‘s forgetting represents one of the greatest examples of “technological injustice” in software development over the last 50 years.