Consensus on the kdelibs coding style

Cornelius Schumacher schumacher at kde.org
Sat Jul 5 19:01:13 BST 2008


On Saturday 05 July 2008 15:41:23 Lubos Lunak wrote:
>
> ===== Coding style proposal =====
(...)

So in a slightly shortened version you want to change the coding style which 
is on techbase in two aspects:
- not requiring brackets for if statements only containing one line bodies 
(for the reason that you don't understand this rule)
- Putting the opening brackets of code block to an own line (because your 
personal view and that of the Wikipedia author is that it's more readable)

Sounds like a true coding style discussion ;-)

Just for reference the rationale for the two rules:
- When you have if blocks with one-liners which don't have brackets, it can in 
some cases lead to wrong code, if somebody adds an indented line of code, but 
no brackets. It looks right, but us wrong. Additionally when moving around 
code, you might end with dangling brackets, if some code blocks use them and 
some others don't.
- The opening bracket on an extra line violates what McConnell calls the 
Fundamental Theorem of Formatting (It says that good visual layout shows the 
logical structure of the code). The bracket logically belongs to the control 
statement which opens the block. Putting it in the body, but not indenting it 
puts it at a place where it neither belongs to the control structure nor to 
the body. That can be perceived as misleading. Additionally this style 
consumes more vertical space, so that you can see less code on your screen at 
once, which can make it harder to read the code.

That said, there are no clear arguments why to use one or the other variant of 
the style. As far as I know, all studies which research this question show, 
that these variants of coding style don't affect readability.

So I don't think there is much point in discussing the style once again. We 
have a style on techbase, a lot of code follows that, so let's just use that 
and put our energy on something which is more fun and productive.

-- 
Cornelius Schumacher <schumacher at kde.org>




More information about the kde-core-devel mailing list