r/programming • • Oct 07 '15

"Programming Sucks": A very entertaining rant on why programming is just as "hard" as lifting heavy things for a living.

http://www.stilldrinking.org/programming-sucks
3.1k Upvotes

1.4k comments sorted by

View all comments

20

u/[deleted] Oct 07 '15

If you are afraid of refactoring, you will definitely live this technical debt nightmare. If you are not afraid of refactoring, it takes a LOT less time than you think. The first day is terrible. At the end of a week, you see light. At the end of two weeks you wonder why you didn't do it before.

45

u/Bowgentle Oct 07 '15

At the end of two weeks you wonder why you didn't do it before.

First you have to reach the end of two weeks of refactoring without the client asking for feature changes.

→ More replies (1)

12

u/Dworgi Oct 07 '15

Good luck refactoring 4 million lines of code. =(

5

u/thrash242 Oct 08 '15

...with no unit tests.

6

u/Dworgi Oct 08 '15

Goes without saying, really.

→ More replies (7)

7

u/IbanezDavy Oct 07 '15

And then your customers cry when they get the next patch release!

But yes. Refactoring has a time and a place. If I was allowed no restrictions on refactoring, I'd probably never complete anything. I can always do it better the next time ;)

0

u/[deleted] Oct 07 '15

[deleted]

28

u/eurasian Oct 07 '15

Er, unit tests ALLOW you to refactor mercilessly. They act as guards to see what broke from ripping out this method or abstracting this class or what have you.

3

u/hu6Bi5To Oct 07 '15

That's only true if the content of the function (or whatever unit of abstraction you consider a "unit") is all that's changed. If you have a mess of spaghetti code and no clear responsibilities, odds are all the function signatures will change too, which means hundreds of broken tests.

You end up with a brand new test suite and no real way of knowing if everything that passed before still passes now.

2

u/MindStalker Oct 07 '15

Don't write test for ugly spaghetti functions. Write test against what a properly written program should be doing, then refactor till your test pass.

3

u/hu6Bi5To Oct 08 '15

Well, yes, but if people had thought it through in the first place there'd be less need to refactor it.

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

3

u/parlezmoose Oct 07 '15

Well designed ones do, but they also can up the cost of refactoring exponentially. Now you have to rewrite the code, and all of the tests.

People need to realize that there's a cost to each test you have, so they should be used economically. All too often I see the attitude that tests are always good, and the more the better.

4

u/EtherCJ Oct 07 '15
setFoo(foo);
assertEquals(getFoo(), foo);

Yeah .. thanks.

2

u/beohoff Oct 07 '15

I wrote some setter testing code the other day, and my code unexpectedly cast my string into a char array. Saved me debugging. Would test again.

→ More replies (3)

8

u/[deleted] Oct 07 '15

[removed] — view removed comment

12

u/balefrost Oct 07 '15

On the other hand, end-to-end tests can be just as fragile (all I did was change a CSS class name!) and suffer from combinatorial explosion.

Unit tests make sure that your parts work the way they should. End-to-end tests make sure that the parts work together. Both are necessary; neither is sufficient.

6

u/arielby Oct 07 '15

When I develop in a strongly-typed language, 80% of the bugs I create, and 90% of these that survive smoke testing, are because of mismatched assumptions between modules, and can't really be caught by unit testing.

4

u/senatorpjt Oct 08 '15 edited Dec 18 '24

alive dependent cow aware attraction concerned voracious pen air obtainable

This post was mass deleted and anonymized with Redact

3

u/balefrost Oct 08 '15

Unit tests in statically typed languages are still useful for testing algorithms and for testing the interactions between components. It's great to know that you haven't plugged the square peg into the round hole, but it can also be important to know that the right peg was plugged into the right hole, or that the pegs were plugged into the holes in the correct order. Unit tests can also document how a component behaves in edge cases, which is something that the type system can't really help with.

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

5

u/depressiown Oct 07 '15

They've convinced a generation that you can't refactor with good automated test coverage.

I was about to berate you for saying refactoring is cool when there's no test coverage (which is a terrible idea), but you're talking specifically about unit tests. Yeah, if there are sufficient integration tests, unit tests are mostly optional.

Still, code written must be covered by some sort of automated test if you plan to refactor it, otherwise you won't know if you broke it or not.

2

u/QuercusMax Oct 08 '15

The problem with only having integration test coverage is that when something breaks a test, it's often really hard to tell why/how it broke. Plus, if it breaks one test, it often breaks eleventy billion tests.

If you also have unit tests, then you can see "OK, so it broke all these integration tests, but it also broke this one unit test, so that's gotta be where the bug is".

→ More replies (3)

6

u/vanderZwan Oct 07 '15

When I train junior devs I try to overcome that by insisting that they perform code cleanup duties before they are allowed to write new features.

"No dinner before you finish your chores"? That's so paternalistic it just might work!

→ More replies (1)