Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Code Style for CDT code



On Tue, Jan 27, 2015 at 5:08 AM, Alena Laskavaia <elaskavaia.cdt@xxxxxxxxx> wrote:
Sorry to bring this up again, but I want to discuss this on cdt-dev.
Marc yet again -1'ed my commit because of code style, specifically because not surrounding
a single statement with braces within if operator. First of all I don't remember agreeing on any sort of code style like that (see cdt process and code style wiki), second of all I strongly disagree with this specific one. Coding style like that was created I think 20 years ago where people were
formatting code manually. Today everybody who works on cdt code should use auto-formatter.

Strongly disagree. JDT formatter is buggy and is being rewritten as part of https://bugs.eclipse.org/bugs/show_bug.cgi?id=303519

This should be the rule, not braces.

Formatter doesn't insert or remove braces, so it is suitable no normalize style related to them. For braces I propose the following rules:
1. Braces are mandatory in 'for', 'while' and in 'if-else'. Both branches of 'if-else' should have braces. 
2. In a simple 'if' without 'else' braces are optional if the body of the branch, including comments if present, occupies a single line.
 
Adding more braces actually clutters the code leading to lesser readability, and it affects all code not just "we had a case 10 years ago when somebody formatted code manually and it led to a bug".

Adding braces doesn't clutter code since it provides moderate visual separation between control statements.
 
I also strongly disagree with using code style with right side comparison like (null == a). This was created again to mitigate bad gramma of C language and it has no value in Java. It greatly impairs readability because it is not a natural order of english language, so people even they understand it eventually will had hard time reading these expressions.

Agree with that. 

Would be nice if we can actually agree of code formatting style so we can add this to our save actions, so then we don't have waste time dealing with code style and formatting on the reviews.
Note if majority of committers will agree on certain style, even I personally disagree with it I will follow it.

Not until JDT formatter starts producing satisfactory results in 100% cases.

-sergey 

_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/cdt-dev


Back to the top