Raku vs. Perl
p6steve.wordpress.com
p6steve.wordpress.com
This is an excellent point, and one that not enough programmers pay attention to (well, outside of the APL family of languages, anyway!)
(Aside from the attraction in small and simple code, each screen in forth is traditionally allocated a designated spot on the hard-drive so it's partially also for space and HDD usage efficiency too)
}
} // not
} // a single
} // fucking else
// implicit else
// return nullptr
return result;
}
A deeply-indented scope should mean "shit is complicated, think deeply about it," not "there were five times I tried something and elected to punt and return null if it failed." The LLVM style guide has the right idea; if you're gonna punt, early-return.As a side-note, I really wish the C++ community would take a page out of Lisp's book and stop giving closing braces their own lines. But that'll never happen.
Oh for the love of God, please don't! That would make things even more unreadable.
Also, the closing braces are often accompanied by error handling and cleaning up code.
You might like the golang approach better, which is really the Linux kernel approach when I think about it....
int double(int x){
return x * 2;}
instead of like this: int double(int x) {
return x * 2;
}
In Lisp, you would write that like this: (defun double (x)
(* 2 x))
and not this: (defun double (x)
(* 2 x)
)
You can read either with syntax highlighting and the appropriate indentation, but it's much harder to get away with putting the closing brace on the same line in C-like languages because of how few people use something like Smartparens or Paredit and how having multiple kinds of brackets (parens, square brackets, curly braces, and angle brackets) introduces ambiguity.When you said that putting the closing bracket on the same line wouldn't work because of the "lack of Paredit-style editor support" for C-like languages, I thought you meant that the Paredit-style plugins wouldn't work well with/support C-like languages. That struck me as odd, because I use Smartparens when writing Rust, and it works just as well as it does when I write a lisp/scheme. In particular, it handles parens, square brackets, curly braces, and angle brackets just fine (and it even distinguishes between a single quote that's used to start a character literal (which should be paired) and a single quote that indicates a lifetime label (which should not))[0]. I could easily use it to write Rust with closing braces on the same line; the only reason I don't is because it's not the common style in that community.
Based on your last comment, I now understand that you're not saying Paredit-style plugins don't _work_ with C-like languages. You're saying that most programmers who write in those languages don't use those plugins. Is that right? If so, I agree that they aren't widely used and that it'd be hard for anyone to use the formatting style above without adopting a plugin.
[0]: The only thing Smartparens fails to handle is that it does not recognize that a pipe character is a pair when delimiting the arguments for a closure. I'm sure I could fix either Smartparens or rust-mode to fix that issue but so far I haven't been annoyed enough to bother.
[Edited to add a missing close-paren, fittingly enough.]
With Paredit, there are key chords for moving up, down, and sideways (forwards and backwards) on the tree of Sexps, for transposing two sibling Sexps, for grabbing a sibling (before or after) of a Sexp and making it a child ("slurping"), for taking a child of Sexp and making at a sibling ("barfing").
I have not found a reliable way to slurp statements into the scope of an if statement (Paredit kind of works but tends to misplace semicolons and various other things).
The opening curly brace is better like this:
int double(int x)
{ x += 3;
return x * 2; }
I found it's good to have spaces within the braces, including when closing them: int double(int x, int b)
{ if (b)
{ x += 3;
return x * 2; }
else
{ x -= 3;
return x * 4; } }
This naturally jives with a two space indentation, so everything is pleasingly copacetic. I feel I could easiy maintain a 200KLOC code base in this style.Oh, incidentallly, this style is followed in the production rule action bodies of the TXR yacc file parser.y:
http://www.kylheku.com/cgit/txr/tree/parser.y
I wonder how well GCC's newer "misleading indentation warnings" handle this, though.
> C-like languages because of how few people use something like Smartparens or Paredit
However, everyone in C (or C-like) programming with two brain-cells to rub together uses at least auto-indention and brace/bracket/paren matching features in their editor. A stock installation of Vim turns some of it on by default if you open anything with a given suffix like .c or .js.
These editing features work equally well regardless of how you lay out the braces.
More generally, you can specify KEEP and UNDO phasers in a block, that will fire whether the block is left successfully or not. So a typical usage would be `UNDO $dbh.rollback`.
(all I can think of is something where you could handle it with a finally-type clause)
maybe a fn shouldn't have post conditions?
Or are you saying that there are some lines of code at the end checking the post conditions? I'm not exactly sure what that would look like, it sounds a bit insane, especially if you do it for every function. Could you give an example?
Raku has a zero cost way to add arbitrary post processing that kicks in no matter where or how a block of code exits.
This provides a general mechanism accessible by arbitrary user defined control flow related constructs.
Raku also ships with a dozen or so built in constructs such as PRE and POST blocks that are the foundational elements for DbC, plus UNDO and KEEP blocks for transactional semantics, and so on.
Before:
if (a.works()) {
// some code
if (b.works()) {
// more code
}
}
After: if (!a.works()) {
// error handling code, if necessary
return;
}
// some code
if (!b.works()) {
// error handling code, if necessary
return;
}
// more code> if you're gonna punt, early-return
Bail early and you wont have spaghetti code, plus you wont even allocate things to memory you're not even going to use, cause you're going to bail.
I don't know what it is but I once interviewed for an embedded C position. During the interview, I wrote out some code samples. The only issue the interviewer found was that I had "returned early". He said there could basically only be one return in a function and it had to be at the end. I told him I'd never heard of that. He only said it was a "standard" that had to be followed because of the crypo involved in the code base.
Sadly, even though I didn't get the job, that stupid statement of only one return call in a function has stuck with me and lead to many mental arguments.
There are two main advantages:
- it's obvious when the function ends, no hidden early exits in the middle of nowhere
- if you need to do something before returning, there is only one place to do it (e.g. trim the output, e.g. log performances), and it make it easier to move this kind of last mile logic to a different function (if it's of any interest)
About your interview, don't sweat it, is not for that you didn't pass (you could do a great job and yet lose to a more fit candidate)
I haven't seen many developers do this: get a computer screen that can stand in the portrait position.
My setup currently is: laptop monitor + 27" screen in portrait. I never have the trouble of scrolling back up and down again when it comes to reading code.
This is also why I'm not as enthusiastic about CPAN as I could be. It's great that the modules are available for when you want to write real applications, but that's not what I do with Perl and one-off scripts really don't seem like it's worth pulling in external dependencies for.
Like an ELI5 for someone not into neither Perl or Raku and haven’t met the units library before.
weight = unit("10 kg")
speed = unit("2.5 furlong per week") Unit(float, unit_as_string)
The free text version is pretty cool thoughFor example,
import week, custom, si, type from stdlib.units
weight = 10 * si.kg
speed = 2.5 * (custom("furlong", type.LENGTH) / week)Mainly because you can add things to the existing parser instead. (See postfix and infix below.)
role Physics::Datum {
has Real $.value is required;
}
role Physics::Distance {
also does Physics::Datum;
}
role Physics::Volume {
also does Physics::Datum;
}
class Physics::Volume::Gallon {
also does Physics::Volume;
}
class Physics::Distance::Mile {
also does Physics::Distance;
}
role Physics::Per[ ::N-Type, ::D-Type ] {
has N-Type $.nu is required;
has D-Type $.de is required;
# could have a submethod TWEAK to reduce the fraction
}
constant gallon = Physics::Volume::Gallon.new( value => 1 );
sub postfix:<miles> ( Real $value ){
Physics::Distance::Meter.new( :$value )
}
sub infix:<per> ( ::NT Physics::Datum $nu, ::DT Physics::Datum $de ){
Physics::Per[NT,DT].new( :$nu, :$de )
}
my $mpg = 5miles per gallon;
Which would result in the following data structure. Physics::Per[ Physics::Distance::Mile, Physics::Volume::Gallon ].new(
nu => Physics::Distance::Mile.new( value => 5 ),
de => Physics::Volume::Gallon.new( value => 1 ),
)
I think the main reason it was written that way was it was copied from Perl.
A lot of the above would be more difficult or slower in Perl.(This was mostly a quick throwaway example of how it could be done.)
http://blogs.perl.org/users/ovid/2019/08/is-perl-6-being-ren...
http://blogs.perl.org/users/ovid/2019/10/larry-has-approved-...
I think that would only add to the confusion, since Perl 6 was already a thing, albeit totally different from Perl 5
The current numbering scheme uses odd minor version numbers for development versions and even for stable, just like Linux used to, until Linus got fed up with 2.6 after 8 years. Now it gets a bump whenever the minor version sticks too much.
“A foolish consistency is the hobgoblin of little minds.” — Ralph Waldo Emerson
PHP 6 was thrown away never to be seen from again, because it was seen as bad.
Perl 6 was renamed because both Perl 5 and Perl 6 are significantly different active languages.
If Perl went to 7 it could indicate to some that 6 was bad in the same way. That is it would trade one confusion for another.
---
If Perl truly wants to go beyond 5, it should make a major step.
Either by going to the subversion (32), or the year (2020).
Raku has some pretty amazing things going for it though. It is unique compared to any programming language with its grammars and such.
So both of these lines would be equivalent.
use v5.32;
use Perl v2020;What made the author write this in the first place? He could use one of the many many parsing libraries, and then at least the comparison with Raku grammars would be honest and fair.
The dependency could break compatibility or add a bug a year from now.
That's what https://metacpan.org/pod/Regexp::Grammars is for, indeed.
EDIT: Oh, that's in the Perl (5) code. Nevermind then.
In C-like it kind of makes sense – it's 1 character shorter, and on some ancient crappy compilers it may actually run faster than while(1) since it doesn't have to check the condition every time ;)
Try reading some of this: https://github.com/Raku/problem-solving/issues/81
In the end it felt better to stop wasting all those emocycles and suggest a rename.
Edit* I make no criticism of the language, simply the argument that a different language should have been named as the incremental release of another.
They both got 0% on rotten tomatoes, but I don’t think Police Academy 6 tried to switch genres.
Also, note what chromatic has to say:
https://perlmonks.com/?node_id=1220578
https://perlmonks.com/?node_id=11105180
And so on.
You appear to forget that the "Perl 6" initiative originally came from the Perl 5 Porters. It did not just come along and called itself "Perl 6": the "Perl 6" name was used because originally it was intended as the successor of Perl 5.
That it didn't materialize in time, that it became something much different, is something that happened later. But even with Pugs around 2005, Perl 6 was still the successor to Perl 5. Only around 2010, when the sister language concept was introduced, was Perl 6 considered to be a different language.
Bullying Isn't Effective Advocacy: https://perlmonks.com/?node_id=1221390
Also, when it was known Perl 6 was going to be a different language, they were several year away from a release
What is in question was it worth making the already extremely messy name situation even more confusing?
Raku, Rakudo, Rakudo Star, it's like they went out of their way to make it confusing. Which, given the Perl culture of whimsy, isn't unlikely.
Working in the perl sphere, I assure you clients do not know this. Also http://blogs.perl.org/users/ovid/2019/08/is-perl-6-being-ren...
Not at all.
Haskell, GHC, hackage/cabal/whatever -- intentionally confusing? No, they are different things.
Same in the Raku case: Raku is the language, Rakudo a compiler, and Rakudo Star a distribution (with compiler, docs, module installer etc.)
Giving three different things the same name would be much more confusing.
No different than "Perl 6" being a different thing from "Perl 5".
Those are all completely different words though... that's my point - that's the sensible way to do it.
> Raku is the language, Rakudo a compiler, and Rakudo Star a distribution
These all start with Raku. Can you understand how they'd be easy to mix up, rather than using different words like in the previous example?
> Giving three different things the same name would be much more confusing.
You've got the wrong end of the stick. I think they should have different names. I think at the moment their names are too similar.
Raku is the language.
Rakudo = Raku “Do”
Rakudo Star = Rakudo* (i.e rakudo, rakudo-devel, rakudo-doc,…)
It has more linguistic cohesion that the tooling of a lot of languages.
Java, javac, java* seems totally normal. I feel like it’s because “Raku” sounds alien and so you don’t read Raku-do you read Rakudo because Raku “isn’t a word”.
But that's the problem! I don't want clever, witty, whimsical. I want clear, simple, precise.
This is what went seriously wrong with Perl. In the 90s when Perl was doing well it was fashionable to be wacky like this. Then around 2000 the fashion suddenly changed and the industry grew up and people started to take things more seriously. Now Perl looks terribly out of date and silly.
Really?
Goofy codenames for projects (Bionic Beaver, etc), the sign of a 'serious' project is having a cartoon mascot, 'open source' people relying on closed/proprietary things like slack, macOS, etc. instead of open/libre alternatives, 1 page github READMEs and API docs as 'documentation' but having a youtube channel full of 'howto' videos instead
there is probably an equal amount of goofyness/immaturity and seriousness then as now - it just manifests differently
The programming language industry, yes. There was a marked shift towards simplicity away from silly whimsy. The extreme example is Go.
Personally, I'm happy that we live in a time where we have many different languages featuring meny different paradigms; I find it refreshing and stimulating.
I'm not in charge of what language the Perl projects choose to use.
> Personally, I'm happy that we live in a time where we have many different languages featuring meny different paradigms
You're not arguing against what anyone in this thread said.
“Raku” is the anglicized form of “楽”, which means “easy”. (It is also a form of pottery.)
“Rakuda do” is supposed to be “way of the camel”.
“Rakudo” is “Rakuda do” but shortened/portmanteau.
“Rakudo” is also supposed to mean “paradise”.
---
I want to know how “easy” and “paradise” are not considered different words.
And “Rakudo Star” is the “Rakudo” compiler combined with a bunch of useful modules. So it makes a lot of sense for it to contain “Rakudo”, because it does indeed include “Rakudo”.
---
It also makes a certain amount of sense that “Rakudo” is a thing which you use to “do” "Raku".
Everyone who have been following the evolution of the language the last decade. But most people have not, and new people are born every day. So the name change will avoid confusion going forward and make it easier for both the Perl 5 and Raku communities.
Now after the rename, I guess every HN discussion will have a subthread discussing how the rename was terrible, and it should've stayed Perl 6.
There's just no pleasing the Internet crowd.
This can also come up in political contexts when some of your adversaries say something, but you don’t track which of them said it, and instead assign the opinion to [democrats, republicans, libertarians] as a whole. Next thing you know you think they’re all dirty hypocrites arguing in bad faith, and it takes an effort to see otherwise.
I don't see any evidence for this claim. Besides those on the inside, I have yet to see any support for naming a different language as logical next version of another.