Take the 2-minute tour ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

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?

share

locked by Jamal Aug 10 at 0:07

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

1 Answer 1

up vote 4 down vote accepted

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.

share
    
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. –  Blake Dec 18 '12 at 15:29

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