in reply to Re: Re (tilly) 3: References
in thread References

Cine - you're missing the point tilly's trying to make. The two syntaxes you're using, while legal, are horrid programming practice. Absolutely horrid.

The first breaks all sorts of scoping suggestions by using a lexical global within a tiny function, then using a scoped global right after! Do not do this!! Whenever I see this kind of crap in some program I've been asked to maintain, I rip it out immediately. Of course, it usually takes me an hour or so to do this, just because I can never be sure that there aren't dependencies elsewhere.

The second is a back-asswards way of dereferencing a hashref that would confuse the heck out of me, and anyone else who would read your code. I can read it now, but only because I have some context within which to read it. Again, if I ever saw this in some code I was maintaining, I would rip it out in a heartbeat!

"What should I do?" you ask? Do the following:

sub c { my $d = shift; $d->{$_} = $_ foreach (0 .. 200); }
And get used to it! This is the way people will write code for you to maintain. You will read this syntax.

In addition, if you're freaking out about which is faster, I decided to run your Benchmark script, adding in my subroutine. Just for kicks. Here're the results I got:

b: 154 wallclock secs (153.27 usr + 0.00 sys = 153.27 CPU) @ 1216.55/s + (n=100000) c: 152 wallclock secs (153.17 usr + 0.00 sys = 153.17 CPU) @ 1216.55/s + (n=100000) f: 156 wallclock secs (156.57 usr + 0.00 sys = 156.57 CPU) @ 1252.98/s + (n=100000)
Pretty interesting, huh?

------
/me wants to be the brightest bulb in the chandelier!

Vote paco for President!

Replies are listed 'Best First'.
Re: Listen to Tilly ... he knows what's what!
by Cine (Friar) on Aug 20, 2001 at 17:46 UTC
    I'm sorry I'm not making myself clear in what my goal is.
    First off I wanted to know if there were an easy and understandble way to filter out references, so that it was transparent that it was the hash from the caller that was being worked on. This was to archieve a way to hide the "gory" details about references ;)

    When I figured out that the only way to do this is to alter the symbol table (which is a hell of a lot more difficult to read and understand), I was curious if there were a visible speed difference, which I gladly saw there was not.
    Alas now I NO reason use this now.

    ps. As Efficiency of $$var, ${$var} shows there is no difference in b and c.

    T I M T O W T D I
      Now, you've piqued my curiousity. Why on earth would you want to filter out the most powerful syntax tool in Perl since the subroutine?!? References are the sole thing that took Perl from a glorified scripting language to a programming language that rivals the expressibility of almost every other C-like language out there!

      In addition, references are not a very complicated concept. Try explaining how C does strings to something, one day. Or, try explaining the friends concept in C++. All of a sudden, references become reeaaaalllly simple.

      ------
      /me wants to be the brightest bulb in the chandelier!

      Vote paco for President!

        It can be that both you and I believe that references are very easy to understand, but try to take a java programmer with little XP and teach him the concept of references. This was what I wanted to avoid, but if I have to explain sym tables instead, I will go a long way to explain refs first ;)

        T I M T O W T D I