Results matching “perl6”

Python is The New "Write-Only, Linenoise" Language

As a Perl 5 programmer of about a decade, I'm well aware of how it was referred to at some point or another as the "write-only" and "linenoise" language. With the newest addition of the baby Perl 6 language to the Perl family, I fear that I must declare (wildly speculate) based on my extensive research (a boring ride on a bus, while staring at my phone) that Python steals that title now!!

Why Python? Blame whoever made the Stackoverflow Python Report scroll through my Twitter feed. I merely picked two problems from that list and asked myself what would the Perl 6 solutions to them look like.

Interleave Two Strings

The top rated item of the week is interleaving two strings.

#Given:
u = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
l = 'abcdefghijklmnopqrstuvwxyz'

#Wanted:
'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz'

The accepted Python answer is this:

res = "".join(i + j for i, j in zip(u, l))
print(res)

Certainly isn't bad, but using a two-variable postfix for loop inside a method call is something I wouldn't want to read in code very often. Let's examine the Perl 6 version:

say join '', (u.comb Z l.comb)

Just like the Python version, we're utilizing the join(), but the rest looks certainly cleaner: we're using the .comb method on our two strings, which without arguments returns characters in a string, and we combine them with the Z zip operator. That is it! No loops needed. (And before someone points it out, no, I haven't missed any sigils. Perl 6 can have sigilless vars, baby).

Round-Robin Merge Two Lists of Different Length

Another interesting item on the list is round-robin merge of two different-length lists. There isn't an accepted answer to the question, so I'll go with the highest-voted:

list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
list2 = ['x', 'y'] 
n = 3

iter1 = iter(list1)
res = []
for x in list2:
    res.extend([next(iter1) for _ in range(n - 1)])
    res.append(x)
res.extend(iter1)

>>> res
['a', 'b', 'x', 'c', 'd', 'y', 'e', 'f', 'g', 'h']

I see a for loop, and another for loop, .extend method and then .append method and after another .extend after the outer for loop, voilà! Result.

Being a Perl 6 noob, I first reached for the trusty Z operator, then I messed with the Hyper Operators, and all I got in return were either wrong solutions or messy solutions... Until someone pointed out that Perl 6 actually has a roundrobin routine! So what's the Perl 6 answer?

my @list1 = 'a' .. 'h';
my @list2 = <x y>;
say flat roundrobin @list1, @list2;

# >>>
# OUTPUT«a x b y c d e f g h»

On the first two lines, we're simply creating two variables for our lists. @list1 uses a range with letters and @list2 uses the quote word construct. I'm sure similar things exist in Python too, so I won't count clarity and ease-of-writing points for those, but the rest of the code is rather different. There are no loops, extends, or appends. We use the roundrobin routine to... surprise... round-robin through the two lists. Now, it returns a Seq of Lists, which is why I added the flat routine as well, to flatten the output to what the Python answer returns.

EDIT: as one of the commenters pointed out, I wasn't paying much attention to this one and completely missed the "nth element" requirement. Never fear, however, the alternate requirement only needs the addition of trusty .rotor List method that breaks up a list into sublists:

my @list1 = 'a' .. 'h';
my @list2 = <x y>;
my $n = 3;
say flat roundrobin @list1.rotor($n - 1, :partial), @list2;

# >>>
# OUTPUT«a b x c d y e f g h»

Summary

This post is, of course, a tongue-in-cheek joshing, based on a random post I saw on Twitter. However, on a more serious and deeper note, it does seem that the brand-new language like Perl 6 that has an actual language specification, when compared to an old grandpa specless language like Python, seems to offer built-in methods, operators, and subroutines specifically geared to real-world problems that—for however short a period of time—made it to the top of a popular programming question website.

And now, if you'll excuse me, I'm off to make a silly YouTube video declaring Python to be the new "Write-only, Linenoise" language. Sorry, Perl. You lose.

Update 1

As I'm not the one to shyly sit in a silo, I went to #python on irc.freenode.net and asked for feedback on this article, and it's this:

In the first example, the use of the for loop is extremely idiomatic Python, so the code is perfectly readable to a competent Python programmer. As for the second Python example, the general opinion was that it's overly-complex and I did see a simple 1-line round-robin example presented to me in-channel. The nth element variant may be dropped to me on Twitter as well in the future :)

I stayed for some drinks, there was cake too! And then I left the channel...

The Perl 6 User Experience

A person's experience with a programming language involves many aspects: how a user first learns that a language exists, their first steps in that language, their process of learning more about it, developing in it, contributing to it, and spreading the word about it are all part of that experience. In short, it's a huge swath of elements, which is why it's important to have a means to efficiently identify any issues in that experience, so that it can be improved.

I'd like to announce the creation of The Perl 6 User Experience Repository. Its main page enumerates various aspects of the Perl 6 User Experience and the sub-pages will outline plans to overcome any of the identified problems, or perhaps serve as a documentation repository for protocols, lists of contacts, or other additional files.

A valuable aspect of that repository is the Issues tab where anyone can bring up an issue with any aspect of the Perl 6 User Experience, for possible consideration and improvement. A set of Issue labels corresponding to main sections listed on the main page has been created, so the Issues can be tagged approprietly.

Having a centralized place to raise such issues should prove more useful than an occasional grumble on an IRC channel, a blog post, or a Reddit comment. Those things tend to slip through the cracks and get forgotten.

Main Sections

Here are the main sections currently available. At the moment, they're the result of one mind's work, and thus I fully expect changes: more sections added, sections removed, changed, or expanded. PRs are welcome.

Finding Out Perl 6 Exists

The rest of the User Experience can never exist if no one knows Perl 6 exists. Are there any issues that need to be addressed when it comes to people finding out Perl 6 is a thing? Do the marketing materials deliver their point? Do blog articles, social media posts, and news items about Perl 6 ever reach the ears and eyeballs of those who aren't familar with Perl 6?

Getting Perl 6

Once interest sparks up, how does a person get to the point where they can run some Perl 6 code and have it work? If they care, can the person understand the difference between, say, Perl 6.c the language, Rakudo 2015.12 the compiler, and Rakudo Star the distribution? And if they don't care, is it still easy for them to "install Perl 6"?

At the time of this writing, this is a section where a definite problem has been identified and a plan of action has been put in place.

Running Perl 6

Installation is just one step. How easy is it for a user to run a Perl 6 program? Such a program may require the functionality offered by a module in the Ecosystem. Is the search feature functional enough to find such a module? Is the toolchain usable enough to correctly install that module?

Developing in Perl 6

A Perl 6 programmer produces modules and programs. Is there a toolset available to simplify that process (e.g. a dist-minting toolkit like Dist::Zilla in Perl 5)? Is it easy to package a Perl 6 program so that it can be sold to a customer or deployed by someone not knowledgeable about Perl 6?

Getting Help and Training

Efficiently programming in Perl 6 is tough if you can't get help when you run into issues or don't receive proper training. Do Perl 6 and its ecosystem modules offer useful and complete documentation? Do Perl 6 users know where to ask for help? Can they easily access those channels, even if they don't have experience with things like, say, IRC? Is it easy for them to find out about and attend Perl 6 conferences and workshops?

Reporting Problems

If a user has any issues with Perl 6 or its compilers or modules, or even something else, how easy is it for them to report those problems? Will they get notified when the reported problems get resolved?

This is an area where The Perl 6 User Experience Repository itself falls under and can itself have issues to be addressed.

Contributing to Perl 6

Should a user wish to give back to the Perl 6 community, how easy is it for them to find out what needs to be done and to contribute their work? Is it easy for them to get commit bits, if their work is of stellar quality? Do contributors get proper recognition?

Interacting with the Community

A strong community doesn't just talk code all the time. They chat about other things and go out for a drink. Is that available in a Perl 6 community?

Are there any community participation barriers—whether deliberate or accidental—for persons of a particular gender, sexual orientation, race, age, creed, nationality, or physical, mental, or technical abilities?

Is there a Standard of Conduct that sets the bar for the expected way the members of the Perl 6 Community treat others? Is there a particular person one can safely contact in private, when that Standard of Conduct is violated, or when other members of the community are being abusive?

Being a Perl 6 Programmer

The last section completes the circle the first section started. A Perl 6 Programmer exists in a larger world and tells that world about Perl 6; whether it is by working at a job that involves Perl 6, by interacting with communities of other languages, or by simply spreading the word about Perl 6 on blogs, social media, and conferences.

Are there resources allowing to post or search for Perl 6 job offerings? Are there any issues with other communities? Do Perl 6 markerting materials—like printable brochures or a well-written "sales pitch"—exist and is it easy to obtain them? Is there Perl 6-styled merchandize, like mugs, pens, or shirts, one could either get to keep for themselves or to hand out at some event? Are there places someone can blog about Perl 6, if they don't have a blog space of their own?

The Frustrated Reporter

The nature of what this repository wishes to address begs an obvious question: won't we end up with a whole bunch of low-quality Issues created by frustrated users banging on their keyboards while foaming at the mouth?

Well, we probably will. If I spent "three f#$(!ng hours" trying to install a Perl 6 compiler just to get "this stupid script" to run, I'll be quite angry, I'll use colourful terms in the Issue I create, and I'll likely blame the creators of whatever I tried to use for my frustration. Those responding to such Issues must be aware of where The Frustrated Reporter is coming from. Something made that user this aggravated and it's possible that something can be improved.

"So little time, so many things undone..."

The Perl 6 User Experience covers a lot of things. Big things. Huge things! I suspect most Issues won't be closed with a simple and quick one-line fix. Some will require an extra army of Volunteers. This is what this blog post—and, indeed, the repository itself—is all about: inviting people to pitch in. Not only to report the issues, but to attempt to resolve them, and... to become a part of The Perl 6 User Experience itself.

Why in The World Would Anyone Use Perl 6?

I mean, can you get it any more WRONG?! The juvenile logo and awful color scheme of the website. The Christmas release that isn't all release-like. Version 6.c? Why not 6.0? What's with the whole "language" and "compiler" distinctions no one cares about? Why is the first stable release of the compiler not optimized to the max? And why is it called "Perl" in the first place? They should rename it!!

Too little, too late. Is there a need for a new Perl? No, of course not. What is it good for? Nothing. What is its business case? None! What's Perl 6's "Killer App"? Non-existent. Why in the world would anyone use Perl 6?!

In the three short months since I joined the Perl 6 community, those are some of the criticisms and attacks I had to endure—and sometimes respond to—on blogs, HackerNews, IRC, and Twitter.... I don't mind it at all, since there's little substance in those attacks. At the end of the day, I'm just writing my Perl 6 code. Enjoying it a lot, too.

Am I not meant to?

Must I look for logos tailored to the 50-something CIOs and not logos aiming to discourage misogyny in the community, before I even try the language? Must I demand the first stable release of something to perform better than other things that had a couple of decades of optimization? Must I demand from volunteers they spend the Holidays making a picture-perfect release instead of enjoying rest with their families? Must I hold every open-source tool I use to such standards? A solid, clear business case or GTFO?

cowsay.png

English isn't my native language. That language is something else and I can barely speak it now. Don't have much use for it. In fact, I dislike it. It's nothing major—some of the most famous literature in the world is written in that language, after all—but... well... it's the little things.

Maybe it's having too many letters or weird letters that aren't usually present on a keyboard. Maybe there are too many rules and too many special cases for them too! Maybe... Ugh, the language is just ugly, you know? I want results and not a language.

Of course, the same applies to programming languages too. It's the little things. Like having to write foo(1, 2, 3) instead of foo 1, 2, 3; or writing some_var instead of some-var; importing a lot of functionality instead of having it available from the get-go; perhaps writing if 5 < x and x < 100 instead of the much clearer if 5 < $x < 100; or how about checking a set contains only valid elements? In Perl 6, it's just a set operator away: if @given ⊆ @valid; or use subsets and junctions! I want results and not a language.

Omited parentheses and fancy operators are little things, I know. But they add up. Some programs that I converted to Perl 6 are nearly half the original size. In a 100,000-line program, that's 50,000 lines you don't have to write, and, especially, read later.

And it's things like these that make me enjoy programming in Perl 6. It's this that makes me feel—once again—the wonder I experienced 16 years ago, when I wrote my first program: writing something simple and getting the result, as if by magic. It's hackers like me who will nurture Perl 6 and help her grow. The trailblazers. The unabashed. We stare in the face of critique without flinching. We use the tools with value, not ones with solely a marketing campaign. We'll build the ecosystem and the killer apps. And should you decide to give our tool a spin and should you like it, we'll welcome you with open arms.

Why in the world would anyone use Perl 6? Well... it's the little things.

  1 2 3 4 5 6 7

About Zoffix Znet

user-pic I blog about Perl.