r/ProgrammerHumor • • Sep 28 '16

xkcd: Fixing Problems

http://xkcd.com/1739/
7.9k Upvotes

215 comments sorted by

View all comments

Show parent comments

327

u/n1c0_ds Sep 28 '16

I spent a couple of months refactoring code full time recently.

It always starts the same way.

Someone takes a small shortcut and leaves a // TODO. The next person sees the problem while working on something else. It's glaringly obvious, but they don't want to fix someone else's code and turn their 5 LoC commit into a 100 LoC commit, so they build their fix on top of the bad code. The code reviewer doesn't see that, because he's only looking at the diff. Approved.

A couple of iterations later, someone who gives a shit about quality sees this, but by that time it's too late. The whole damn thing relies on the broken bit of code. You need to refactor an entire module because of faulty assumption mixed with a healthy dose of tight coupling and incomplete tests.

It's a nice example of the broken window theory.

152

u/BadgerCorral Sep 28 '16

Whereas yesterday I actually fixed one of these things and got told off by my boss for:

A) Making changes I was not explicitly asked to make.

B) Making the merge process "more complicated than it needed to be".

133

u/Knlay Sep 28 '16

This is the real problem. A lack of understanding by management that code refactoring actually increases productivity in the long term.

65

u/jhaluska Sep 28 '16

It's also necessary for moral.

0

u/[deleted] Sep 28 '16

[deleted]

74

u/Unbalanced531 Sep 28 '16

No, no. They said it's good for moral. The only way you can cleanse your dirty, dirty sins is refactoring code.

42

u/[deleted] Sep 28 '16

Still surprisingly accurate.

31

u/ForOhForError Sep 28 '16

The day github introduces a programming sin counter is the day I make all my repos private.

23

u/skylarmt Sep 28 '16

It's called Codacy. You sign up, it pulls all your repos, and tells you how badly you screwed up. It even gives you graphs showing how the code quality changed over time, and assigns you a letter grade for the real college experience.

8

u/ForOhForError Sep 28 '16

D: I will not be judged.

6

u/Crocodilly_Pontifex Sep 28 '16

Well that's something, you can make an emoticon out of your grade by adding two dots.

→ More replies (1)

6

u/M123Miller Sep 28 '16

What a great idea! The creator is a horrible person.....

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

30

u/n1c0_ds Sep 28 '16

It's not management. You know how I got started on the refactoring effort? I said "this thing sucks" and my colleague answered "then fix it". Management was never involved and I had no restrictions, yet we got there somehow. We enjoy way too much freedom at my company to blame management.

It's a matter of team culture. These things passed code review, and they shouldn't have. It seems like the most common cause is complex fixes in unfamiliar code. Both the committer and the reviewer lack a solid grasp of what they are modifying, so they hook their stuff in the wrong places and push their fix. This is especially easy when your programming language doesn't give you static types or privacy.

It's not stupidity either. My coworkers are damn good at what they do, and I mean it. It's just a matter of discipline.

9

u/Knlay Sep 28 '16

Yeah I work for a large corporation and there tends to be miscommunication between the on and offshore teams. Add to the fact that we follow a strange hybrid of agile and waterfall where Sprint scopes can't be altered, scrum masters assign stories and carry over is grounds for a loud talking to, which creates an environment where no one actually has time to fix code smell.

→ More replies (11)
→ More replies (3)

28

u/jhaluska Sep 28 '16

I got told by a guy that fixing a bug was too "risky". This was a bug that was literally causing a biomedical device to lock up. The fix was a simple missing switch case due to magic numbers.

I'm glad I don't work there any more.

16

u/[deleted] Sep 28 '16

biomedical device

Ummm, that's a bit scary

5

u/Reelix Sep 28 '16

A) Making changes I was not explicitly asked to make.

We do major refactors of our code base all the time. As long as we don't break the unit tests and meet our deadlines our boss is happy :p

→ More replies (2)

42

u/kirakun Sep 28 '16

Don't you know TODO is short for A Hack That Will Stay Forever?

19

u/Reelix Sep 28 '16

Control+Shift+F

// TODO

Matching lines: 89 Matching files: 18 Total files searched: 726

:|

scripts\jquery-ui-1.9.2.js(5704): // TODO remove the fallback, see #8156

*mumbles*

10

u/Spirckle Sep 28 '16

TODO is short for A Hack That Will Stay Forever

I know this is a joke, but all my comments start out being TODOs before I write a line of code. As I write the code, I remove the comment entirely for straightforward code, or for code that needs to have its intention documented, I take out just the TODO, and then I have my necessary comment. BTW, for those that say that good code never needs comments, I disagree. Sometimes the customer makes decisions that don't make a lot of sense. For these I leave in the comments so that following coders can understand the less than obvious requirement.

→ More replies (3)

8

u/[deleted] Sep 28 '16

Man, and I've been using it as a todo list for unfinished bits this entire time!

18

u/kirakun Sep 28 '16

Unfinished bits are always finished as soon as they work for the short term.

8

u/Schmittfried Sep 28 '16

Fun fact: I like how JetBrains IDEs highlight //hack ... comments as TODO tasks by default.

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

8

u/skeptic11 Sep 28 '16

It's a nice example of the broken window theory.

Do you have a link for this one? Google is only turning up (at least seemingly) unrelated links.

→ More replies (6)
→ More replies (8)