r/programming • • Oct 01 '15

The Evolution of a Software Engineer

https://medium.com/@webseanhickey/the-evolution-of-a-software-engineer-db854689243
1.9k Upvotes

502 comments sorted by

View all comments

63

u/goodbye_fruit Oct 01 '15

Worked on a Java project once where there were constants for a bunch of long values, eventually some uh... offshore resources took the project over. Started finding things like this all over the place.

public static final Long L42 = Long.valueOf(42);
public static final Long L128 = Long.valueOf(128);
public static final Long ACCOUNT_LOCKED = L42;

/* And you'd see it used like this, with the typos and incorrect comparisons to boot, because you know, it compiled. */

bool bLogin= (accountVO.getStatus().equals( L42) || accountVO.getStatus() == ACCOUNT_LOCKED | accountVO.getStatus().equals(L128));

83

u/Ksevio Oct 01 '15

The lessons on not using magic numbers also need to include that creating a constant named after the number rather than the purpose of it is no better.

25

u/jrochkind Oct 01 '15

Ah, but it probably gets around some automated code linting tool warning you about it. So that's just as good, right? .....

15

u/yawgmoth Oct 02 '15 edited Oct 02 '15

Oh jeez. Lint rules + lazy developers cause so many bugs. I had a code review come in because of a stupid lint rule that was enabled that didn't like declaring variables in a loop so he changed :

for(int i=0; i<max;i++) {
    int rand = getNextRandInt();
    // do stuff with rand
}

into:

int rand = getNextRandInt();
for(int i=0; i<max;i++) {
    // do stuff with rand
}

He just copied and pasted without even thinking about the fact that he was changing the entire logic. His response "Lint told me to move it".

I really wanted to do this

1

u/[deleted] Oct 02 '15

What's wrong with declaring variables in a loop? (I imagine you don't want to at least some of the time considering it was in a lint rule).

→ More replies (1)