Perl 6 special cases

2016-09-28 11:26:01 admin Perl 6 0 Comments

The idea of special cases is not something new and it’s not strictly related to Perl 6. They’re not a problem, as some people have labeled them (especially people who don’t use perl 6), you can learn about them and get used to them with the right resource. Damian Convay at YAPC:NA talked a little bit of this, about how many language features defaulted to working on $_ and how many did not. Perl 6 can default to $_ , but not magically. To do that you need a . with the  $_ . Like so.

Another example given by Damian was the angle brackets and curlies. In the above example you have angle brackets, you could also have curlies but in Perl 6 curlies don’t autoquote. Things like these can be a bit confusing, especially for a novice, because you can’t really figure them out just by intuition and deduction. These special cases makes most developers shy away from languages that hold too many such special situations. They may be detrimental if the benefits they bring to the table outweigh the drawbacks that developers have to face. It’s depending to the circumstances. Perl 5 has quite a few operations that defaulted to $_  and you have to learn a few of them to be able to figure them out from context when reading someone else's code.

C has the postfix “++” operator, the only operator that performs an operation on a variable in-place, but whose value remained the same as the previous state of the variable. This way you only had one feature to learn, which made everything very easy for beginners.

The big upside in Perl 6 is that some of the irregular special cases that you find in Perl 5 have been improved, as in made more specific, for a better uniformity of code and language basically. $_  was used in many different operations in Perl 5, so you had to do a bit of guessing at times, but in Perl 6 it’s been more restricted, to only a few operations.

That doesn’t mean that Perl 6 doesn’t have special cases, (Perl is not the only one with special cases), but it gets better at offering a more clear understanding of them for the users and  yes, also to have less special cases for more clarity.

Tell us what special cases you ran into using Perl 6, Perl 5 or your language of choice.

Leave a comment


Subscribe to our newsletter!

Make sure you never miss the interesting stories of Perl startups, apps and projects.