Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is the benefit of the num prefix?

 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a lot of the assignemnts I've been nitpicking lately, I've seen variable names prefixed with <code>num</code>.

I'm curious as to what benefit people see to using this prefix?

I'm not necessarily asking only those who actually use it. Also, I'd like to hear arguments both for and against the use of such a prefix.

Also note that I'm not in Nitpick mode - I'm trying to figure out what I might be missing here.
 
Dick Summerfield
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How come noboby is answering? Surely those who have used this prefix chose it for some reason... ?
I thought I had never used it but I see I have - in a program working with some numbers which are purely that. They do not represent an amount of anything. In this case, surely it's reasonable to call them num1, num2 etc.? I have to admit that later I called them number1 and number2 (I remembered a tip from a nitpicker:- letters for identifiers come free in Java so why abbreviate?).
Anymore "num" users?
 
Evan Reisman
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think num is short for "numb," as in what happens to our brains during the holidays festivities.

On a more serious side (which is almost impossible with me), my feeling is that it is easier for people to think of a variable name as a string rather than a token or identifier (which is really what it is). So this is easier:

String seven = "seven";

rather than this:

int seven = 7;

So people have a tendency to do this:

int numSeven = 7;
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dick, there are most definitely other <code>num</code> users out there.

Evan, that sounds like a reasonable explanation. In those terms, it seems like a variation on hungarian notation, which I'm not particularly familiar with.
 
Belinda Lawson
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Katrina Owen:
In a lot of the assignemnts I've been nitpicking lately, I've seen variable names prefixed with <code>num</code>.

I'm curious as to what benefit people see to using this prefix?


Wow, I just realized that I sort of did this and didn't even think about it.
Let me see if I can lasso a reason by the horns.

In my most recent attempt, I used a variable named <code>numberOfFullLines</code> to denote, well, the number of lines that were fully populated by elements, as opposed to ones that were only partially populated. I guess an equally good name might have been simply <code>fullLines</code> or <code>fullyPopulatedLines</code> or <code>completeLines</code>.

This is an interesting question, since I have always felt that I am absolutely terrible at giving variables meaningful names. But by convention, I think counters that end in in the word <code>count</code> make sense. And maybe also limits that begin with <code>max</code>.

What's rather curious is that, just now, I realized that I would be inclined to completely spell out <code>number</code> in a varible, but use <code>max</code> as an abbreviation for maximum. Guess I'll nitpick myself for being inconsistent.

One thing that makes my head spin with regard to java naming is classes that end in the suffix <code>Impl</code>. I know that's short for implementation, but couldn't someone have picked a better convention? I see that all the time. Why not call the interface <code>somethingInterface</code> instead of calling the implementation <code>somethingImpl</code>? Who comes up with this stuff anyhow?

Ah well, maybe I'll hang out here enough and find out that there's nothing wrong with that after all, and it's just one of those pesky personal preferences...
 
Katrina Owen
Sheriff
Posts: 1367
18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I would also spell out <code>number</code> and abbreviate <code>max</code>. This is consistent with how I use the English language. I will often just say "max" rather than the full "maximum" when talking about limits.

I never, however, say "num" unless it is in the sense that Evan was talking about, "numb"
 
Jinny Morris
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Uh ... yeah! On the other hand, I've been nitpicked for both "num" and "max" ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic