Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Favorite Descriptive Variable Name

by vroom (His Eminence)
on Dec 21, 2000 at 20:20 UTC ( [id://47813]=poll: print w/replies, xml ) Need Help??

Vote on this poll

$foo
[bar] 170/47%
$bar
[bar] 12/3%
$baz
[bar] 19/5%
$bob
[bar] 36/10%
Other
[bar] 123/34%
360 total votes
Replies are listed 'Best First'.
(Ovid) Re: Favorite Descriptive Variable Name
by Ovid (Cardinal) on Dec 21, 2000 at 21:33 UTC
    I was working on a program once where the author named his variables after different types of alcohol. One line in the program was:
    COMPUTE MARTINI = GIN + VERMOUTH.
    I could have killed him.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      I've occasionally punned with variable names. One I like (and I forget where I first saw it) was %cornedbeef. (corned beef hash). I've been do to do { ... } until $cows_come_home; or { ... } until $hell_freezes_over; for nigh-endless loops.

      When I'm not being creative, I find myself occasionally using junk variables like $stuff, $stuf, $stuph, $morestuff, $yetmorestuff, $evenmorestuff, $toomuchstuff, so on and so forth.

      =Blue
      ...you might be eaten by a grue...

        When calling the function phish() or moe(), I'll often pass the %|. Especially because I don't need it. ;)

        japhy -- Perl and Regex Hacker
      I once reviewed a program with lots of cinematic references like:
      MOVE INDIANA_JONES TO TEMPLE_OF_DEATH
      cheers, fengor
      --
      "WHAT CAN THE HARVEST HOPE FOR IF NOT THE CARE OF THE REAPER MAN" -- Terry Pratchett, "Reaper Man"
Re (tilly) 1: Favorite Descriptive Variable Name
by tilly (Archbishop) on Dec 21, 2000 at 23:52 UTC
    To go with all of these temporary variable names, here is a useful naming convention.

    Make all of your flags be questions starting with "is".

    One of the most common errors people make is to reverse what a flag is supposed to stand for. For instance if you are looking at a variable called $status_flag, is 1 success or failure? Who knows? Much better to call it $is_ok or $is_bad as appropriate, then there is no room for confusion.

    The rule is, Say what you mean, mean what you say, and stop saying it before you mess up! Make your variables say your story. Don't leave landmines by changing what they mean. Don't make people have to maintain stuff in both comments and code. So on and so forth...

Re: Favorite Descriptive Variable Name
by Albannach (Monsignor) on Dec 21, 2000 at 20:51 UTC
    Though I automatically use $foo (and $bar next), when I need a couple more I tend to use $fee, $fie, $foe, $fum. I have no idea why - maybe it comes from having kids?

    Update: I was browsing the jargon file on foo and thought others might enjoy this bit which fits well with our metaphor:

    An old-time member reports that in the 1959 "Dictionary of the TMRC Language", compiled at {TMRC} there was an entry that went something like this:

    FOO: The first syllable of the sacred chant phrase "FOO MANE PADME HUM." Our first obligation is to keep the foo counters turning.

    --
    I'd like to be able to assign to an luser

(Guildenstern) Re: Favorite Descriptive Variable Name
by Guildenstern (Deacon) on Dec 21, 2000 at 20:47 UTC
    I love wearing my ThinkGeek shirt that says "Kung Foo". Very few people get the joke.

    Guildenstern
    Negaterd character class uber alles!
      i always like to start with $stuff or $something. nice & descriptive. (:
      do a lot of people use variable prefixes like $hr_something (hash ref), and $a_stuff (array ref) to show the type? my officemate/code reviewer has had me using these for a while- i don't know that it's helped my programming so much, but it makes it easier for him to find my bugs. it might be more of a Cish thing than a perlish thing.
        I like the idea of prefixing variables. It sure can't hurt, especially since Perl doesn't do strong typing.

        I used to do this with VBA code because a very solid manual on VBA recommended it as a naming convention, until I showed the code to a consultant who was to build a SQL 7 replacement for my Acccess application, who snickered and said that "real" programmers didn't do it that way. But now I've seen his code, and I don't care what he says. Personally I think anything that helps get the bugs out is good.

        Update: After reading tilly's comments, I'm reminded of the real reason I stopped using these prefixes in VBA, it was a pain in the kiester to go through and change all the instances of that variable name. In Perl I don't use anything like this because I tend to keep most of my blocks small enough that only a few pages of scrolling are needed to read the entire routine.
        I use that all the time. Always.

        My naming convention goes like this.

        • @aLine = array
        • $paName = pointer/reference to array
        • %hCountry = hash
        • $phLanguage = pointer/reference to hash
        • $objLog = reference to object

        The only really bad thing about this is the pointer/reference mixup, since there really are no actual pointers in Perl. This is a Bad Thing, but I'm reluctant to change on account of too much legacy code. I really should take some time and fix that though.

        Now, the good thing with using this naming convention everywhere is primarily that all parameters to subs are implicitly documented when it comes to type. I find that very useful.

        /J

      Hehe...the only person who understood my shirt was my AP Comp Sci teacher...and I have had the shirt for about two years :-). Kung foo baby, kung foo...
Re: Favorite Descriptive Variable Name
by Adam (Vicar) on Dec 21, 2000 at 22:47 UTC
    Actually, when working in Perl, my favorite descriptive variable name is $_

    Powerful, Ubiquitous, Descriptive.

      ...and you often don't even have to mention it in order to use it!

              - tye (but my friends call me "Tye")
Re: Favorite Descriptive Variable Name
by mirod (Canon) on Dec 21, 2000 at 20:58 UTC

    toto of course!

    I actually started using toto, tata... way before I read the jargon file, so I can testify it's the natural sequence for French speaking coders. I even had a friend who would do strings new_expensive_french_software | grep toto and never failed to find results.

    See the Jargon File for a complete list of descriptive variable names.

      I second mirod on this one! Though, some $scalar, @array or %hash might be quite fun when you have to review your code after a week or two.

      <kbd>--
      PerlMonger::Paris(http => 'paris.pm.org');</kbd>
        Of course, if you want to really mess with people, you could use $hash, @scalar, and %array... :)

        stephen

