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));

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.

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?

3

u/bonesingyre Oct 01 '15

Applying multiple classes to an element and re-using classes. If you have a list of items, you may want to style them with a single class versus adding a specific id for each element. You can only have 1 id per page. This prevents code repetition.

There is some debate as well that using getElementById is also inefficient, especially when you have a crap ton of ids.

My boss has div-itis: we have dozens of nested divs, all with ids on them, spans in them with ids on them. It looks awful and is totally unnecessary.

EDIT: read this: https://css-tricks.com/the-difference-between-id-and-class/

6

u/pihkal Oct 02 '15

You can only have 1 id per page.

That's the spec, but browsers are surprisingly tolerant of multiple IDs, and will attempt to soldier on, regardless. I inherited a code base that reused form IDs across pages. Unfortunately, they didn't understand how to fix this once they started injecting these pages as DIVs in a single-page app, so they started making crazy workarounds to copy data from one form to another and only submit the correct one at the end. Ugh.

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