News for hackers. Stuff that matters.
Re:Larry Wall has approved renaming Perl 6 to Raku by Upvoter33 on Friday October 11, 2019 @04:11PM (#21227999)
I'm amazed that Perl is still around. I personally find it the least readable language that I've ever used, and that includes a lot of languages. But some people really seem to love it, for reasons a bit beyond me.
Re:Larry Wall has approved renaming Perl 6 to Raku by pmoriarty on Friday October 11, 2019 @04:44PM (#21228293)
How familiar are you with Perl, and how much have you used it?

Most of the anti-Perl comments I've heard have been from people who really didn't know it very well, if at all.

Some of them might have glanced at some Perl code and saw a dense regex and dismissed it as "line noise". Well, yeah, if you don't know regexes you would be forgiven for thinking it was line noise, but if you did know regexes it should look no more like line noise than a similarly dense regex in any other language.

For a long time now, Perl has allowed regexes to be commented. Commenting dense regexes and splitting them up in to short regexes assigned to judiciously named variables is just good style in any language, and has been the norm in Perl for a long time. Furthermore, modern Perl style guidelines advise code to be written with verbose, English words instead of ancient Perl one-character special variable names.

So setting aside both dense, uncommented regexes and ancient single-letter special variable names, both of which have been recognized as poor style in Perl for decades now, I'm really not sure what the complaints about Perl readability are about. To me it looks really no uglier than any other mainstream language, and one could easily make the argument that any other mainstream language you care to name is uglier in some of its own ways.

If you include non-mainstream languages, some languages which have a lot of fans here on HN are arguably a lot less readable than Perl to someone only familiar with traditional Algol-style languages. In particular, I'm thinking of Forth and Haskell. Yet you rarely hear complaints on here about their readability.

Re:Larry Wall has approved renaming Perl 6 to Raku by j9461701 on Friday October 11, 2019 @05:31PM (#21228686)
>How familiar are you with Perl, and how much have you used it?

It's what my company's entire code base is written in. So every hour of every work day for the past 6 months.

>To me it looks really no uglier than any other mainstream language, and one could easily make the argument that any other mainstream language you care to name is uglier in some of its own ways.

It's no one thing, but a bunch of little things that compound on top of each other. Until you get something like this:

while (<>) { ($h{$_}++ == 1) && push (@outputarray, $_); };

Mostly though it's how it's used. It can technically do anything, so a lot of the times it is asked to do everything. Until one day you wake up to find you have hundreds of perl files, all tens of thousands of lines long, that all interconnect in an insane Object Oriented hierarchy soup stretching across every conceivable programming space - from database control to money processing to security to web site design.

Re:Larry Wall has approved renaming Perl 6 to Raku by skinniks on Friday October 11, 2019 @10:23PM (#21230203)
I've worked on large 20 year old Java and C applications (OLTP and batch processes) and I can assure you that they can be as ugly as any old Perl code you have dealt with.

Saying that I see absolutely nothing wrong with that perl code you are highlighting as being obtuse or ugly. Anyone who understands Perl should not have an issue with that line. It is clear and concise.

Re:Larry Wall has approved renaming Perl 6 to Raku by Grinnz on Saturday October 12, 2019 @12:51AM (#21230767)
Well, the "foo && bar" is a bit of a bashism, idiomatic perl would do "bar if foo" or similar.
Re:Larry Wall has approved renaming Perl 6 to Raku by nocman on Sunday October 13, 2019 @02:31AM (#21238739)
And a C-ism, and a C++-ism, and a Java-ism, and probably at least one other I'm not thinking of at the moment.

There are a variety of things that Perl programmers would consider idiomatic (depending, I would say, on the background of the Perl programmer). Using something like (foo && bar) in this manner is actually quite common in some Perl code bases (although, I suspect it is more commonly used where there are multiple conditions that are chained -- Damian Conway's "Perl Best Practices" book has some examples of those).

In the example given, I suspect the author of that code did it that way to reduce the length and put it on one line. I understand the desire for concise code, but if it were me, I would spread it out more to make it easier to read (mostly, I just wouldn't put it all on one line). I like having concise code also, but there is a fairly definite line that I try not to cross. If I have to work hard at all to keep track of the pieces, it's time to either add some more whitespace (horizontally or vertically, or sometimes both), change some of the constructs, or add some temporary variables to make the intent clear.

I am the person most likely to have to deal with the code a year later, so like many others, I try to not confuse my future self.

Re:Larry Wall has approved renaming Perl 6 to Raku by kbenson on Friday October 11, 2019 @07:41PM (#21229403)
> while (<>) { ($h{$_}++ == 1) && push (@outputarray, $_); };

That's a business culture thing. If you set the expectation, that it's okay to do that, people might do that. If you set the expectation that it's not okay, people shouldn't.

The equivalent C and Python are likely just as ugly (given that the equivalent python might be using a far too complex range statement or put it on a single line using : and ;, which is possible...).

That said, as bad code goes, that's not really that bad. The only non-standard things are <> and $_, and if you don't know what those are, you really haven't done the minimum of learning about the language (<> might be somewhat exotic in that form depending on the codebase, but $_ is not something you can get way with not knowing about). In all, the major problem with it is that it's not commented and uses poor variable names, which is something every language needs to deal with. I would write it like so if I wanted it on a single line (but I would probably use 2-3 lines):

    # Report each duplicated line once
    my (%lineseen,@linedups); # This was required in yours too right? I assume you're using strict...
    while (<>) { (++$lineseen{$_}==2) && push(@linedups, $_); };
But I would likely opt for the following if doing it myself:

    # Report duplicate lines once
    my %lineseen;
    my @linedups = grep { ++$lineseen{$_}==2 } (<>);
Assuming I was using <>, which I generally don't since File::Slurp is usually available and clearer.
Re:Larry Wall has approved renaming Perl 6 to Raku by cutler on Saturday October 12, 2019 @01:20AM (#21230853)
There's always <STDIN> if <> is too cryptic. I think what most fail to grok, if they've only glanced at Perl, is context. Above all Perl is a context-based language. It's the opposite of Python's spell-everything-out approach but just as valid. Perl also excels at whipupitude.
Re:Larry Wall has approved renaming Perl 6 to Raku by kbenson on Saturday October 12, 2019 @01:36AM (#21230907)
Except that <> isn't just <STDIN>, it reads from each line of each file specified as an argument on the command line or STDIN if no files were specified. This dual use (and magical-ness) is why I shy away from it in actual programs (but it is useful for one liners, which is why it does this), as it can be confusing.

Some people will look at this as evidence that Perl should be relegated to one-liners, but I find immense usefulness in combining my more engineered aspects with one-liners, and providing myself with a "project evaluator". What I do is create a simple bash script which just calls perl and sets the library include path to the project lib, includes a few useful things to always have (Path::Tiny, Try::Tiny, Data::Dumper, etc), and passed the rest of the args to Perl. Using DBIx::Class for SQL manipulation and/or using complex API client libraries I've written combined with the abilities of perl to do things easily as a one-liner is amazing.

Re:Larry Wall has approved renaming Perl 6 to Raku by Grinnz on Saturday October 12, 2019 @09:43PM (#21237707)
<> is actually <ARGV>. And actually the least cryptic spelling IMO is "readline(*ARGV)" or just bare readline, which still compiles to the same opcodes. Sure, <> is more common, but it's easier to find what readline and ARGV mean.
Re:Larry Wall has approved renaming Perl 6 to Raku by mst on Saturday October 12, 2019 @10:27AM (#21233373)
File::Slurp is broken AF though, and obsoleted by File::Slurper since the original can't be fixed without breaking accidentally working code in the wild.

Still mostly fine so long as you know you're only dealing with 7-bit ASCII, IIRC, but Caveat Emptor.

Re:Larry Wall has approved renaming Perl 6 to Raku by kbenson on Saturday October 12, 2019 @02:12PM (#21235036)
Ah, well I actually use Path::Tony's slurp functionality mostly, depending on if it's already available in the project (which it is in any I set up).

It's easier to just say File::Slurp in mixed company so people immediately know what it is if they look it up, rather than them be confronted with a grab-bag of functions.

Re:Larry Wall has approved renaming Perl 6 to Raku by Grinnz on Saturday October 12, 2019 @09:41PM (#21237705)
File::Slurper is just as immediately obvious, and happens to not be fundamentally misdesigned :) Path::Tiny is also great.
Re:Larry Wall has approved renaming Perl 6 to Raku by wumpus on Friday October 11, 2019 @05:57PM (#21228864)
Huh, I worked at a company that wrote 1.5 million lines of perl together, and we never ended up with those problems. Maybe you picked the wrong co-workers? You can screw up in any language.
Re:Larry Wall has approved renaming Perl 6 to Raku by hpcjoe on Friday October 11, 2019 @10:02PM (#21230097)
Yeah ... most of my 2-company-ago's software stack was written in Perl. Worked very well.

The specific example cited

while(<>){ $h{$_}++ && ... }

is quite understandable to anyone who has used Perl for more than a few weeks. Its a common pattern. Complaining about this, which is, for the uninitiated, looping over reading each line from STDIN until EOF, incrementing a hash variable indexed by each line, etc.

This is a very common pattern in perl. Draw your own conclusion as to whether complaining about idiomatic language from a "skilled practitioner" is something one should take without a grain or two of salt.

And of course, being Perl, there are many ... many ... ways to accomplish the same task. Leveraging CPAN modules. I'd leave discovering some of the as an exercise for the reader.

Re:Larry Wall has approved renaming Perl 6 to Raku by weare138 on Friday October 11, 2019 @06:05PM (#21228924)
I have a decent amount of experience with Perl 5 and one of Perl's greatest features is also sometimes it's greatest liability, versatility. It's permissiveness tends to facilitate poor coding styles and methods which is why there's alot of bad Perl out there. Plus Perl 5 is just different for lack of a better term. If your proficient newer languages, Perl 5 and the Perl way of doing things probably seems a little strange.
Re:Larry Wall has approved renaming Perl 6 to Raku by jrumbut on Friday October 11, 2019 @10:04PM (#21230113)
It's different from the newer languages, it's different from the older languages, it's it's own thing. I find it really beautiful for that reason.

Who knew you could do that in a programming language? Not sure I would have ever thought to try.

I even love the above sample while loop, you can tell the person who posted it is good because they can't create too heinous an example. The <> and $_ provide what I think of as visual anchors that describe a path for the data to follow. Obviously some style minded author could do it better, but it's not bad. The real line noise is from the one-liners for systems tasks I think.

Re:Larry Wall has approved renaming Perl 6 to Raku by weare138 on Friday October 11, 2019 @10:35PM (#21230255)
I totally agree, I didn't mean what I said in a negative way at all. That's how I got into Perl. What made it cool to me was just how different it was. It's experimental, esoteric and functional all at the same time depending on how you use it.
Re:Larry Wall has approved renaming Perl 6 to Raku by lenkite on Saturday October 12, 2019 @02:55AM (#21231144)
Seriously...? I last worked with Perl in college (more than a decade ago) and thats perfectly understandable to me. There is nothing un-readable about that code as long as you understand Perl conventions. The more important part regarding code quality was whether that piece of code was encapsulated into an independent function or a snippet of a wall of text.

You should see C++ Templates! Even the idiomatic examples in cppreference.com will blow up your head and require multiple re-reads.

Re:Larry Wall has approved renaming Perl 6 to Raku by b2gills on Wednesday October 16, 2019 @03:08AM (#21267836)
Note that:

    while (<>) { ($h{$_}++ == 1) && push (@outputarray, $_); };
Would be written as the following in Raku:

    my @output-array = lines.unique;
Re:Larry Wall has approved renaming Perl 6 to Raku by lizmat on Monday October 21, 2019 @09:28AM (#21311986)
Actually, since the Perl 5 example doesn't chomp (remove newlines), the Raku version would need to be:

    my @output-array = lines(:!chomp).unique;
where the `:!chomp` is a named parameter representing a `False` value for the named parameter `chomp`. AKA, `chomp => False`.
Re:Larry Wall has approved renaming Perl 6 to Raku by tangental on Friday October 11, 2019 @08:37PM (#21229668)
> while (<>) { ($h{$_}++ == 1) && push (@outputarray, $_); };

We use Perl::Critic [0] to deal with issues like that. It has enabled us to develop a very consistent style, and helps new devs adopt to it quite quickly.

[0] https://metacpan.org/pod/Perl::Critic

Re:Larry Wall has approved renaming Perl 6 to Raku by commandersaki on Saturday October 12, 2019 @12:38AM (#21230719)
'x' is an operator...
Re:Larry Wall has approved renaming Perl 6 to Raku by lilSebastian on Friday October 11, 2019 @04:56PM (#21228383)
> Most of the anti-Perl comments I've heard have been from people who really didn't know it very well, if at all.

Indeed, I hope this thread gets picked up by http://n-gate.com/

Re:Larry Wall has approved renaming Perl 6 to Raku by AlexCoventry on Friday October 11, 2019 @10:12PM (#21230148)
You are violating the prime directive.

http://n-gate.com/hackernews/2017/08/22/0/

Re:Larry Wall has approved renaming Perl 6 to Raku by Shoop on Friday October 11, 2019 @04:34PM (#21228201)
Even if you never want to write any Perl code, I definitely recommend checking out some of the features of Raku. As someone who is interested in language design but never has (or likely will) use Perl for a project, I still found reading about Raku's feature set super interesting. Here's a whimsical slide deck that introduces a lot of the most interesting features: [0]. Even if you find yourself shaking your head at all the craziness, you at least have to admire Raku's success at fulfilling its goals of being a post-modern language optimized for fun (-Ofun).

[0] http://tpm2016.zoffix.com/#/

Re:Larry Wall has approved renaming Perl 6 to Raku by cutler on Saturday October 12, 2019 @01:05AM (#21230806)
I love Perl - the syntax, community, Larry Wall's writings and The Monastery. Occupationally I'm forced to write Ruby for a living these days but Perl's influence is there and enhances my appreciation or Ruby. I came into programming after reading in the Dreaweaver Bible that you could extend the search facility with regular expressions. Jeffrey Friedl's monumental Mastering Regular Expressions was listed for further reference and I was hooked. Perl was the natural language to learn if you were inspired by regexen and wanted to create dynamic websites back in the early 2000s so I sought-out Larry Wall's Programming Perl. That book is such a joy to read. I still dip into it today just for the quality of the writing ... and a little nostalgia.

Take time to really grok Perl and you may find the soundbite swipes at Perl don't make sense any longer.

Re:Larry Wall has approved renaming Perl 6 to Raku by eruci on Friday October 11, 2019 @05:34PM (#21228709)
Just because you can't read it, is not a good reason to hate it. But, as Larry says, "It is better to be hated by those who don't know you, than by those who do"
Re:Larry Wall has approved renaming Perl 6 to Raku by theonemind on Friday October 11, 2019 @04:17PM (#21228059)
I find programming perl fun inversely to program size and proportionally to the need to slice and dice text. I didn't learn perl until the perl 5 era, but from what I can tell, I would've been as satisfied with perl 4, before they bolted on OO and tried to expand the applicable problem domain of the language. I mostly just use it as a super-charged awk and bash replacement for scripting.
Re:Larry Wall has approved renaming Perl 6 to Raku by tyingq on Friday October 11, 2019 @04:57PM (#21228399)
The bolted on OO is really just one new function...bless(). The rest is package namespaces, which are also used for non OO purposes.

I'm never sure what people don't like about OO Perl. There's a tiny bit of boilerplate in a constructor, other than that, it doesn't seem different from other OO script languages.

Re:Larry Wall has approved renaming Perl 6 to Raku by hnick on Friday October 11, 2019 @07:33PM (#21229359)
It's not terrible to get working, but for many people a major point of OO is encapsulation and it doesn't work out of the box like that. You have to install another package or use the inside-out object model to prevent direct access to package variables and 'private' functions are usually by naming convention only.

It's just another example of Perl's biggest strength and weakness. Total freedom to build something amazing or shoot yourself in the foot.

Re:Larry Wall has approved renaming Perl 6 to Raku by jlokier on Friday October 11, 2019 @09:16PM (#21229863)
Python and Perl have almost exactly the same OO model, yet many people quite like Python's OO, so that can't be it surely...

There's no private data or private methods in Python objects. All the properties are right there for anyone to read, protected only by convention.

JavaScript and Perl have almost exactly the same OO model, yet many people quite like JavaScript's OO, so that can't be it, surely...

There's no private data or private methods in JavaScript objects. All the properties are right there for anyone to read, protected only by convention.

(It's closer than it looks. Perl's "bless" function means almost the same as JavaScript's ".__proto__ =", and inside-out data hiding is possible in JavaScript much the same as Perl, although hardly anyone uses it in either language.)

Re:Larry Wall has approved renaming Perl 6 to Raku by hnick on Friday October 11, 2019 @09:56PM (#21230067)
I'm not necessarily a fan of the OO in those either :)

I try to use OO sparingly when possible, and in Perl that generally just means I've been using a hash and decide it'd be more convenient that it keep some functions to itself rather than pass it around to other functions.

I will say in Perl's defense, the bare implementation really made me appreciate what OO actually is under the hood. I felt like I understood it much better, especially since it takes a mixed approach (rather than 'everything must be an object, including Program.cs' which I never really enjoyed).

Re:Larry Wall has approved renaming Perl 6 to Raku by Grinnz on Saturday October 12, 2019 @12:57AM (#21230775)
It does make it very clear that it is just a data structure (state) associated with a class (behavior).
Re:Larry Wall has approved renaming Perl 6 to Raku by tyingq on Saturday October 12, 2019 @10:32AM (#21233422)
It's also pretty neat that you can bless any type as an object. People use the hash most often for obvious reasons, but you can use a scalar/string, array, etc, if you wish.
Re:Larry Wall has approved renaming Perl 6 to Raku by tyingq on Saturday October 12, 2019 @12:04AM (#21230590)
That's fair, though as mentioned, not much different from other scripting languages with OO. The _private convention seems to work ok in practice, if not in theory.
Re:Larry Wall has approved renaming Perl 6 to Raku by kbenson on Friday October 11, 2019 @05:42PM (#21228766)
Agreed. Not to mention, from what I understand they just borrowed the OO system from Python, so it shouldn't be that foreign to most people.
Re:Larry Wall has approved renaming Perl 6 to Raku by GuB-42 on Sunday October 13, 2019 @11:27AM (#21240886)
I also find it one of the least readable language. Or more precisely, the language that requires the most effort to be made readable. Every language can be made unreadable.

But it is also one of the most writable language. In Perl, for most problems, there is a quick and dirty way of addressing it. It is especially true when it comes to processing text files, the thing that Perl is best known for.

Many languages try to be clean and consistent, it is obviously good for readability, but it means that choices have to be made. Sometimes the best way is the "wrong" way and you have to fight against the language. Perl solved that problem by not having a "wrong" way of doing things, screw cleanliness and consistency.

Also, first class regex are awesome for quick and dirty text processing.

Re:Larry Wall has approved renaming Perl 6 to Raku by takeda on Saturday October 12, 2019 @03:07AM (#21231175)
Perl gets a lot of flak, I am no fan of it, but frankly the least readable language IMO is bash.
Re:Larry Wall has approved renaming Perl 6 to Raku by WheelsAtLarge on Friday October 11, 2019 @09:06PM (#21229819)
True, it's very easy to make your code unreadable but other languages have the same drawback too. I would never pick it as the language for team projects. But with Perl you can really pack a lot of power into each line of code. It's hard to beat for scripting.
Re:Larry Wall has approved renaming Perl 6 to Raku by h1d on Saturday October 12, 2019 @05:31AM (#21231739)
Seems you've never used shell scripting.