The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

What do I call that variable ?

Ever have one of those moments when you just can't think what to call your variable. You know that you need it but you just can't come up with a name ? It's times like that when you realize that you don't actually know what the variable is going to be used for ! If you did then naming it would be easy ! It's times like that when you need to sit back and look at the bigger picture and perhaps have a cup of tea.
Martin Waller Send private email
Wednesday, August 24, 2005
 
 
Sometimes I run across that very situation.

That's why you'll see some variables called Fred in my code :-)
redeye Send private email
Thursday, August 25, 2005
 
 
If you don't know what you're going to use the variable for, how do you know you're going to need it?
Chris Tavares Send private email
Thursday, August 25, 2005
 
 
I like "monkey," personally.
Matt Brown
Thursday, August 25, 2005
 
 
Metasyntactic variables. Probably not the greatest for readability/maintainability :)

Foo
Bar
Baz
Quux
Bat
Xyzzy
shme

ref: http://en.wikipedia.org/wiki/Metasyntactic_variables
...But What Do I Know
Thursday, August 25, 2005
 
 
> If you don't know what you're going to use the variable for, how do you know you're going to need it?

That's why he's sitting back and having a cuppa - so he has time to work out what he's actually doing.  ;)

He already said that if you can't name it then you should realise that you don't know why you're doing it.

Thursday, August 25, 2005
 
 
I once worked on a system with variables named Tom and April and Aardvark.  I can't recall whether I changed them; if that section of code was working properly, I probably didn't.
Kyralessa Send private email
Thursday, August 25, 2005
 
 
Name them foo, bar, etc (or your local langauge swear words).  then go back and replace them when their use is more defined by the sematic context.

Because oftentimes it is hard to put a linguistic moniker on what you're doing. People don't think in English.
YaYaYa Send private email
Friday, August 26, 2005
 
 
If you are creating the variable, you have some idea of its purpose, so you'll at least have some related terms in mind.  Maybe, you are even trying to pick between a few different words.  (I find myself in that situation frequently.)

I go to a coworker and explain what the pros and cons of the words I have in mind are to someone else.  Sometimes they'll have a completely different suggestion that's better.  Usually, they'll at least have a preference for one or the other.

If not, then pick one among the top few and establish a convention.
dougqh Send private email
Monday, August 29, 2005
 
 
I often find myself in a situation where the variable name I want to use would be unwieldy but accurate.  Then I end up trying to find a word that means what the string of words it replaces means.  I am not sure this is good.  This happens to me more often with complex algorithms, or in sections of code that don't seem to have a break.  Usually I take it as an indicator that I should be refactoing or reorganizing the section.  At my day job we have the "tendency" to put the type (or some indication of the type) at the beginning of the variable name.  An example:

parEquipmentTypeId;

would mean an sql parameter that is the equipment type id.  This starts to become unwieldy when you take it out of a grid:

Convert.ToInt64(drVendorLocationRow.Cells["EquipmentTypeId"].Value)

I guess I am just lazy and don't want to type. 

Has anyone ever had a situation where they know what the variable is going to do, but an english name isn't really practical?  I find this happens to me when I have a set of data (amongst many other sets in the same method) that is very specific with what it holds.  I can't rightly name a set:

EquipmentCreatedInTheLastTwoYearsByVendorLocationId

I could say:

RecentEquipByVenLoc

but even that seems long, and it doesn't necessarily convey what the true contents of the variable are.  Thank god for intellisense.
Joshua Volz Send private email
Wednesday, September 07, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz