56
votes
Foreach-loop with break/return vs. while-loop with explicit invariant and post-condition
This is easy.
Almost nothing matters more than clarity to the reader. The first variant I found incredibly simple and clear.
The second 'improved' version, I had to read several times and make sure ...
19
votes
Accepted
Foreach-loop with break/return vs. while-loop with explicit invariant and post-condition
I think for simple loops, such as these, the standard first syntax is much clearer. Some people consider multiple returns confusing or a code smell, but for a piece of code this small, I do not ...
14
votes
What's The Difference Between Imperative, Procedural and Structured Programming?
I am afraid none of the answers given so far capture the core of the concepts very well.
Imperative, procedural and structured are not mutually exclusive properties, they just focus on different ...
9
votes
Foreach-loop with break/return vs. while-loop with explicit invariant and post-condition
int i = 0;
while (i < array.length && array[i] != value)
i++;
return i < array.length;
[…] everything is more obvious and more in a structured-programming way.
Not quite. The ...
8
votes
Is there a good reason not to use a "super class" (an all-encompassing class)
there is only one SPI bus, there will only ever be one SPI bus ... he still made an abstract SPI bus class that he overrides with... the real SPI bus class. It makes zero sense to me - CHollman82
And ...
5
votes
Accepted
Proper program structuring in Python
Refactoring
Lots of people have written tomes and tomes on the subject. Martin Fowler has some good advice. Highly recommend looking through his work, also take a look at Kevlin Henney.
Sprout and ...
2
votes
Foreach-loop with break/return vs. while-loop with explicit invariant and post-condition
The two loops have different semantics:
The first loop simply answers a simple yes/no question:
"Does the array contain the object I'm looking for?"
It does so in the most brief manner possible.
The ...
2
votes
Foreach-loop with break/return vs. while-loop with explicit invariant and post-condition
I'll suggest a third option altogether:
return array.find(value);
There are many different reasons to iterate over an array: Check if a specific value exists, transform the array into another array, ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
structured-programming × 15object-oriented × 2
coding-style × 2
history × 2
loops × 2
procedural × 2
design × 1
php × 1
python × 1
unit-testing × 1
programming-languages × 1
database-design × 1
c × 1
data-structures × 1
code-quality × 1
clean-code × 1
language-design × 1
debugging × 1
search × 1
python-3.x × 1
dry × 1
engineering × 1
lisp × 1
paradigms × 1
control-structures × 1