I disagree that comments are an indication of messy code. The purpose of comments are to 1) translate low level concepts into higher ones for improved readability and 2) to maintain information in the design process that can’t be represented by the code itself.
Obviously I don’t have to comment mathematical operations, but it makes sense to comment the algebra of how I derived an equation and it’s use in the code. Now, I could refactor that section of code into a function in order to give it a name, but that would make it more difficult to read as the programmer would then have to find the definition of that function somewhere else in the file. It is objectively more spaghetti-like to pull out single-use code into a function rather than just label the block of code with a comment.
I disagree that comments are an indication of messy code. The purpose of comments are to 1) translate low level concepts into higher ones for improved readability and 2) to maintain information in the design process that can’t be represented by the code itself.
Obviously I don’t have to comment mathematical operations, but it makes sense to comment the algebra of how I derived an equation and it’s use in the code. Now, I could refactor that section of code into a function in order to give it a name, but that would make it more difficult to read as the programmer would then have to find the definition of that function somewhere else in the file. It is objectively more spaghetti-like to pull out single-use code into a function rather than just label the block of code with a comment.