I was fixing a bug in the code and it was something like this:

int const ROW_LOC = 1;
Foo ( x , y , ROW_LOC ) ;

so it was passing that constant to a method ... and this ROW_LOC constant is being used in multiple other places in the code too.

For ONLY ONE place in the code because this constant was getting passed to some method that was working with a zero-based index I did like this:

SomeOtherFooMethd ( x , str , ROW_LOC -1 );

So my question is: Do I need to create a separate constant with value Zero for this one method call or you would continue using the same ROW_LOC and like I did just decremneting it by 1 in this case?


1 Answer 1


It depends on the meaning of this constant. If the value ROW_LOC - 1 has logical relation to ROW_LOC (e.g. it means that it should go right before ROW_LOC in some list) then just use ROW_LOC - 1 there, but if it's just 0 - then either define a new constant or just use 0 as value, depending on situation.

What I would suggest is to rename ROW_LOC to more meaningful (descriptive) name unless it's a well-known acronym in your company.

  • \$\begingroup\$ yeah on the second method it should have been ROW_LOC too but there was a bug and that method was using zero-based so I used "ROW_LOC -1 " so I think that fits in the "logical relation to ROW_LOC"that you mentioned. \$\endgroup\$ Dec 18, 2012 at 15:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.