Skip to main content
copy-edited
Source Link
Deduplicator
  • 9.1k
  • 5
  • 33
  • 52

Your alternatives are not as bad as you may think. Good code should:

  1. Clearly indicate with good variable names / comments under what conditions the loop should be terminated. (The breaking condition should not be hidden)

  2. Clearly indicate what is the order of doing operations. This is where putting the optional 3rd operation ( DoSomethingElseTo(input)DoSomethingElseTo(input) ) inside the if is a good idea.

That said, it is easy to let perfectionist, brass-polishing instincts consume a lot of time. I would just tweak the if as mentioned above; comment the code and move on.

Your alternatives are not as bad as you may think. Good code should:

  1. Clearly indicate with good variable names / comments under what conditions the loop should be terminated. (The breaking condition should not be hidden)

  2. Clearly indicate what is the order of doing operations. This is where putting the optional 3rd operation ( DoSomethingElseTo(input) ) inside the if is a good idea.

That said, it is easy to let perfectionist, brass-polishing instincts consume a lot of time. I would just tweak the if as mentioned above; comment the code and move on.

Your alternatives are not as bad as you may think. Good code should:

  1. Clearly indicate with good variable names / comments under what conditions the loop should be terminated. (The breaking condition should not be hidden)

  2. Clearly indicate what is the order of doing operations. This is where putting the optional 3rd operation ( DoSomethingElseTo(input) ) inside the if is a good idea.

That said, it is easy to let perfectionist, brass-polishing instincts consume a lot of time. I would just tweak the if as mentioned above; comment the code and move on.

Source Link
Pat
  • 1.6k
  • 1
  • 15
  • 12

Your alternatives are not as bad as you may think. Good code should:

  1. Clearly indicate with good variable names / comments under what conditions the loop should be terminated. (The breaking condition should not be hidden)

  2. Clearly indicate what is the order of doing operations. This is where putting the optional 3rd operation ( DoSomethingElseTo(input) ) inside the if is a good idea.

That said, it is easy to let perfectionist, brass-polishing instincts consume a lot of time. I would just tweak the if as mentioned above; comment the code and move on.