Re: Favorite Descriptive Variable Name
by c-era (Curate) on Dec 21, 2000 at 20:56 UTC
    Sometimes I use $this just to confuse the OOP people ; )
Re: Favorite Descriptive Variable Name
by amelinda (Friar) on Dec 21, 2000 at 22:57 UTC
    $foo, $bar, $baz, $bletch. I never seem to remember $quux when I'm actually coding.

    On the other hand, in actual practice, I find I use a lot of bad puns and such. Once, in a program that found digraphs, I started with a simple $di, and ended up with variables like $paparazzi.

Re: Favorite Descriptive Variable Name
by larsen (Parson) on Dec 22, 2000 at 14:56 UTC
    You know, professors often (and correctly) repeat to use descriptive variable names. I've heard about a student very bored by these advices. He wrote a program where every variable had a name like this one:
    int ove_si_memorizza_lo_valor_medio_de_la_lunghezza_de_le_stringhe_di_ +caratteri;


    The program was quite unreadable. I don't know professor's reactions :)
    see you
    lars
Re: Favorite Descriptive Variable Name
by Falkkin (Chaplain) on Dec 21, 2000 at 22:28 UTC
    Considering as how my Other Favorite Language is LISP, and being familiar with shortcuts such as (caaar)instead of (car (car (car))), I find that my metasyntactic variable list goes as follows:

    ($foo, $bar, $baz, $fooo, $baar, $baaz, $foooo, $baaar, ...)

    Is there anyone else out there who does this?
Re: Favorite Descriptive Variable Name
by gaudior (Pilgrim) on Dec 22, 2000 at 00:30 UTC
    I tend to use $junk, $stuff, $such.

    I had a boss once, long ago who used porn stars names. That made for interesting error messages!

(kudra: TAMARA) Re: Favorite Descriptive Variable Name
by kudra (Vicar) on Dec 21, 2000 at 23:03 UTC
    I tend to have files with names like foo, bar, or often just a single letter, but I rarely give my variables names like that. One thing you will find in my code a lot, however, is '# TAMARA' and '#NUKEME'. The second one is just for lines I want to remember to remove. The first is just a habit I picked up from a friend whose sole comments consisted of that. It's a good thing to grep for since it isn't likely to be in my file for any other reason. These are of course only 'work in progress' comments that are removed when I finish the program.
      This is a whole different kettle of fish. I usually use **DTR** standing for Dave the Rave... -- Dave
Re: Favorite Descriptive Variable Name
by Maclir (Curate) on Dec 22, 2000 at 09:02 UTC
    As someone who many years ago programmed in Fortran, $i, $j, $k for loop indicies.

    For those of you too young to remember such things, variables in Fortran (we are talking Fortran IV - not recent things corrupted by quiche-eating Pascal programmers) were never declared. Integer variables (by default) started with the letters I through to O (no case dependancy, either).

    Oh, the joys of FORMAT statements with nested implied do loops.

