Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Long identifiers are fine (Re^2: CGI Tables)

by Flexx (Pilgrim)
on Sep 02, 2002 at 10:20 UTC ( [id://194557]=note: print w/replies, xml ) Need Help??


in reply to Re: CGI Tables
in thread CGI Tables

Uh! Bad advice (the "shorten your variable names", not the map example)! Sorry, just my humble opinion.

As soon as the scope of the variable you use is larger than 5 lines, use Identifiers::Long! ;)

Then, if it's just 5 lines, you'll survive typing a long name two or three times either. When someone else will need to read your code -- and after 6 Months you yourself are someone else -- he'll be glad to have meaningful names.

I banned $i for counters right after school (where the formula's my programs were based on used i, of course), and I never missed it. Even if it's an iteration I'd rather use $iteration_count. And in case of indices it's nice to expess what your're indexing.

And let's be honest, typing $request especially in a coding situation takes me no longer that typing $r. Well almost... It surely takes more time to read (and lookup/translate and undestand) $r for anyone not knowing the obvious...

If I don't want to repeatedly type an identifier with a fancy name I simply cut and paste. Of course, it's good to know how to do that using your keyboard... ;)

There's enough abbreviation in Perl anyway ($_, $a, $b, $#array, etc.).

So, while I'm with you that obfuscuated perl is cool and fun, yet for serious work it's cool to use @long_names, and lame to be $lzy.

So long,
Flexx

PS: I know I am a style phanatic.

Update: Humm... I just realized I talked back to a saint... :] (...) a lazy saint. ;)

Replies are listed 'Best First'.
Re: Long identifiers are fine (Re^2: CGI Tables)
by tadman (Prior) on Sep 02, 2002 at 13:42 UTC
    Think of variable names in a LZW compression style. The more you use it, the shorter it can get, but to a point. I was just saying that for things you use capital-A All The Time, you can get by with a single letter. For me, $r is Always the same thing. It's sacred.

    If you want, you can call it $apr, or whatever, but things like $apache_request are kind of like naming your dog The Happy Canine Who Is My Life-Long Friend Named Spot. When you're talking about $dbh or $cgi, you should have an idea what you're dealing with.

    What I don't like is functions like this:
    sub mulch { my ($x, $z, $zz, $a) = @_; $x->foo($z, $zz, $a->id()); $z->insert($x); $a->restore(); return $x; }
    Isn't that informative? Without backtracing through caller after caller, you have no idea what type the variables are. Sure, you could put in some diagnostic code, but isn't that kind of absurd?

    All I'm saying is that if you use someting A Lot, you can reduce the letter count accordingly. If you use it almost never, you should be pretty clear as to what it is.

      Sure, you're right, $dbh, $sth (and $foo and $bar ;) and the like are almost reserved words... ;)

      The sorry thing is, there's a lot of mulch() out there...

      However in a script where I use HTTP::Request, CGI, and XML::Parser I'd still rather have $parser, $query and $request instead of $p, $q and $r.

      But maybe that's just because qbpd are just mirrors and rotations of each other... ;)

      Cheers,
      Flexx

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found