What are WET Comments?

Asked

Viewed 202 times

12

What are W.E.T., Python comments? Why are they bad?

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

1 answer

17

It’s not just for Python, it works for any code. The acronym means Write Everything Twice which is opposed to DRY (was chosen so to make a pun with DRY). It’s the obvious comments that say exactly what the code is already saying in a clear and readable way to any programmer.

If you’ve written a simple, obvious code, there’s no point in commenting on what it does. If you can’t do that, redo the code. Comments are to say why you did something not obvious, because there is something there that seems strange, because you had to touch it or where the reference information came from to do that. Comment is not to say what the code does.

total = qtde * valor #calcula o total

I put in the Github for future reference.

Ah go? If I did not have the comment I would never know!

These comments are only acceptable when being didactic in a sample to teach someone how to do it, not for code in production.

Almost every comment violates the code’s DRY and forces you to be aware of it in any change in code.

The WET does not apply only to comments, any real duplication, and which are not equal only by coincidence, should be avoided.

  • Just to complete the great answer: one of the worst problems with comments is that often people don’t update them when they change the code. Then the comments become outdated and lie to the programmer, increasing the time to understand the code.

  • Comments that explain the function and its arguments (e.g. Javadocs) can be considered WET as well, if something is very obvious? Or is it different because this is code documentation? I don’t know if I should ask this question in a new question.

  • 1

    It’s different. But it has similar problem, because if you change the code and not change the doc is chipped. But as it is usually part of the contract, it should not change much, the ideal is never, and if moving should be extra careful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.