Liste des Groupes | Revenir à cl c |
On 2024-09-22, David Brown <david.brown@hesbynett.no> wrote:So, everyone has to write code exactly to the C standard.I am not suggesting overuse of braces. I am suggesting /good/ use of them.My super advanced text editor from the future isn't letting me do that:
>
<https://www.synopsys.com/blogs/software-security/understanding-apple-goto-fail-vulnerability-2.html>
>
That's perhaps the most famous example of the havoc caused by omitting
useful braces.
>
Consistency and clarity is important. So is maintainability. Suppose,
for example, you want to add a line "attempts++;" alongside the "ok++;"
line. When the braces are there, the change is exactly that - add the
new line you want. Without the original braces, you are now making
changes to the structural syntax of the code as well when you add in
original braces - or you are making a mistake in the code.
if (failed)
WARN("failed because...");
else
ok++;
attempts++; // automatic deindent
When I add a line after ok++, it deindents it to be at the same
indentation level as the if, before letting me type any content into it.
OK, I lied about the super advanced from the future. It's just Vim.
Also GCC has been able to diagnose misleading indentation for some
years now.
Between those two, there is nothing to worry about; just concentrate on
whether it looks prettier without the braces or with.
Les messages affichés proviennent d'usenet.