Conversation
|
https://en.wikipedia.org/wiki/Structured_programming -> Early exit One "return" at the end of the function or three? In the end we still get one "return" (and the execution algorithm, as described in my version): ps: Creating human-readable code in the age of AI is sheer stupidity. A person describes a task in sentences based on images, not machine codes. No one manually climbs into the matrix of AI coefficients anymore. As a result, all the variants of programming languages created for humans are not needed, as are the programmers themselves, busy translating the task into these outdated languages. |
|
Yeah the resulting machine code is the same, I thought it was just lots more readable. For example, the case If you prefer assigning a variable to have only one return, you could do something like // 2200..3000 mv - 0..100%
_attribute_ram_code_
u8 get_battery_level(u16 battery_mv) {
u8 out;
if (battery_mv >= MAX_VBAT_MV) {
out = 100;
} else if (battery_mv <= MIN_VBAT_MV) {
out = 0;
} else {
// Keep the /100 in the denominator to avoid an u16 overflow
out = (battery_mv - MIN_VBAT_MV) / ((MAX_VBAT_MV - MIN_VBAT_MV) / 100);
}
return out;
}Anyway, feel free to close if you don't like it. |
|
FWIW I feel @nschloe is clearer and does not suffer from a steady marching on the right, which makes it harder to read. Of course if the point is to make code better for the machine we would just write assembly or generate it from high-level specifications.
Wikipedia actually says for most of that section that the early exit exception is useful, except when you have to do rollbacks, and is case there is nothing to undo on return.
This is the most depressing statement I've read in a while about programming
This was the slogan of COBOL, Visual Basic, "no code" tools... yet we're still discussing on GitHub |
Modern computers are equipped with completely different monitors, not entry-level CRT-based ones with a display of up to 80 characters per line. Some languages use a top-to-bottom, columnar writing order.
You are talking about programming languages created for humans, not for machines. They didn’t take root because they had the same views as you - To force everyone into a framework and limit freedom. PS: Who's stopping you from creating your own repository and writing code there the way you like? |
No description provided.