Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Using functional abstraction in Perl

by spurperl (Priest)
on Jul 02, 2005 at 09:16 UTC ( [id://471896]=note: print w/replies, xml ) Need Help??


in reply to Re: Using functional abstraction in Perl
in thread Using functional abstraction in Perl

The has is only an example, a demonstration of a broader concept. I tried to make it as simple as possible, but often this approach is used to hide more complex data structures than plain hashes. For example, I was referring to HoAoHs or something like that.

It's OK to use hashes directly. It's not OK, IMHO to use HoAoHs directly, but better abstract this usage away.

Even in the small example I presented, the implementer of the binding abstraction may decide that (for some reason) it will be better done with an array or a tree (perhaps the typical data will make it more efficient). The abstraction allows to hide it from the "user code".

  • Comment on Re^2: Using functional abstraction in Perl

Replies are listed 'Best First'.
Re^3: Using functional abstraction in Perl
by revdiablo (Prior) on Jul 02, 2005 at 18:47 UTC
    The has is only an example, a demonstration of a broader concept.

    Fair enough, but as you can probably see by the replies, your broader concept got lost in the example.

    It's OK to use hashes directly. It's not OK, IMHO to use HoAoHs directly, but better abstract this usage away.

    That would be more reasonable. I certainly would understand more readily if I saw code that did this. Though, I'm still not buying it 100%. I see a lot of code that handles these type of data structures "raw", and I don't think it's really that bad. For instance, I wouldn't blink twice if I saw something like:

    my %thread = ( title => 'Using functional abstraction in Perl', participants => [ { nickname => 'revdiablo', status => 'replying', replies => 3, }, { nickname => 'spurperl', status => 'unknown', replies => 4, }, ... ], ); do_something(with => %thread);
    the implementer of the binding abstraction may decide that (for some reason) it will be better done with an array or a tree

    As BrowserUk aptly explained, this type of thing can be abstracted in a different way in Perl. Rather than forcing users to make function calls that do hash-like things, we can have hashes that trigger function calls. I'm not saying tie is the right option in every case, but it's certainly a nice alternative.

    A quick side note, related to the other thread about OO. I'd like to point out that -- though you may not be willing to accept the terminology -- what you're doing is very OO-ish. You're passing a chunk of data (an "object") around to various functions ("methods"). This is essentially how OO works in Perl; the object is passed as the first argument to the methods. (Of course, there's no inheritance or polymorphism here, but those are only another aspect of OO, not the defining characteristics.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://471896]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-16 13:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found