Perl 6 in a hands-on test
Double Down
Perl 6 gives the Perl 5 syntax a new paint job and introduces a genuine object system. Mike gives it a hands-on test based on a re-implementation of the old blackjack game.
You should never write off the old dogs: After decades of anticipation, Perl 6 finally seems to be taking shape. I found this out recently when I attended the grass roots Perl Conference YAPC 2016 in Orlando, Florida. About two-thirds of the talks were dedicated to Perl 5 topics, but to my amazement, more and more people in the community are seriously taking to the successor and problem child of many years standing, Perl 6.
No less than 11 years ago at the OSCON Conference 2005, Damian Conway seriously announced that the "endgame" of the development had started, but multiple setbacks and new beginnings ensued. Then, suddenly, at the end of 2015, the Rakudo virtual machine finally become operational, and although it does not exactly impress with its performance, it does at least reliably parse Perl 6 code.
What Is Perl 6?
To find out what you need Perl 6 for, it is helpful to analyze what Perl 5 lacked. Shortcoming number one was without a doubt a full-blown object system. In Perl 5, it was a makeshift affair, and no one in their right mind would have used the blessed hash structures, dubbed classes, without additional strictures in anything but toy-sized systems.
Instead, for the past 10 years, professional Perl developers have used the CPAN module Moose or one of its offshoots to define classes and access their attributes. This approach not only removes the need for developers to type tedious boilerplate code but also establishes a safety net, because the Perl engine immediately notices if a typing mistake has crept in. This is not the case if you have an incorrect hash key, resulting in undefined values being returned and random programmatic outcomes that are destined to creep up on you unawares. Any other modern language has solved this problem, but Perl 5 unfortunately only has a patchwork implementation for historic reasons.
Noisy Code
The makers, Larry Wall and Damian Conway, thus gave Perl 6 syntax for defining classes and invoking object methods that can take lists of named parameters. While they were at it, they adjusted some logical inconsistencies in the Perl 5 syntax that had proved to be pitfalls for beginners.
They didn't stop there, however; they kept going by borrowing syntax from various modern languages such as Python or Ruby, with the promise of practical use and clever programming tricks. The result is a language with a relatively large number of special characters that completely breaks compatibility with the old Perl 5 and needs a new interpreter named Rakudo.
Schrodinger's Cat
One of the smart and exotic new constructs in the new version involves superpositions, called "junctions" in Perl 6 and penned by Damian Conway. Conway peddled the idea 13 years ago at conferences, and later introduced it to the language in the form of quantum variables as a CPAN module by the name of Quantum::Superpositions.
Like the famous cat in Schrodinger's experiment [1] that is simultaneously dead and alive, these variables can simultaneously assume several values. For example, an integer can be 1 and 2 at the same time, and adding 5, gives you a result of 6 and 7. Back in the day, while trying to come up with a practical example for this, I remembered the casino game blackjack as an example, where an ace counts as either 1 or 11.
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.
-
Linux Sees Massive Performance Increase from a Single Line of Code
With one line of code, Intel was able to increase the performance of the Linux kernel by 4,000 percent.
-
Fedora KDE Approved as an Official Spin
If you prefer the Plasma desktop environment and the Fedora distribution, you're in luck because there's now an official spin that is listed on the same level as the Fedora Workstation edition.
-
New Steam Client Ups the Ante for Linux
The latest release from Steam has some pretty cool tricks up its sleeve.
-
Gnome OS Transitioning Toward a General-Purpose Distro
If you're looking for the perfectly vanilla take on the Gnome desktop, Gnome OS might be for you.