Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: When hashes aren't enough

by dragonchild (Archbishop)
on May 25, 2004 at 15:26 UTC ( [id://356256]=note: print w/replies, xml ) Need Help??

in reply to When hashes aren't enough

Use a hash of hashes (aka, HoH). Yeah, you're treading close to OO, but I'd take the plunge when the plunge is warranted. You're building a 2-level lookup table. Nothing more, nothing less. OO is for when your things do stuff. These things don't do much, other than retain knowledge.

We are the carpenters and bricklayers of the Information Age.

Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

I shouldn't have to say this, but any code, unless otherwise stated, is untested

Replies are listed 'Best First'.
Re: Re: When hashes aren't enough
by flyingmoose (Priest) on May 27, 2004 at 19:08 UTC
    While it is true that *real* OO is nice when objects do stuff, OOP in Perl, even if halfway done without doing stuff (it can do stuff, but doesn't have to), is a decent way to implement C structures in a halfway clean sort of way without having to deal with the ugly gorp that is an HoH. That being said, my objects contain HoH's all the time, but I really hate it when outside methods must delve into them each time the hard way, or to iterate through their keys.

    I suggest you take the plunge, but retain the knowledge of the old ways. Properly mixed, they are powerful. You never really have to go "pure OO" if you want to, especially not in Perl. Trivial OO (i.e. objects that just work like C glorified structs) is ok for starters until you decide to add more real-OO functionality. Of course, OO isn't really OO until you are using inheritance and other fancy over-hyped concepts :)

    Note that over half of the developers that think they are doing "real OO" are just using overglorified structs -- which means (yes), you can do that in C or pretty much in any language. The next step is to mix functional, procedural, and OO styles all in one, which sounds goofy -- but it's kind of cool at the same time. Anyhow, go forth, and take the plunge. The water's fine. (Just beware the alligators -- such as folks who profess fancy "design patterns" and don't have enough common sense to keep things simple when they can be simple).

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-21 09:00 GMT
Find Nodes?
    Voting Booth?

    No recent polls found