Re: Favorite Descriptive Variable Name
by FouRPlaY (Monk) on Dec 22, 2000 at 01:44 UTC
    $x... Always $x.



    FouRPlaY
    Learning Perl or Going To die() Trying
Re: Favorite Descriptive Variable Name
by jynx (Priest) on Dec 22, 2000 at 02:01 UTC

    definitely $_. And @_ and %_. it's very obvious which is getting used where too : )

    jynx

Re: Favorite Descriptive Variable Name
by Macphisto (Hermit) on Dec 22, 2000 at 01:08 UTC
    Most favorite == $pie

    Everyone has their demons....
Re: Favorite Descriptive Variable Name
by Anonymous Monk on Dec 22, 2000 at 02:35 UTC
    $asdf I Wouldn't want to run into other of my junk vars!
Re: Favorite Descriptive Variable Name
by BigJoe (Curate) on Dec 21, 2000 at 23:13 UTC
    I usually go with $val ro $var then hit the standard $foo, $bar, etc.

    --BigJoe

    Learn patience, you must.
    Young PerlMonk, craves Not these things.
    Use the source Luke.
Re: Favorite Descriptive Variable Name
by agoth (Chaplain) on Dec 22, 2000 at 14:43 UTC
    $flibble and $wibble get used in mine......
    or $flib and $wib if Im being terse.....
Re: Favorite Descriptive Variable Name
by MadraghRua (Vicar) on Dec 23, 2000 at 01:31 UTC
    Mine are fairly boring in comparisson to most of these. I tend to parse files a lot, so I have a wee system to help me remember what I'm working with at anytime. So opening the file is $inputFile, writing to a file is $outputFile. Reading in a file line by line is @inputData and turns $inputLine. It can get split into @processedLine. As I do stuff with the array, array elements can get pushed into @parsedArray. Simple names for a simpleton...

    MadraghRua
    yet another biologist hacking perl....

Re: Favorite Descriptive Variable Name
by extremely (Priest) on Dec 21, 2000 at 23:55 UTC
    I guess I'm just a lazy slug. I usually go with $a, $b, $c, etc. Years of schooling in Basic, Fortran and C taught me that for loops always need to be $i, $j, $k and that if you need more than four levels of loop you should start over...

    Of course, in perl that bites me on the ass at "m" or "s" or "x" or "y".

    --
    $you = new YOU;
    honk() if $you->love(perl)

      $a and $b might also bite you, considering they are magic global variables used by sort.
      I can understand "m", "s", "x", and "y" causing problems as subroutine names, which will conflict with the operators of the same names, but why would they be a problem as variable names?
        Basically because I DO use them for subs and filehandles etc etc... =)

        --
        $you = new YOU;
        honk() if $you->love(perl)

Re: Favorite Descriptive Variable Name
by Lexicon (Chaplain) on Dec 25, 2000 at 11:03 UTC
    I really like $foo when discussing code theoretically, but I never use it for actual programming. I frequently throw in $myInt's or such for quick things. In most other languages, I will usually label arrays as such, i.e.
    var clientArray = new Array();
    but this is of course redundant in Perl, which is nice because adding "Array" onto the end of a half dozen variables eventually takes up a lot of valuable horizontal space.
Definition of foo
by jeorgen (Pilgrim) on Dec 27, 2000 at 20:19 UTC
    I found this definition some years ago on foo:

    "A Foo is a Fab with a Bletch sticking out of its Flum"

    I think it was at a web site about lines of reasoning, or possibly in the good old Mac program MacEuclid docs

    /jeorgen

Re: Favorite Descriptive Variable Name
by Segfault (Scribe) on Dec 22, 2000 at 06:45 UTC
    I use $windows for my throw-away variables. I mean, Windows is junk, after all, so naming a trash variable after it seems only fitting...

      That's not nice. At times true, but not nice...

      -OzzyOsbourne

Re: Favorite Descriptive Variable Name
by ryddler (Monk) on Dec 22, 2000 at 07:35 UTC

    I'm guessing that anyone else that chose $bob as their favorite is also named Bob.

    I use this var in almost every prog/script I write as a debugging var because I know I'll remember what I called it when I go back through to remove all my debug code ;)

      hehe, I chose $bob, but my name is Wes.

      Why? Bob is, IMHO, the best name of all. If I ever feel like legally changing my name, it's going to be Bob.

      After all, it's a palindrome! Hooray for Bob!

        ah, Bob, but you spell your name backwards...
