elfs: (Default)
[personal profile] elfs

I’m prepping for an interview this afternoon at what is primarily a Perl shop, and so I’m mainlining the O’Reilly Perl in a Nutshell book as a way of reminding myself about the little details of the language. I can write Perl just fine– I just made some major hacks to dailystrips for example, and I write various renaming and text processing scripts all the time in Perl, because it is the language for that kind of thing.

But it’s little corners like, exactly what does bless do, that I’m reminding myself of. I know it’s the OO instance creation operator, and I remember the instantiation procedure but what exactly does it do?

So I go read the source code for Perl, in C, because that’s where the magic is kept, and I discover to my not-so-surprise that bless is a complete and utter hack. It puts a flag in the dereferencer to point to a different function, one that seems added after-the-fact, that instead of handling a procedure one way, instead just handles it another way with the recently dereferenced scalar as the first argument. That’s all it does. OO is so “bolted onto the side” of Perl that it’s amazing how important it seems to have become to the language.

But there’s so much missing from Perl; the whole metaprogramming capabilities of modern languages like Python, Ruby, and Javascript is just gone– done instead with code generation and eval, good grief– and yet the capacity for obfuscation is so terribly great. In many ways, Perl feels more like Bash scripting with a much bigger library of niceties and bolt-ons, which may explain why I use it that way.

This entry was automatically cross-posted from Elf's technical journal, ElfSternberg.com

Date: 2009-07-10 06:01 pm (UTC)
From: [identity profile] lucky-otter.livejournal.com
It *is* possible to use Perl as a properly OO language, with much more powerful capabilities, but it requires using add-ons that substantially change things like inheritance. And of course it may still munge your datatypes if you pass something to a method that's written in a different style.

I did this a while back, but it's not at my fingertips anymore.

Date: 2009-07-11 02:40 am (UTC)
From: [identity profile] duskwuff.livejournal.com
Perhaps you're thinking of Moose (http://search.cpan.org/~drolsky/Moose-0.87/lib/Moose.pm)?

Pay No Attention to the Man Behind the Curtain

Date: 2009-07-10 06:20 pm (UTC)
From: (Anonymous)
So I go read the source code for Perl, in C, because that’s where the magic is kept,

Now you've taken all the magic out of your life by exposing it as simple dreck, so where does that leave you? :^)

Personally I consider C one of the worst programming languages ever created, which probably explains its popularity. It's a bunch of programmer shorthand that was never consistent across machines with different word lengths, and statements that looked perfectly simple and reasonable and would compile and execute just as you expected them to in virtually every other language could give you horribly wrong answers in C. And as for "the awesome power and flexibility of pointers", I would be just as happy to see them disappear at the same time that PEEK and POKE and GOTO disappeared from the programming ventricular.

YMMV, but mine is at least an equally informed opinion.

--DB_Story
From: [identity profile] duskwuff.livejournal.com
And as for "the awesome power and flexibility of pointers", I would be just as happy to see them disappear at the same time that PEEK and POKE and GOTO disappeared from the programming ventricular.

I would be interested to see you try to do anything useful in C without pointers. Go on, try it.

From: (Anonymous)
I would be interested to see you try to do anything useful in C without pointers. Go on, try it.

Funny thing, I can write in Java, which is pretty darn C-like, and nary an exposed pointer to be seen. And I can name quite a few other high-level languages that I can say the same about.

And yes, I've written in nearly a dozen assembly languages over the years, actually rather like assembly when there's a reason for it (my absolute favorite was for the PDP-11), and have no trouble at all working with direct memory addresses. The point of high-level languages is to not have to deal with the housekeeping tasks and make coding faster and errors harder to commit.

My C experience goes back to 1977, and I've never liked it. But then again, that's just me.

--DB_Story
From: [identity profile] duskwuff.livejournal.com
Once you get beyond a couple of surface features which differ (pointer math, primitive references, and casting), there ends up being surprisingly little conceptual difference between C pointers and Java object references.

Date: 2009-07-10 06:47 pm (UTC)
blaisepascal: (Default)
From: [personal profile] blaisepascal
OO in Perl5 is, as you describe it, incredibly bolted onto the side.While Perl In A Nutshell isn't really the place to get into it, the Camel book is, and does.

(And "Bash scripting with a much bigger library of niceties and bolt-ons" isn't a bad way to describe the origins of Perl... The desire was to incorporate into one tool the libraries and bolt-ons normally involved with shell scripting, things like grep, awk, sed, etc).

The good news is that Perl6 is OO through-and-through; the bad news is that Perl6 has been in development for nearly a decade and isn't ready yet; the second good news is that there are already working implementations of Perl6 (as it stands now) that can do some amazing things; the second bad news is that they aren't ready for production yet.

Date: 2009-07-11 01:55 pm (UTC)
From: [identity profile] genehack.org (from livejournal.com)
The second good news is Moose (as mentioned above) brings quite a bit of the Perl6 OO goodness to Perl5...

Profile

elfs: (Default)
Elf Sternberg

May 2025

S M T W T F S
    123
45678910
111213141516 17
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Jun. 9th, 2025 04:49 pm
Powered by Dreamwidth Studios