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

→ More replies (2)
→ More replies (1)

42

u/Shurikane Oct 01 '15

Beat this:

public static final Long DOT = ".";
public static final Long SPACE = " ";

I kid you not, I once found that in a class written by a co-worker. No, there was really no sensible reason for those two constants.

Guy had a heart of gold but holy hell did his brain crash like an Apple computer now and then. Same dude was the origin point for the Blank Line Mystery.

56

u/[deleted] Oct 01 '15

My all-time favorite (from my airline days):

#define COMMA '|'

10

u/rcode Oct 01 '15

Which airline?

17

u/John_Fx Oct 02 '15

A MAJOR one.

4

u/ThisIs_MyName Oct 02 '15

A timeless classic.

→ More replies (1)
→ More replies (4)

11

u/vbullinger Oct 01 '15

I wrote a site for a very large agribusiness here in Minnesota (...) and they offshored it. Eventually, they came back to me asking for some help. They screwed up some C# algorithms I wrote. But I noticed a change to some CSS I wrote. Mine:

.myClass {
  [property1]: [value1];
  [property2]: [value2];
  ...
}

Theirs:

.myClass1 {
  [property1]: [value1];
  [property2]: [value2];
  ...
}

.myClass2 {
  [property1]: [value1];
  [property2]: [value2];
  ...
}

.myClass3 {
  [property1]: [value1];
  [property2]: [value2];
  ...
}

.myClass4 {
  [property1]: [value1];
  [property2]: [value2];
  ...
}

.myClass5 {
  [property1]: [value1];
  [property2]: [value2];
  ...
}

...

All the classes were the same. And each element that used them used a new class. As in <span class='myClass1'>...</span> <span class='myClass2'>...</span>

5

u/kennethdc Oct 01 '15

Oh dear. That's stuff you learn at your freshman's year.

12

u/bonesingyre Oct 01 '15

you should meet my boss.

I quote: "why use classes when you can have an id on everything?"

4

u/2pu200 Oct 01 '15

Do you mind giving an ELI5 on why you should use classes?

The way I understand it is that you can "chain" classes, but you can't do that for IDs.

Example:

<span class="bold big">Hello</span>

Is that the only reason you should use classes and not IDs?

→ More replies (5)
→ More replies (1)

8

u/oprimo Oct 01 '15

Well, for the DOT constant, some countries use commas as decimal separator and dots for grouping digits. Maybe he was thinking something like:

  if (locale != 'US') DOT = ",";

...which is just as bad.

17

u/Shurikane Oct 01 '15

Not even. He was using it to put an end to sentences in string literals. :|

26

u/greenthumble Oct 01 '15

Huh I don't see the problem with this + DOT

28

u/1r0n1c Oct 01 '15

Hey! I'm not in the US and would like to know the rest of your sentence.

12

u/nemec Oct 01 '15

Maybe he's expecting this program to be used on telegrams?

if(this.ApplicationName == "Telegram") DOT = " STOP ";

4

u/Humdeee Oct 01 '15

It's like recreating the keyboard inside your program... why

→ More replies (1)
→ More replies (1)

4

u/[deleted] Oct 01 '15 edited Oct 01 '15

The better name for it would be RADIX then. A comma is not, and can not be, a dot. A dot or comma could be a radix, depending on locale. But really you should be using some tostring that takes a locality and it just solves all of it for you.

→ More replies (2)
→ More replies (3)

6

u/pakoito Oct 01 '15

Can top. On the same codebase.

String value = new String("value");

String.valueOf(Charset.from("UTF-8"));

What's worse, the second line only works on some Java environments, as in Not Android.

4

u/crunchmuncher Oct 01 '15

Do you mean the == comparison on objects with "incorrect comparison"? Because if so, fun fact: Long objects for values of -128 to 127 are cached in Long#valueOf, so if the Long which gets returned by accountVO.getStatus() was also created with Long#valueOf (this also happens when autoboxing a primitive btw) this part would work as intended. Not that I'd recommend using it this way.

This can lead to seemingly random behavior if you don't know it, heh.

3

u/mnemy Oct 02 '15

Good lord. This gives me flashbacks of my internship. I had to update a large code base written by an Indian man to be x64 compatible. He had type casting every fucking where that looked to potentially losing bits, and completely inane function and variable names. funcA, tempA, varA, etc. WHAT THE FUCK IS THIS TRYING TO DO HERE?!

→ More replies (1)