(crazyinsomniac) Re: Favorite Descriptive Variable Name
by crazyinsomniac (Prior) on Dec 22, 2000 at 13:48 UTC
    My favorite descriptive name is:
    $ascalar or $scalaro, %hasho, @arrayo;

    for loop counters i like to use: $ix, $ixx, $ixa, $nix, $mix

    or in strongly typed languages, like java, i like to use:

    Dialog dialogo = new Dialog();
    String stringy = new String();
    TextArea descriptivenameTA = new TextArea();
    and my favorite, Menu m = new Menu();
    >>>>>>>>>>>>>>>>>>>>>>>>>> death to javac, long live jikes! <<<<<<<<<<<<<<<<<<<<<<<<<<<<

    "cRaZy is co01, but sometimes cRaZy is cRaZy".
                                                          - crazyinsomniac

Re: Favorite Descriptive Variable Name
by Zoogie (Curate) on Dec 25, 2000 at 03:14 UTC
    Might as well add mine to the list, although I don't know where they came from... :)

    $foogle, $narfle, $goober, $argle

    - Zoogie

Re: Favorite Descriptive Variable Name
by Zo (Scribe) on Dec 27, 2000 at 23:33 UTC
    When learning programming, some variables made me crazy ( I hate ('HELLO WORLD!'), confused... so I learned with 'themes'.. almost similar to the posting about the alcohol.. but I used food (always got hungry infront of the pc). $pizza = 8; this way it made the art of programming more fun and kept my variables in check.. (fast foods, italian, etc..).. it's a bit unorthodox, but it worked when learning... (and I did it once on the job, my boss freaked out!), but I do it no more. -Monk Bro Zo.
Re: Favorite Descriptive Variable Name
by nivlac (Scribe) on Dec 28, 2000 at 02:13 UTC
    $this, $that, $here, $there....

    All seem to work well for me
Re: Favorite Descriptive Variable Name
by Anonymous Monk on Dec 28, 2000 at 03:35 UTC
    My absolute, all time favorite is $temp
    Zak
Re: Favorite Descriptive Variable Name
by JohnB (Scribe) on Dec 30, 2000 at 02:14 UTC

    In most programs I use descriptive variables that make the code easier to debug and document.

    The only exception to this is the project from hell. Some idiot in the marketing department decided to sell a product that hasn't been built in ten years.

    They also wanted some changes in the software and the hardware. This is a piece of test equipment that has C and assembly code embedded into the EPROM's on several PC boards. There was nobody left at the company that knew anything about the product. The software wasn't documented at all and some of the source code was missing but we still had the object files. The hardware department also had a difficult time because the schematics didn't match the PC boards.

    Everybody that had to work on this project thought it was a waste of time and money except upper management.

    When the C code was compiled there was about two hundred warnings. I did locate some people that originally worked on the software and they said the warnings are normal and just ignore them. We found a lot of if statements like this:  if (x=b){do_something;}. There should be two equal signs in the if statement.

    For the new changes to the program we started using variables like:
    waste_of_time
    time_waster
    money_waster
    crap
    worthless
    piece_of_shit
    junk

Re: Favorite Descriptive Variable Name
by elwarren (Priest) on Dec 25, 2000 at 01:20 UTC
    $cnt or $c nearly everywhere...
Re: Favorite Descriptive Variable Name
by alfie (Pilgrim) on Dec 29, 2000 at 15:28 UTC
    My alltime favorite is $blah. Just like Don't know how to name it - blah....

    Alfie

Re: Favorite Descriptive Variable Name
by fraktalisman (Hermit) on Dec 29, 2000 at 17:07 UTC
    Sometimes late traces of Commodore Basic can be found in my code: $a $b $c etc. $a is most possibly some kind of input, $i a loop iterator, and $x $y some coordinates. Words like $name or $count are not that much better. The worst thing is when you re-use code for another purpose, and the variable names don't match their content anymore.
      Avoid $a and $b. Avoid in particular declaring them with my.

      The reason is that they are special to sort, and therefore special to warnings and strict.

Re: Favorite Descriptive Variable Name
by Anonymous Monk on Dec 22, 2000 at 05:33 UTC
    $moron, $schmuck.....
Re: Favorite Descriptive Variable Name
by mischief (Hermit) on Dec 28, 2000 at 13:01 UTC
    Personally, I'm a bit of an "arse" man myself.
Re: Favorite Descriptive Variable Name
by Anonymous Monk on Dec 29, 2000 at 16:36 UTC
    $dakine
Re: Favorite Descriptive Variable Name
by Anonymous Monk on Dec 28, 2000 at 04:47 UTC
    $shit

    I mean... is there any other?

View List Of Past Polls


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 learning in the Monastery: (5)
As of 2024-03-28 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found