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
-
Fedora 39 Beta is Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.
-
UbuntuDDE 23.04 Now Available
A new version of the UbuntuDDE remix has finally arrived with all the updates from the Deepin desktop and everything that comes with the Ubuntu 23.04 base.
-
Star Labs Reveals a New Surface-Like Linux Tablet
If you've ever wanted a tablet that rivals the MS Surface, you're in luck as Star Labs has created such a device.
-
SUSE Going Private (Again)
The company behind SUSE Linux Enterprise, Rancher, and NeuVector recently announced that Marcel LUX III SARL (Marcel), its majority shareholder, intends to delist it from the Frankfurt Stock Exchange by way of a merger.