Liste des Groupes | Revenir à cl c |
On 09/21/24 1:47 AM, David Brown wrote:To be clear here - many people have strong opinions about this topic, and there is no good evidence for claiming that one style is "better" than other styles. Different styles can have their pros and cons, and people will give different weightings to those pros and cons when choosing a style.>
You should get in the habit of being consistent with braces, and being generous with them. Your future self with thank you.
I am not suggesting overuse of braces. I am suggesting /good/ use of them.>Nope. There's absolutely no reason to overuse braces.
if (failed) {
WARN("failed because...");
} else {
ok++;
}
>
And don't use "Egyptian" braces. The latter is actually an ill-begotten attempt to remedy the damage from the former. Just stop overusing braces, and there'll be no need for the remedy. Easy.No, it makes code longer and more tedious to read, and wastes significant vertical space so that you can see less code at a time. It leads people to think that it is a good idea to skip braces when they can. Put braces in a sensible place and there is no incentive to skip them.
This is the proper formatting style with braces
if (failed)
{
...
}
else
{
...
}
The vertical spacing introduced by the `{` line provides separation between condition and the branch, which makes your code much more readable. It is also a very good location for a comment, if you decide to include one. Your future self with thank you.
That is indeed true. Sometimes when you have code that you need to single-step or debug carefully, you need to express it a little differently or make syntactic changes to help. (A common one is to mark some of the local variables as "volatile".)... is smallNope. Do not ever write single-line `if` statements. This is a major impediment to step-by-step debugging.
enough to fit entirely on a single line, and the statement could not possibly be misinterpreted, use a macro, or have any other non-obvious behaviour.
>
Thus :
>
if (failed) return -1; // Early exit
>
or
>
if (!failed) ok++;
>
Otherwise, put in all the braces.
Les messages affichés proviennent d'usenet.