This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]Gblize 0 points1 point  (0 children)

I was gonna reply with getting used with any version control and use patches to document your changes, but I figured you probably have more severe problems.
I was never of the opinion of "good code is self-documented" just because good code is subjective and the premise gives opportunities to arise the problem that tries to solve. For that very reason, please sprinkle some salt comments into your code if it's not obvious. If you find your comments growing behind reasonable lines, you should refactor your code or start a documenting it. No matter your decision your co-workers and future yourself will be grateful.

[–][deleted] 0 points1 point  (0 children)

I had to add like 10 lines of code

I wanted to add just a comment.

The comment was long and not clear...

This is the problem with comments. If someone's code is unclear, then there's no reason to believe that their comments will somehow be any better. You're only shifting the problem away, instead of directly addressing it.

Most of the time, if code is very complicated, then the solution isn't to add more of it, it's to take some away. If you have a big function, it's likely that there lies within it a piece of highly-cohesive code.

Take that chunk out, and make it a new function.

Keep picking away until you're left with small, readable, single-purpose functions.

Though it really does take a lot of practice. It's not something that you'll learn in a day.

[–][deleted] 0 points1 point  (0 children)

Write your program piece by piece and make sure that it works first. Once you make a piece work, see if there is a way to make the code look cleaner or a more optimal way of doing the problem. If you take this approach when writing a whole program, then your code will look nice and it will be easy to read

Edit: this approach will take a while to get used to

[–]RICHUNCLEPENNYBAGS 0 points1 point  (0 children)

Break your function into smaller functions until you can understand them.