News for hackers. Stuff that matters.
Re:Perl 5.26.0 released by joosters on Thursday June 01, 2017 @07:54AM (#14459492)
Perl 5 isn't a 'cool' language, because it isn't trying to rapidly change itself, instead it just works. I use it just about every day (by my own choice!) and it can be a fine language to develop in. The libraries available in CPAN contain support for pretty much any task you could think of.

Most of the horror stories that you'll hear about perl are from people who have tried to fix/maintain code that was written badly, which is no different from any other language. You can write horrific or easily-readable code in any language.

Perhaps perl has its reputation because it is often used as a quick kludge to do something that would be just too painful to do in shell script, and novice writers just cut & paste stuff from their searches online to get the job done?

Re:Perl 5.26.0 released by rootusrootus on Thursday June 01, 2017 @10:55AM (#14460744)
As a long time Perl programmer myself who has been doing Python for the last three years, I have to say that it is much easier to write unintelligible Perl code than Python. Not that you cannot write some gross things in Python if you try, but the language defaults towards readability and the community strongly encourages it.

I recall a great talk a couple years ago at OSCON that Damian Conway gave about how you could essentially turn Perl into a custom language that exactly fit your needs. I walked out of there thinking "wow! That is incredibly awesome, and yet I would never consider it for a business environment." Perl is an appealing language for people who like languages. I count myself as one of those. But I cannot deny that Python makes so much more sense for teams of more than one person.

Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @10:59AM (#14460767)
The one thing that I miss in Python is true anonymous functions. Perl has them. JavaScript has them. Ruby has them. Python just has lambda functions which can only evaluate an expression.
Re:Perl 5.26.0 released by btilly on Thursday June 01, 2017 @11:11AM (#14460895)
Meh. In Python you can put a def inside of any scope you want and do anything that you want with it. The fact that it winds up with a name in that scope doesn't stop it from being anonymous everywhere else.

At that point the difference is just syntax.

Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @12:31PM (#14461763)
You're declaring the function within that scope. You can do this in other languages too. In Javascript, I can declare a function within a scope too:

  function myFunc () {
    var myFunc2 = function () {};
    return myFunc3().then(myFunc2);
  }

This isn't some Python-specific thing.

> At that point the difference is just syntax.

Isn't that the case with most things? If I said that I missed curly braces, that's "just syntax" too.

Re:Perl 5.26.0 released by seertaak on Thursday June 01, 2017 @01:49PM (#14462625)
I think the parent poster was referring to the fact that the critical thing is that a) you can define a function within the scope of another function, and b) you can return the inner function. To do this requires something called a closure, which in general involves some of the local variables being transferred to the heap.

You're right that almost all dynamic languages have this feature, but to give you two notable languages that don't: C doesn't allow defining inner functions. Pascal allows to define inner functions, but doesn't allow you to return them. C++ does allow you to define inner functions (actually functor classes) and allows you to return them, but you need to be explicit about the capturing process.

Re:Perl 5.26.0 released by btilly on Thursday June 01, 2017 @03:02PM (#14463376)
Right. Anything that you could want to do with an anonymous function, you can.

It is less frustrating for me than the fact that the scoping rules for a var in JavaScript mean that you're likely to scope to the nearest function call rather than loop. Despite having anonymous functions, doing what I would want to do with them in JavaScript is often much harder than doing it in Python.

Re:Perl 5.26.0 released by vram22 on Thursday June 01, 2017 @06:57PM (#14465692)
>You're declaring the function within that scope. You can do this in other languages too.

>This isn't some Python-specific thing.

I think btilly meant that by the ability to do in Python what he described (define a nested function and then return it), you get (almost) all the same features as anonymous functions (and specifically, more than Python's lambdas give you, because they can only contain an expression, not statements) - in response to what you said:

>Python just has lambda functions which can only evaluate an expression.

In fact, IIRC, Guido (van Rossum, Python creator) has been known to say, to people who complain about the limitations of lambda in Python, to just use nested functions. And BTW they are quite powerful so you can do a lot with them.

He (btilly) was not implying that other languages cannot have nested function declarations (if I understood his comment right).

Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @07:10PM (#14465790)
> And BTW they are quite powerful so you can do a lot with them.

I'm not saying that they aren't powerful. I'm saying that personally, I find declaring one-time-use functions in-line to be syntactically more pleasant / organized than sticking the function definition in the middle of functional code.

I'm not a newbie to Python, but after working with it for years, it's one of those things that I still wish existed. It's not necessarily a pain point or deal breaker or anything. I'm not even sure how it could work given Python's syntax.

Re:Perl 5.26.0 released by vram22 on Friday June 02, 2017 @10:11AM (#14469992)
>I find declaring one-time-use functions in-line to be syntactically more pleasant / organized than sticking the function definition in the middle of functional code.

Ok, I get what you mean now, and think you have a point there.

Re:Perl 5.26.0 released by mixmastamyk on Thursday June 01, 2017 @12:02PM (#14461456)
And better clarity---I've seen anonymous callback hell in .js, no thanks.
Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @12:32PM (#14461768)
That's not a requirement of anonymous callbacks. That's just a symptom of poor coding standards. It can happen in Python too.
Re:Perl 5.26.0 released by mixmastamyk on Thursday June 01, 2017 @02:59PM (#14463349)
And yet the two go hand in hand. Have never seen it in Python, though have never used twisted either.
Re:Perl 5.26.0 released by pyre on Friday June 02, 2017 @09:50AM (#14469839)
> And yet the two go hand in hand.

It's a tool that can be abused. Saying that the number of tools available should be limited so that they can't be abused seems counter-productive.

Re:Perl 5.26.0 released by mixmastamyk on Friday June 02, 2017 @06:17PM (#14473705)
The trend toward limiting ultimately counter-productive language flexibility is getting stronger, not weakening.

See static typing, golang, and functional languages.

Re:Perl 5.26.0 released by nf05papsjfVbc on Thursday June 01, 2017 @11:53AM (#14461357)
I think perl invites a kind of mindset from how the language is and how the initial community was.

Why does it have something called 'say' instead of something more intuitive like 'println'. Then there are worse examples: carp, cluck, croak. These are commonly used. They are from the same module of course. There is also Moo, Moose. I'm not sure but was there something called 'Mo' too? Commonly used of course but as you can see from the names - you can't tell what they are for.

So, I think from some of the choices made in how the language is, it ended up being more drawn towards unreadability than readability by attracting a kind of mindset that wanted it to be 'fun' in a way that only a clique could relate to and now if the language doesn't have broad appeal, I think it shouldn't be that hard for them to accept that fact.

Re:Perl 5.26.0 released by perigrin on Thursday June 01, 2017 @01:04PM (#14462136)
I'm biased, I've release bits for Moose but ... Django, React, Rails, Spring, : can you tell what they are used for from the names? Does this mean that Python, Javascript, Ruby, and Java are "drawn towards unreadability than readability by attracting a kind of mindset that wanted [them] to be more 'fun'"?

In fact Moose, Catalyst, Starman, etc were all projects specifically named more fun _becasue_ their authors saw other communities not naming things "DBIx::Class" or "ExtUtils::MakeMaker" and wanted to bring some of that fun to Perl.

Re:Perl 5.26.0 released by yellowapple on Thursday June 01, 2017 @04:57PM (#14464633)
"Why does it have something called 'say' instead of something more intuitive like 'println'."

'say' is a lot more intuitive than 'println' for me. In the former case, I'm telling my program to say something. In the latter case, I'm telling it to... print? What if I don't have a printer? And what's a 'ln'? Line? Loan? Loon?

In other words, 'println' is not "intuitive". The word you're looking for is "conventional" or "familiar", and it's only either or both of those things if the programmer is coming from a different language.

Perl was the first programming language that really "clicked" for me, though, so I'm probably a bit biased there.

(as a side note, Perl has a 'print' as well, which actually predates 'say' by a considerable amount ('say' only became a thing in, what, Perl 5.10?). 'say' is pretty much just 'sub say { print "$_[0]\n"; }'.)

"Then there are worse examples: carp, cluck, croak."

'carp' and 'cluck' are weird, yeah. 'croak', however, makes sense in the context of 'die'.

"There is also Moo, Moose."

Both of which feature the letters "oo", which usually stands for "object-oriented". Not as obvious as I'd personally like, but once you spot that it becomes clear that both have at least something to do with Perl5's object system.

Re:Perl 5.26.0 released by cutler on Saturday June 03, 2017 @07:39PM (#14479104)
... which is basically just blessed hashes.
Re:Perl 5.26.0 released by yellowapple on Sunday June 04, 2017 @12:53AM (#14479941)
Blessed anything, really. One could bless a scalar or array if one so chooses (not that I would recommend doing so, but whatever).

But yeah. Perl 5's flavor of object-orientation is remarkable for exposing the inner workings of objects to the programmer. Fields are just hash table items. Methods are just subs that take the object as the first parameter. Classes are just namespaces/modules full of methods and constructors. Constructors are just ordinary subs that return blessed data structures.

It's all remarkably simple and elegant once you're used to it.

Re:Perl 5.26.0 released by dragonwriter on Thursday June 01, 2017 @05:01PM (#14464671)
> Why does it have something called 'say' instead of something more intuitive like 'println'.

"Say" is a common English verb that fairly directly communicates the action performed (with a bit of metaphor, sure.)

"Println" is, well it starts out with something which might be as good as "say" and then has some extra opaque consonants glued on the end.

The latter is only "more intuitive" from the perspective of someone whose used languages which happen to use it in the past.

Re:Perl 5.26.0 released by throwaway7645 on Friday June 02, 2017 @09:44PM (#14474497)
Exactly. "Print" originally made me think of an ink printer. "Say" makes alright sense. Strangest I've seen is the basic language PBASIC's "debug" statement for the BASIC STAMP controller.
Re:Perl 5.26.0 released by chromatic on Thursday June 01, 2017 @03:03PM (#14463392)
Why does it have something called 'say' instead of something more intuitive like 'println'.

Why is the Unix command `ls` not `list-directory-contents`? Sure, it's a lot more for everyone to type all the time, but you could get rid of a single line in the man page, meaning the name is much, much more intuitive!

Re:Perl 5.26.0 released by vram22 on Thursday June 01, 2017 @07:02PM (#14465731)
>Why does it have something called 'say' instead of something more intuitive like 'println'. Then there are worse examples: carp, cluck, croak. These are commonly used. They are from the same module of course. There is also Moo, Moose. I'm not sure but was there something called 'Mo' too? Commonly used of course but as you can see from the names - you can't tell what they are for.

I'm not a Perl expert, but have read books on it and done a bit with it. I think Perl tends to attract the kind of people who find these kinds of names (and many other things) fun, and are not put off by it - which is fine.

>worse examples

According to who(m)? Opinions differ.

Re:Perl 5.26.0 released by nf05papsjfVbc on Friday June 02, 2017 @05:37AM (#14468662)
EDIT: Please, before you get fixated on 'say', consider that perl already has 'print'. So, it has "print" and "say" - where "print" is "print" and "say" is "println".
Re:Perl 5.26.0 released by pyre on Thursday June 01, 2017 @10:57AM (#14460758)
> instead it just works

All of those other languages "just work" too. I'm not really sure what you're getting at with this comment.

I worked with Perl 5.x in for 4 years a while ago. It's not as bad as people really think it is. That said, there are a lot of things that can cause you to go wrong. For example: source filters. Super powerful, but if implemented wrong can make debugging a nightmare.