Skip to main content
deleted 173 characters in body
Source Link
Robert Harvey
  • 200.7k
  • 55
  • 470
  • 683

The question you mentioned (Is every number in the code considered a “magic number”?) is arguably a duplicate of this one, but maybe we can add some more info here.

The first major problem with

connection.setLoginTimeout(30);

Is that you're assuming the junior developer you just hired who's looking at this 6 months from now will know that "30" is seconds & not milliseconds.

The second major problem (as @KilianFoth pointed out in a comment) is that again, 6 months from now, that junior developer might not be able to find this parameter very easily if at all.

An important point not brought up in your examples or the examples in the other question is that there is absolutely no reason to declare the constant right next to where it's used.

Instead, stick all of those "tuning parameters" in a common well documented place - perhaps a Constants.h file or equivalent.

The question you mentioned (Is every number in the code considered a “magic number”?) is arguably a duplicate of this one, but maybe we can add some more info here.

The first major problem with

connection.setLoginTimeout(30);

Is that you're assuming the junior developer you just hired who's looking at this 6 months from now will know that "30" is seconds & not milliseconds.

The second major problem (as @KilianFoth pointed out in a comment) is that again, 6 months from now, that junior developer might not be able to find this parameter very easily if at all.

An important point not brought up in your examples or the examples in the other question is that there is absolutely no reason to declare the constant right next to where it's used.

Instead, stick all of those "tuning parameters" in a common well documented place - perhaps a Constants.h file or equivalent.

The first major problem with

connection.setLoginTimeout(30);

Is that you're assuming the junior developer you just hired who's looking at this 6 months from now will know that "30" is seconds & not milliseconds.

The second major problem (as @KilianFoth pointed out in a comment) is that again, 6 months from now, that junior developer might not be able to find this parameter very easily if at all.

An important point not brought up in your examples or the examples in the other question is that there is absolutely no reason to declare the constant right next to where it's used.

Instead, stick all of those "tuning parameters" in a common well documented place - perhaps a Constants.h file or equivalent.

Source Link
Dan Pichelman
  • 13.9k
  • 8
  • 46
  • 74

The question you mentioned (Is every number in the code considered a “magic number”?) is arguably a duplicate of this one, but maybe we can add some more info here.

The first major problem with

connection.setLoginTimeout(30);

Is that you're assuming the junior developer you just hired who's looking at this 6 months from now will know that "30" is seconds & not milliseconds.

The second major problem (as @KilianFoth pointed out in a comment) is that again, 6 months from now, that junior developer might not be able to find this parameter very easily if at all.

An important point not brought up in your examples or the examples in the other question is that there is absolutely no reason to declare the constant right next to where it's used.

Instead, stick all of those "tuning parameters" in a common well documented place - perhaps a Constants.h file or equivalent.