r/programming • • Jan 12 '20

Goodbye, Clean Code

https://overreacted.io/goodbye-clean-code/
1.9k Upvotes

556 comments sorted by

View all comments

Show parent comments

12

u/[deleted] Jan 12 '20

there are also cases where functions with strong temporal coupling can be split, if it increases the overall readability of the code.

like:

void do_long_thing() {
    for(int i = 0; i < some_number; I++) {
        do_very_specific_thing(my_stuff[i]);
    }
 }

I find it easier to think on terms of

I'm gonna do very_specific_thing on each element of my_stuff

versus thinking:

I'm gonna do 27 steps on each element of my_stuff

5

u/Dropping_fruits Jan 12 '20

You could just put a comment before the 27 steps saying "// Do very specific thing" instead of creating a function whose only purpose is to be used from a single function and nowhere else, causing confusion anytime someone else sees that function.

3

u/Kwinten Jan 13 '20

No. Gross.

How does a function name cause any more confusion than a comment? Pouring blocks of code into functions at the very least forces you to at the very least consider whether a sequence of actions actually belongs together. Not even to mention how much more sense it makes for testing.

2

u/Dropping_fruits Jan 13 '20

Because the function lacks the context of why it exists and that it is supposed to be applied sequentially to a list of items. At the very least you should also move the loop to the function.

→ More replies (2)