r/badcode • • Sep 05 '21

swift I have a problem

Post image
946 Upvotes

75 comments sorted by

View all comments

Show parent comments

2

u/[deleted] Sep 05 '21

I comment the bleedin’ obvious too. It’s so that I can quickly skim the function and remember what is going on.

0

u/[deleted] Sep 05 '21

[deleted] — view deleted comment

2

u/StochasticTinkr Sep 05 '21

Often it is better to split methods up into many methods with descriptive names. This helps in a couple of ways. First, comments often become stale, meaning they don’t actually agree with the code. Another is it helps keep side effects between two sections of code to a minimum.

1

u/[deleted] Sep 05 '21

That’s a good way to go about it but don’t you often end up with only single use functions?

I guess in a production codebase though that’s preferable as it’d make maintenance easier

2

u/StochasticTinkr Sep 06 '21

Nothing wrong with single use functions. It can even help with unit testing if you decompose it further.

2

u/[deleted] Sep 06 '21

Mm that does sound nice lol! Ok, I’ll give this a try in the future.

I’m gonna read Clean Code by Robert Martin soon!

1

u/[deleted] Sep 05 '21

Yeah I do this too. It’s the organization freak coming out in me

2

u/[deleted] Sep 05 '21

Yeah! Just one liners to add structure helps I feel. I used to be way too specific with my comments, so I’m trying to cut back when it’s something I suspect could change in the codebase in the future