Why would you want to use Perl 6? Some answers.

2015/12/25

People ask me what’s so special about Perl 6. Well, there are a lot of answers to that. One of the answers is a long list of the things that make Perl 6 different from Perl 5, and that make Perl 6 different from a lot of other programming languages. So, here goes!

General topics

Perl 6 is a clean, modern, multi-paradigm language; it offers procedural, object-oriented AND functional programming methodologies.

Easy to use consistent syntax, using invariable sigils for data-structures.

Perl 6 is a very mutable language (define your own functions, operators, traits and data-types, which modify the parser for you).

Adding a custom operator or adding a trait is as simple as writing a subroutine.

Advanced error reporting based on introspection of the compiler/runtime state. This means more useful, more precise error messages.

Multiple versions of a module can be installed and loaded simultaneously.

System administration is simplified due to simpler update/upgrade policies.

Runtime optimization of hot code paths during execution (JIT), by inlining small subroutines and methods.

Runs on small (e.g. Raspberry Pi) and large multi-processor hardware.

Garbage collection based: no timely destruction, so no ref-counting necessary. Use phasers for timely actions.

Fewer lines of code allow for more compact program creation. Huffman-coding of names allows for better readability.

Text-processing

Full grapheme based Unicode support, including Annex #29, meaning almost unparalleled excellent Unicode support.

Regular expressions are cleaned up, made more readable, taken to the next level of usability, with a lot more functionality. Named regular expressions are made possible for ease of use.

Extensible grammars for parsing data or code (which Perl 6 uses to parse itself).

Execute code at any time during parsing of a grammar, or when a certain match occurred.

Scoping

Dynamic variables provide a lexically scoped alternative to global variables.

Emphasis on composability and lexical scoping to prevent “action at a distance”. For example, imports are always lexically scoped.

Easy to understand consistent scoping rules and closures.

Phasers (like BEGIN / END) allow code to be executed at scope entry / exit, loop first / last / next and many more special contexts.

Object-Oriented Programming

Powerful object orientation, with classes and roles (everything can be seen as an object). Inheritance. Subtyping. Code-reuse.

Introspection into objects and meta-objects (turtles all the way down).

Meta Object Protocol allowing for meta-programming without needing to generate / parse code.

Subroutine and method signatures for easy unpacking of positional and named parameters, and data structures.

Methods can be mixed into any instantiated object at runtime, e.g. to allow adding out-of-band data.

Typing

Multi dispatch on identically named subroutines/methods with different signatures, based on arity, types and optional additional code.

Compile time error reporting on unknown subroutines / impossible dispatch.

Optional gradual type-checking at no additional runtime cost. With optional type annotations.

Easy command-line interface accessible by MAIN subroutine with multiple dispatch and automated usage message generation.

Concurrency, Parallelism, Asynchrony

High level concurrency model, both for implicit as well as explicit multi-processing, which goes way beyond primitive threads and locks. Perl 6’s concurrency offers a rich set of (composable) tools.

Multiple-core computers are getting used more and more, and with Perl 6 these can be used thanks to parallelism, both implicit (e.g. with the >>. method) and explicit ( start { code } ). This is important, because Moore’s Law is ending.

Structured language support is provided to enable programming for asynchronous execution of code.

Supplies allow code to be executed when something happens (like a timer, or a signal, or a file-system event, or gui events).

The keywords react / whenever / supply allow easy construction of interactive, event driven applications.

Data-structures

Junctions allowing easy checking of multiple possibilities, e.g. $a == 1|3|42 (meaning is $a equal to 1 or 3 or 42).

Lazy evaluation when possible, eager evaluation when wanted or necessary. This means, for example, lazy lists, and even infinite lazy lists, like the Fibonacci sequence, or all prime numbers.

Lazy lists defined with a simple iterator interface, which any class can supply by minimally supplying a single method.

Native data types for faster, closer to the metal, processing.

Floating point math without precision loss because of Rats (rational numbers).

Large selection of data-types, plus the possibility to create your own types.

Multi-dimensional shaped and/or native arrays with proper bounds checking.

Automatic generation of hyper-operators on any operator (system or custom added).

Interoperability

Interfacing to external libraries in C / C++ is trivially simple with NativeCall.

Interfacing with Perl 5 (CPAN) / Python modules is trivially simple with Inline::Perl5 resp. Inline::Python.

Perl 6 runs on a variety of back-ends. Currently MoarVM & JVM, JavaScript is in development, more may follow.

So, and now, what to do now?

Install Perl 6, and learn how to use it, of course!

Getting started: http://www.perl6.org/getting-started/

For most people, download and installation instructions can be found here: http://www.rakudo.org/how-to-get-rakudo/

The simplest way to install Perl 6 is to use Rakudobrew: https://github.com/tadzik/rakudobrew/

MoarVM: http://www.moarvm.org/

Useful places to start learning Perl 6

http://perl6intro.com/ Perl 6 Introduction

http://learnxinyminutes.com/docs/perl6/ Perl 6 version of Learn x in y minutes

http://rosettacode.org/wiki/Category:Perl_6 Perl 6 section of solving problems with different programming languages

https://perl6advent.wordpress.com/ Perl 6 Advent calendar: every day leading up to Advent, a new interesting Perl 6 example

https://p6weekly.wordpress.com/ Perl 6 Weekly, with the latest developments in Perl 6

https://6guts.wordpress.com/ Perl 6 Guts, the newest innards of Perl 6 explained by Jonathan Worthington

http://strangelyconsistent.org/ Strangely Consistent, an insightful blog by Carl Masak

http://pl6anet.org/ Perl 6 Planet, a collection of blogs and articles

http://szabgab.com/perl6.html Screencasts about Perl 6, by Gabor Szabo

http://blogs.perl.org/users/damian_conway/ If you ever have the chance to attend a presentation by Damian, enjoy!

http://design.perl6.org/ Perl 6 Design Documents: This is the core of what is Perl 6

https://www.reddit.com/r/perl6 Reddit page with many useful articles on Perl 6

Get involved and contribute

The Perl 6 homepage at http://perl6.org/ links to many useful resources.

IRC: the channel #perl6 on irc.freenode.net discusses all things Perl 6. The people are very friendly and very busy developing Perl 6. Keep an eye on this to stay up-to-date. The channel is logged, and you can read back to see what has been discussed: http://irclog.perlgeek.de/perl6/today

Mailing lists: send an email with subject ‘subscribe’ to:

perl6-announce-subscribe@perl.org Announcements and news. Low traffic.

perl6-users-subscribe@perl.org User questions and discussions regarding the Perl 6 language and compilers.

perl6-language-subscribe@perl.org For issues regarding the Perl 6 language specification.

perl6-compiler-subscribe@perl.org For issues regarding various Perl 6 compilers

Have fun!