Mr. Conway disagrees with some of my college professors again. He says that it is not useful to abuse loop constructs just to consolidate control in a single location. He is a hero for this stance.
In college, many of the instructors hated any loop or function that had more than one exit point. They railed about the evilness of this, and, worse, marked points off your assignments for it. They simply said It Is Bad, and that it is required to write correct code.
Problem is, they would wind up writing hugely distorted blocks of code with massively complex conditionals just to avoid having a “break” or “continue” in a loop. The infinite loop – the handy while(1) { … } – was verboten as there was in their minds no way out.
Writing a loop with simple conditions, and clear paths out of the loop is, in my mind, far superior to writing one complex conditional with additional logic smeared through the body of the loop.
As usual, the book provides enlightening examples which I will not duplicate here.
Your professors were correct: that sort of code is evil.
… when you are trying to make a formal proof for it, that is.
Not so much when you are trying to make it readable and bug-free.
[…] fact, the example provided for Distributed Control was one such place. The addition of a single word in the example code made it clearer what was […]