Perl 5.38 Released with New Experimental Syntax for Defining Object Classes (phoronix.com) 48
Perl 5.38 was released this week "after being in development for more than one year," reports Phoronix. "Perl 5.38 brings a new experimental syntax for defining object classes where per-instance data is stored in 'field' variables that behave like lexicals."
"Maybe, just maybe, the new features introduced into the language in this newest version will attract much sought new talent," writes the site I Programmer, noting the argument that Perl is installed by default everywhere — and has the "fun factor... The class keyword is part of the plan to bring effective object-oriented programming to the Perl core while still keeping Perl being Perl."
The Perl docs warn that "This remains a new and experimental feature, and is very much still under development. It will be the subject of much further addition, refinement and alteration in future releases." But "Since Perl 5, support for objects revolved around the concept of blessing references with a package name," notes updated documentation, which points out this new class syntax "isn't a bless wrapper, but a completely new system built right into the perl interpreter." The class keyword declares a new package which is intended to be a class... classes automatically get a constructor named new... Just like with other references, when object reference count reaches zero it will automatically be destroyed.
Phoronx notes that Perl 5.38 also brings a new PERL_RAND_SEED environment variable "for controlling seed behavior for random number generation," along with some new APIs. And I Programmer adds that Perl 5.38 also adds support for Unicode 15.0, adding 4, 489 characters, for a total of 149,186 characters. Other additions include enhanced regular expressions, plus defined-or and logical-or assignment default expressions in signatures.
"Maybe, just maybe, the new features introduced into the language in this newest version will attract much sought new talent," writes the site I Programmer, noting the argument that Perl is installed by default everywhere — and has the "fun factor... The class keyword is part of the plan to bring effective object-oriented programming to the Perl core while still keeping Perl being Perl."
The Perl docs warn that "This remains a new and experimental feature, and is very much still under development. It will be the subject of much further addition, refinement and alteration in future releases." But "Since Perl 5, support for objects revolved around the concept of blessing references with a package name," notes updated documentation, which points out this new class syntax "isn't a bless wrapper, but a completely new system built right into the perl interpreter." The class keyword declares a new package which is intended to be a class... classes automatically get a constructor named new... Just like with other references, when object reference count reaches zero it will automatically be destroyed.
Phoronx notes that Perl 5.38 also brings a new PERL_RAND_SEED environment variable "for controlling seed behavior for random number generation," along with some new APIs. And I Programmer adds that Perl 5.38 also adds support for Unicode 15.0, adding 4, 489 characters, for a total of 149,186 characters. Other additions include enhanced regular expressions, plus defined-or and logical-or assignment default expressions in signatures.
Re: (Score:1)
No, Perl is like Python if Python had sensible syntax. For example, Perl has curly braces, and requires their use except when it doesn't. And isn't it obvious when you would use $#$FOO rather than <*FOO>?
Re:change the channel marge (Score:4, Insightful)
Perl and Python are just about exactly the same as far as I am concerned. I was a heavy Perl guy in the 90's through 2015 or so... Now I'm a Python guy. Python has just as many warts as Perl does, and a few more like python2->3, multiple pythons existing on the same system, and the ongoing Python3.6->Python3.newest... Also, python modules collide with each other all the time and things from upstream break us at least once a month (Pydantic just released a crap ball last Friday, actually and caused a fire drill for us). Some versions drop support for older version stuff. Python is a frigging tread mill of constant updates. Perl??? My code from the 90's written in Perl 5.12 runs just fine today for the most part. Hashes work the same, arrays and scalars work the same, the syntax is ok... You even can use objects. It's unpopular today, but Perl was damn near perfect. The only problem with Perl was CPAN and the horrible problems you'd run into trying to install modules. ActivePerl helped a bit there, but it's not as slick as pip... And even pip is a pita sometimes...
Anyway, I think I see some teenagers on my lawn... now shoo!
Python is perl designed by a college student (Score:5, Interesting)
Perl and Python are just about exactly the same as far as I am concerned.
I think what happened is that Perl had hashes, which are tremendously useful, but the rest of the syntax is conceptually hard to understand so a college student decided to implement a new language with hashes (dicts) without the concept of context.
I think that's how new computer languages come about - someone in college learns a language, thinks "this sucks, I could do better", and writes something new for their senior thesis. (Apropos of nothing, I'm right now tutoring a college senior in math who's doing exactly that - implementing a new language based on Go, but aimed at AI and machine learning.)
Perl has a lot of nice features that people don't appreciate. Most languages define the CPU operations natively and leave the OS operations to libraries, which leads to all sorts of portability problems when the OS calls for simple things like reading and writing files use different names and interfaces. Perl defines file ops and even directory listings as part of the language syntax, which means the same code will run on any OS and the actions taken are completely obvious to the reader.
Perl was written by a linguist (Larry Wall) and not a CS, so it has the concept of "context" like other human languages. This makes it harder to learn, but lots more expressive. Lots of things you typically want to do in code can be had by simply referring to an object in a different context. Things like sort, grep, and map are builtins and so don't require a lot of external setup to use.
And finally, Perl natively manages lists and memory allocation seamlessly without user intervention. A function can take a list of arguments, but passing back more than one value in C++ is conceptually difficult and a recipe for memory leaks. In Perl you just package up the vars as a list, using native syntax, and return it to the caller. No need to use class references, or worry about who allocates and deletes the list - perl does that for you.
that's the whole point (Score:1)
Re:that's the whole point (Score:4, Insightful)
This is obvious BS. Perl 5 has been releasing a new major version every year for a while now [cpan.org] (a new version adds 2 to the dot count, intermediate odd-numbered versions are development only).
So, this year's 5.38 had several additions including Classes, which is the first part of the new OO system Corinna.
Last year, 5.36, added a few other things, some highlights are probably the "finally" block for try/catch and iterating over multiple values.
5.34 in 2021 was the one added try/catch (you had to use a CPAN module before).
etc...
Re: (Score:1)
What is wrong with reading comprehension today. Yes they are adding features to Perl. But WE DON'T NEED THESE FEATURES.
Who is this "we" you're referring to? Surely you don't claim to know that "nobody" wants these new features and that nobody really actively develops with Perl anymore?
Re: (Score:2)
Re: (Score:1)
That's interesting, I'm quite confused on what video I should recommend you...
Who are "we"? If you are a Perl user and you subset of features is just working, congrats. If you're not a Perl user, why do you thing any other person in the whole world doesn't need it? If you're a Perl user and really need something else, help the community expressing it with real examples instead of throwing things like that. Or is Perl being maintained and financed by a bigtech we're not aware of and there are hundreds of eng
Re: (Score:1)
What is this Perl 5 you are talking about? Anything past 4 was added fluff and sent people packing to Python.
Re: change the channel marge (Score:3)
My biggest complaint with Perl was the fact that a single-character typo usually resulted in a trainwreck with completely unhelpful error message that generally blamed some part of the program far from where whatever was ACTUALLY causing the problem was.
Re: (Score:2)
This, apparently, is one of the things fixed in this release. See the perldelta page [metacpan.org].
Re: (Score:2)
And yes, languages that don't make you define your variables are fucking evil. use strict will make the compilation phase of perl fatally die if you attempt to use any variable that isn't defined in scope.
Re: (Score:2)
Re: (Score:2)
Yeah, from what I remember, the two big villains were "accidentally-omitted" (or spurious) quote or double-quote, or a semicolon that was accidentally omitted in a situation where it was actually required. I think mismatched parentheses/braces were another major cause of distant-error trainwrecks.
Making matters worse, the piece of shit laptop I had in 1999 did keybouncing via software... in the BIOS only. If you ran Windows 9x, it was OK... but if you ran NT (which, of course, I did), you had basically NO d
Re: (Score:2)
Yeah, from what I remember, the two big villains were "accidentally-omitted" (or spurious) quote or double-quote, or a semicolon that was accidentally omitted in a situation where it was actually required. I think mismatched parentheses/braces were another major cause of distant-error trainwrecks.
Yup, those guys get me all the time.
I don't miss semicolons so much, but quote-fuckups- ya. Fortunately, emacs is pretty good about noticing the problem at its actual source.
Re: (Score:1)
Ha! I remember thinking that when I started using Perl 20 years ago! You must not have used Perl seriously. It took me a couple of weeks to figure out that you just go to the topmost line with an error, and if the error is non-sensical it means the parser did not get that line at all, so look at what's missing right above it (usually a semicolon). Back then it could also have been a bracket imbalance, but most modern editors make that easy to control. At work we are still using (modern) Perl, and new develo
Re: (Score:2, Insightful)
Python3 should have also had the same treatment as Perl6. Those arrogant Python devs pulled it off though, forcing the entire world to bend the knee. What an ego boost that must have been.
Re:change the channel marge (Score:4, Funny)
Perl is very important even in 2023: it serves to remind the poor souls who have to code in VBA or Java for a living that it could be worse.
Re: change the channel marge (Score:1)
Just the first part of the new OO system Corinna (Score:5, Informative)
This is the first part of the modern OO Perl framework called Corinna [github.com]. While Perl supports OO via the "bless" method, people who wanted a complete system had to use the 3rd party Moose/Moo/Mouse frameworks.
Corinna is designed to be better and faster and become part of Perl's core (and also out-class if you allow the pun other languages' OO systems). If you remember 3 years ago "Perl 7" was going to come out (which would auto-enable the latest features that come in Perl 5 but require you declare some pragmas to not break old code), but it was decided to keep the 5.xx going on for now. I think the general feeling is that once Corinna makes it into core, Perl 7 will be released.
Now, while only the experimental Class syntax has made it into core on this release, you can actually use the new object system (and quite a few people do, even in production systems), as the prototype is available on CPAN as Object::Pad [metacpan.org]. There may be refinements by the time it makes it into core, but the syntax is mostly decided, so your Object::Pad code will be pretty much compatible.
Re: (Score:2)
Although I must say that Perl has some of the best array operations by default of any language, probably better than the traditional functional approach.
Re: (Score:2)
No, but OO inheritance is largely giving way to functional composition in everything from language syntax, frameworks, libraries, and supporting tools.
Re: (Score:2)
OO has mostly been an expensive mistake. Perl doesn't need it as is better off without it.
Exactly what Perl needs (Score:1)
More syntax.
Re: (Score:1)
Just give it up (Score:2)
Re: (Score:3)
23 years ago when I did something for our webservice in Perl it certainly wasn't
If you were on Linux, it almost certainly was. What may not have been installed was mod_perl.
Re: Just give it up (Score:2)
Re: (Score:3)
"Perl is installed by default everywhere" It is? 23 years ago when I did something for our webservice in Perl it certainly wasn't, and I never heard about it for windows. But just give it up, perl is so outdated and doesn't add anything to the already crowded world of development languages. Any sensible company would have redesigned its service/application away from perl 15-20 years ago. Just convert it to the, IMHO, abysmal python, javascript or C#, at least that way you know you can get more developers to continue it.
Wow! That's a seriously old quote.
FreeBSD dropped perl from the default install with FreeBSD 5.0, which was 20 years ago.
Re: (Score:1)
Re: (Score:1)
Nothing (well, nothing useful) is installed by default on Windows. That's literally Windows' whole schtick: you have to separately obtain and install every single piece of software you're going to use, and then each individual piece of software is going to have its own automatic-updates-installer running out of the system tray, and you're supposed to *like* it that way.
Re: (Score:2)
Clearly a windows hater because what you say is just completely wrong. Also what you say goes the same for Linux and MacOS.
Why would I need Perl installed if I never gonna use it? it should not be installed by default. The less installed the better, it needs to be installed when needed.
Re: (Score:1)
You've clearly never used any of the major Linux distributions; because no, they're not like that. What is included in a default install varies from one distro to another, but it's generally a lot more extensive than on Windows. And *none* of them (unless you count LFS) require you to separately obtain and install every piece of software individually. At worst, you just search for what you want in the package manager and push a button. Sort of lik
features (Score:2)
Most of the messages here talk about features in Perl and/or/vs Python.
Hash tables, multiple values, exception blocks (such as try/finally), keyword arguments, abstract file/directory interfaces, etc. Not to mention objects, lists, and garbage collection.
Also naming (package/module identifiers and references).
In other words, basic features from Lisp circa 1980.
Of course, Lisp has lots of other features not mentioned above.
There's anonymous functions (which many languages have picked up at least some notion
Re: (Score:3)
The only thing Lisp lacks is a syntax that doesn't make one's eyes bleed. For me and, I suspect, many, S-expressions are incredibly ugly, so IMHO that's one of the main reasons, if not the major one, few people use it. And so they go and reinvent it in a way, any way, that looks more reasonable, some such reinventions being explicit proposals for alternative ways to write Lisp.
Re: (Score:1)
I'm not aware of a single documented case of anyone ever *using* the feature, but it's there.
The feature I want from a lisp variant, is text buffers (and, relatedly, markers), from elisp.
Re: (Score:1)
was using format when printing to dot matrix printers in the early 2000s :)
Why? (Score:2)
this new class syntax "isn't a bless wrapper ...
Was something wrong with the Perl bless function?
... but a completely new system built right into the perl interpreter."
IIRC, bless is a builtin. So, not really a valid reason (not that this stops people from changing things).
Re: (Score:1)
Mostly, it's _different_ from the way C++ and Java do things, and that annoys people who come from those linguistic backgrounds.
Personally, the language whose object model and syntax I have always admired most is Inform 6. It's not (and not intended to be) a general-purpose language that you can use for most things; but its OO system is great.
Updated in T2 Linux (Score:2)
Redundant (Score:1)
...its syntax was born experimental.
Is OO needed or wanted in Perl? (Score:2)
Why not just keep making Perl better at what it does, instead of trying to make a silk purse out of a sow's ear?
Re: (Score:2)
Short answer: Yes.
Longer answer: Yes, I want it because OO makes polymorphism easier, and that helps with a range of programming tasks.
Yet longer answer: Perl gives you more than one way of doing things, it always has. Those who like perl tend to favor this approach, detractors point at it as a fault. You can use OO or not in your own code, the choice is yours. A fair number of CPAN modules give you both OO and non-OO interfaces.
Oh, and perl is already excellent at what it does, on that there is cons