Aquiles:

When you are forced to think recursively you have to think of your base cases, your invariants, your pre and post conditions, and how you get from x[k] -> x[k+1] without violating your contract. Again it encourages deliberate design as opposed to empirical exploration.

A solution here is to think about loop pre-condition, invariant and variant, instead of throwing all loops away to replace them with recursions.

Time ago I have suggested to enhance D contract programming a bit, allowing the invariant {} statement in the middle of loops. Formally this adds nearly nothing over using a nested scope {... assert(...);} but it makes more explicit to the code reader what's in that part of the code, and it guides the mind of the code writer in thinking about invariants. So in the end it seems worth a little enhancement request.

Bye,
bearophile

Reply via email to