180 points · by vezzy-fnord · 11y ago · 122 comments
It's a new language with its own internal logic.
I used (and still use) Perl 5 because it made some specific things easy to make (various processing of data). I still don't know for which kind of tasks Perl 6 is the best choice. But maybe the language is simply too young for it to be obvious?
Perl6 is at least as good as Perl5 for everything Perl5 is good at.
But Perl6 is way, way more than that.
No. It is not. Don't believe me? Here is a short list of classic selling points for Perl 5 that Perl 6 clearly loses on.
1. Performance. Back in the 1990s, Perl hit a sweet spot of being quick for development while still being fast enough for a wide variety of tasks. It still performs reasonably well versus other scripting language. Every time I looked at Perl 6 it failed to be fast enough for anything interesting to me.
2. Library support. Any argument for Perl quickly lists CPAN. It is a large part of why people adopted it in the first place. Perl 6 loses to every major language, including Perl 5, on this. If you need to do anything from connect to a database to sending email, Perl 6 loses.
3. Backwards compatibility. Perl has a history of being careful with backwards compatibility, starting with Perl 1's unit test suite back in the mid-80s. (It would be decades until other language communities caught up.) Most organizations currently using Perl 5 use it because they already have existing code in Perl 5. Their primary motivation for staying on Perl is that they don't want to rewrite their code. Perl 6 requires a rewrite of their code.
2. With Inline::Perl5[1] this should be a non-issue. The short code snippet in the README at the github repo referenced should give you the idea.
3. Having not been released yet, Perl 6 has zero history on backwards compatibility, so there's no way to assess whether it's relatively better or worse than Perl 5.
That said, I don't necessarily support the original statement that Perl 6 is a superset and at least as good as Perl 5 at everything. I just wanted to address your specific statement regarding library support.
Yeah, performance sucks for Perl 6. Simple reason - first make it work, then make it fast. It's just been announced like yesterday that there's gonna be beta releases before the first stable release.
My money is performance will get better between now and Perl 6, v1.
How? And can you cite any sources that I can read? Thanks.
I don't have time to find supporting sources right now, but I'll just say a couple of things, regarding Perl6 and string manipulation.
Less concretely, Perl6 is still Perl. What does 'Perl' mean? "manipulexity and whipuptitude" :) To me, those things are about being highly pragmatic in as many real-life situations as possible.
More concretely, even though Perl6 has an amazing type system, it's almost all optional. Use it incrementally, as it becomes more useful.
Also, the tight and powerful integration between language and regex still exists.
So, again, regarding string processing, these elements, to me, show that Perl6 is a 'strict supserset' of Perl5.
And, without any citations, I feel like that 'strict superset' is mostly true for things other than string processing!
It's been a number of years, and I can't check right now, but I believe that the amount of code in Perl6 is actually less than in Perl5. The amazing power that is Perl6 naturally falls out of a whole lot of experience and fantastic design decisions. Not to mention several great implementations.
I'm a big fan of 'less is more' as well. In this case, you're literally correct: Perl6 delivers a LOT MORE than Perl5 even though there's 'less to it'!
Was: $str =~ m/^\d{2,5}\s/i
Now: $str ~~ m:P5:i/^\d{2,5}\s/ # :P5 indicates Perl5-compatibile regex syntax
Was: $str =~ s/(a)/$1/e;
Now: $str ~~ s:P5/(a)/{$0}/; # $1 is now $0
I actually find the change from $1 to $0 particularly disturbing, since that is well standardized and group 0 normally refers to the whole matched pattern (though Perl had to give it a different name and for some reason has always discouraged its use).They also provide no information here on the non-"Perl5-compatible" regexes, but they do talk about it a bit in Specification 5: http://design.perl6.org/S05.html There are some really interesting changes there, and we'll see what comes of this -- PCRE has become a de-facto standard, so I'm curious to see what happens as Perl moves away from "PCRE-compatible" syntax.
What's that $1? Well it's the first match if it's Perl 5 but it's a second match if it's Perl 6. But don't worry, the other things in expressions also have sometimes other meanings.
Was: my $len = length($string);
Now: my $len = $string.chars;
My intuitive interpretation of that syntax would be "given a string, return a sequence containing its characters, in order".Or is that overlading on return type, and do you get the behavior I would find intuitive if one assigns to an array?
Even if that is true, I find that ugly. I would prefer more explicit code, for example
my $len = $string.chars.#;
Similarly: Was: $#array+1 or scalar(@array)
Now: @array.elems
(All IMHO) # perl6 -e 'my $string = "foo"; say length $string;'
===SORRY!=== Error while compiling -e
Undeclared routine:
length used at line 1. Did you mean 'elems', 'chars', 'graphs', 'codes'?
Perl 6 tries to get unicode right. In doing so, it makes a distinction between characters, elements, codepoints and graphemes. At certain points, you may want one or the other of these.When asking for the length of a string, what are you really asking for? The number of characters? Visible characters, or unicode combining characters? What if it's really the number of bytes in the string you need? Perl 6 makes it easy to determine all of these things in a clear manner. In doing so, it becomes obvious that "length" is ambiguous due to both its common specific role in other languages, and it's meaning when viewed in the context of these different needs.
If you want individual characters, you split the string, if you want access to the underlying data, you call .encode to get the encoding you expect, or you stick it into a Buf or Blob type if you don't actually need string semantics.
(Corrections welcome, I could be wrong at any number of points above).
If I see string.chars I expect to see a bucket of char, and not the count of chars. That name needs to be more explicit.
Perl 6 is not softly typed, it's gradually typed. It's as hard as you want to make it.
> If I see string.chars I expect to see a bucket of char
Why? Is that an expectation that comes from some other language? There's only so much you can expect a language to follow the semantics of other languages. Perl 6 will have it's own quirks, expecting it to conform to some malleable standard based on what some percentage of other languages do is not something I think is entirely fair to expect.
http://doc.perl6.org/type/Str#method_length
EDIT: I don't see any contact section on their page to let them know
http://design.perl6.org/S29.html#Obsolete_Functions
"length()
This word is banned in Perl 6. You must specify units. In practice, this probably means you want Str.chars(), although it could be Str.bytes(), or even something else. See S32-setting-library/String for details."
(Incidentally, does Python 3 have a solution to this problem?)
Perl 6 does not have a length function. See chars or elems.
An array (of characters in your example) in a scalar context is the length of the array. I don't know if that's whats happening here, but that's how you do it everywhere else in Perl so it would make sense to do it on strings too.
(I think there might be some movement towards letting a function detect sink (void) context. Then functions with both side effects and return values don't need to calculate the return values when they aren't needed.)
It makes me wonder if this will be the case for other methods in the language.
Sorta like the old F2C, Fortran to C, converter. You don't get idiomatic C, but you do get a fortran program that compiles and runs as a C program, more or less.
Some parts of perl6 are annoyingly urbit-y, come on, you guys just had to rename ARGV and rename scalar and the for-foreach transition is ridiculous. I suspect at least a decade of people pointing at items and verbally calling them scalars and so on. Urbit is cool but is most famous for feeling the need to rename everything.
Here's a slide stack for going from MOOSE (more or less the most popular "real" perl5 OO implementation, technically an "add on" for perl5 although many people will only program perl5 with MOOSE) to perl6 OO. At least toward the middle there are adjacent slides of "this is how you do it in MOOSE" "this is how you do it in perl6"
http://www.slideshare.net/lichtkind/p6-oo-vs-moose-moo
I'd like to read a book titled something like "Modern Perl; For Perl 6.0"
The transition will be such fun; I have some business logic libraries where I'll have to replicate behavior and test suites simultaneously for awhile in MOOSE/5.0 and in 6.0.
(response to unfortunately hellbanned berntb question about replication, the codebase is huge and interrelated and can't be forklift upgraded all at once; its already non-trivial to do stuff in both perl and scala, and now it would be perl5 perl6 and scala all more or less interoperating)
# perl -E 'foreach (my $i=0; $i<3; $i++) { say $i }'
0
1
2
# perl -E 'for my $i (0..2) { say $i }'
0
1
2
I never use foreach in Perl 5, and that's what I'm paid to write in. This is just a reaffirming that "for" is the preferred syntax (and this isn't a TMTOWTDI thing, this is two reserved words for the exact same code construct thing).Moose, interestingly enough, is based on backporting the then-proposed Perl 6 object system, so a lot of the concept sand terminology will be the same.
But it sounds like you are talking about transitioning from Perl 5 to Perl 6. Why? The naming is confusing, but most people are not expected to convert codebases to Perl 6. It's not an upgrade, it an also. If you want both, use Inline::Perl5[1] and just call back and forth between the interpreters.
Do you have/write test suites? In P5? P6?
Have you seriously tried any of the p5-to-p6 translators with your scripts?
Was the usage message typically much-improved, about-the-same, or needs-work after your first successful compile?
Same question for command line argument binding?
Any speed stories? Scripts that started unacceptably slow but eventually got there? Ones that beat their Perl 5 originals? Ones that didn't really make it yet?
Have you converted any of your Perl 6 conversions back in to Perl 5 code (to retain the clarity developed in the conversion to 6 but regain the speed that Perl 5 has)?
Do any of your conversions use Perl 5 modules?
...with an exceedingly poorly chosen name.
(Which is not to diminish how good it is as a language.)
I personally wouldn't mind if there was a slow shift towards using the current main implementation's name (Rakudo) or some other (NG Perl?) for the language down the line, but I think doing so before release would just make every problem worse, including Perl 5's ("Oh, Perl 6 is no more? It failed? I knew it would... Perl is a dead end.")
You mean it will take time before you trust the "use Perl 5 code in Perl 6" bridge that is worked on, so it isn't enough to run the Perl 5 tests and then use that code in Perl 6?
(Or you think there will be bad interactions with Moose and Perl 6 OO?)
Edit: Huh, I was shortly un-hellbanned and am Hellbanned again since the previous comment didn't live up to some interesting-level standard? :-)
Maybe your comment got rescued by someone using the new vouch feature?
Even with Inline::Perl5 you need to test the implicit 5<->6 casts with the perl6 vm (which might be rakudo or some other engine).
Moose contains only a small subset of the Perl6 OO, and has also different syntax. E.g. in perl6 types lead to optimizations, in Moose to pessimizations. Rewriting in Perl6 is always preferred, as Perl6 is a much nicer language.
Simply put, there will not be any grand push to re-sigil every stored data structure and make massive, sweeping changes to nearly every line to end up with the same program that looks, if anything, arguably less intuitive.
This shows a profound unawareness of how Perl 5 was actually used in practice.
Perl 6 is not an automatic upgrade path from Perl 5. We don't expect anybody to rewrite huge amounts of Perl 5 code in Perl 6. Perl 5 is going to be maintained separately.
We do provide tools to augment Perl 5 code with Perl 6 code, and the other way around. There's Inline::Perl5 for Perl 6, and Inline::Perl6 for Perl 5.
Or, if Perl 5 and Perl 6 really are two completely separate languages separated by a similar syntax, then what comes after Perl 5 in the Perl 5 language? Will it forever be 5.N, 5.N+1, ...? (And, I guess, will there forever be 6.N, 6.N+1, ...?)
What is being discussed is the excitement brewing from the all the work that has transpired via the Modern Perl movement.
We have modern web frameworks (Mojolicious, Dancer, PSGI/Plack); YEARLY releases of Perl 5; CPAN has never been easier to work with (cpanm, cpanfile, carton); a healthy and supportive community; and modern infrastructure to work with OO (e.g. Moose).
There are several of other things I haven't mentioned.
For example, if you want to try a web app with one of the latest perls:
$ curl https://raw.githubusercontent.com/tokuhirom/Perl-Build/master/perl-build | perl - 5.20.3 /opt/perl-5.20
$ curl -L https://cpanmin.us | /opt/perl-5.20/bin/perl - App::cpanminus Mojolicious
$ /opt/perl-5.20/bin/mojo generate lite_app all_the_awesome.pl
$ /opt/perl-5.20/bin/perl all_the_awesome.pl daemon
... Goto a browser and visit http://127.0.0.1:3000The above command assumes you have a system perl that can bootstrap your user perl into /opt/perl-5.20.
Thank you for asking.
I think a good deal of Perl 6 features will seep into Perl 5 over time, while maintaining backwards compatibility.
I presume perl6 will be doing similarly.
The ask for people to use Perl6 is a huge one given it's basically a completely different beast that just resembles Perl5.
Without pointing out where Perl6 excels (in comparison to Python/Ruby not Perl5) this will probably be a non-starter for most people.
(this is from somebody who did his fair share of Perl5 in the old days and would not go back to Perl5 / try Perl6 unless there would be an extremely clear differentiator that would make it worth it.
Perl 6 is for new projects. And if I'm familiar with Perl 5, it makes all the more sense to use it for my new projects. For non Perl programmers it makes a nice new language to learn.
It's the "New Coke" (see https://en.wikipedia.org/wiki/New_Coke) situation all over again. When Coca-Cola rolled out New Coke back in the '80s, lots of people actually preferred the taste of the new formulation to the original, "classic" Coke. But it failed anyway, because it came in a can labeled "Coke" but tasted very different than what people thought the contents of a can labeled "Coke" would taste like. Their brains never made it to the "hey, this tastes better!" part, because they were too busy raging over thinking they were getting one thing when they were actually getting another.
It's been clear for more than a decade now that Perl 6 was going to be a big, discontinuous change instead of an incremental step up from Perl 5, so why they've persisted with calling it "Perl 6" all this time is beyond me. Just call it something other than Perl and 90% of the gripes about it will vanish overnight.
Why can't it be successful based on its own merits?
Go didn't have a clear upgrade path from anywhere. Rust doesn't, nor do Julia and all the other new, hip languages that I just forgot about.
$x = [ [1], [2], [3] ];
Instead of:
@x = ( (1,), (2,), (3,) );
I always found it quite convenient to be honest.
"In exchange for breaking backwards compatibility, at least at the language level, Perl 6 offers plenty of high-powered language concepts that Perl 5 didn't support..."
EDIT: this was completely wrong, see below.
This will give good error messages when trying to run your code with the wrong compiler.
Oh no.
print +"" ; # a num-ified empty string evaluates as 0
print "1" + 1 ; # 2
The opportunity for insidious bugs (for the benefit of not having to type 'int("1") + 1' those times when you really need to do that) is a terrible tradeoff, in my opinion.In before "but Python...!". Python is strongly typed.
>>> "1" + 1
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects
>>> 1 + "1"
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str' "1" + "1" # 2
"1" . "1" # 11 (~ to concatenate in Perl 6)
1 + 1 # 2
1 . 1 # 11
When you perform a string operation on a numeric type, it stringifies the number, when you do a numeric operation on a string, it numerifies the string (and warns if it can't be cleanly done).This isn't a typing problem, this is a commenting on language without actually knowing how it works problem. But that's nothing new, people have been doing that to Perl for a long time now.
Perl: unary + is "convert to number", binary + is "convert operands to numbers and add". This is clear and consistent. String concatenation uses a different operator completely.
Python: binary + is string concatenation if the left operand is a string, and numeric addition if the left operator is a number. It fails at runtime if the right operator is inconsistent with the operation specified by the combination of the operator and the left operand.
print "1" + 1 ; # 2
This isn't new, is it? '+' is for addition, '.' is for concatenation.You're thinking of JavaScript in this particular issue.
P.S. Why not name this language something new? -- Nicklaus Wirth didn't name Modula-2 Pascal 2.
And that was a big marketing mistake. Do you think C++ would have been anywhere near as successful if it had been called Z?