Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have been reading my latest version of the Camel Book, and I wonder to myself... what good are tied variables?

Hear me out before anyone gets upset. First... one of people's complaints about perl is that it's far too hard to understand and read. While I don't agree, I think tied hashes add an unnecessary layer of complexity that doesn't make much sense when you already have objects.

Imagine a novice looking at the following two code snippets:

<newbiecommenting>

# tie tie $var, "classXYZ"; $var = 5; print $var; # yields 25... ??? # objects my $var = new Squareable(5); $var->square(); print $var; # oh... yields 25... neato!
</newbiecommenting>

Granted, this is a bit of a juvenile example, but do you see what I'm getting at? How is a novice supposed to be able to discern this type of behavior? In the second example, it's easy to tell what happened. Objects are more self-documenting even without POD.

I know modules like the Ordered Hash Tie module are helpful, but even that could have just been an object.

Perhaps I'm missing something, but I just don't understand Tied variables. Even tied filehandles are probably better just as an object or an extension of FileHandle. You formally declare your behavior instead of hiding it behind the way that perl NORMALLY behaves.

If someone could enlighten me as to some really good uses of tied hashes that make more sense than using a similarly coded object, please do. Perhaps I'm just looking at it wrong.

--
perl: code of the samurai


In reply to Tied Variables - why? by samurai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-19 16:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found