[pulseaudio-discuss] Coding style question regarding curly braces
Colin Guthrie
gmane at colin.guthr.ie
Thu Jan 20 08:30:26 PST 2011
'Twas brillig, and Arun Raghavan at 20/01/11 14:34 did gyre and gimble:
> On Thu, 2011-01-20 at 15:03 +0200, Tanu Kaskinen wrote:
>> Hi,
>>
>> When reviewing code, should I complain about excessive curly brackets in
>> code like this?
>>
>> if (foo) {
>> bar = 0;
>> }
>>
>> Pulseaudio source code follows quite consistently the unwritten rule
>> that you shouldn't use curly braces unless necessary, so I was surprised
>> to notice that the unwritten rule was really unwritten (ie. not
>> mentioned in http://pulseaudio.org/wiki/CodingStyle). So, should I add
>> the rule to that page, or should I stop caring about this?
>
> I vote for making the convention explicit, but then I'm biased since I
> prefer not putting braces around one-line conditionals. :)
My own personal taste is to only use braces when needed but if one part
of a logical block (if,else if,else) needs braces, then they should all
get them.
But Lennart always says he prefers "compact code" so the general rule is
to not use them unless needed.
This policy has led to at least one bug (in rtp stuff) related to an
else being matched against the wrong if, but the only policy that would
have mitigated that would be "always use braces" anyway, which at least
Lennart, Arun and myself don't like as a general rule.
So I would say: chuck a comment in on the CodingStyle page about
avoiding braces when possible, as per Lennart's general taste!
Col
--
Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/
Day Job:
Tribalogic Limited [http://www.tribalogic.net/]
Open Source:
Mageia Contributor [http://www.mageia.org/]
PulseAudio Hacker [http://www.pulseaudio.org/]
Trac Hacker [http://trac.edgewall.org/]
More information about the pulseaudio-discuss
mailing list