belle icon indicating copy to clipboard operation
belle copied to clipboard

Suggest use of clang-format

Open WolfgangVogl opened this issue 6 years ago • 4 comments

It's hard to comply to the coding style, a clang-format file would help at some points:

The "nearest" style actually seems something like

Language: Cpp
BasedOnStyle: Mozilla
AlignAfterOpenBracket: DontAlign
AlignOperands: false
AlignTrailingComments: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
  AfterClass: true
  AfterControlStatement: true
  AfterFunction: true
  AfterNamespace: true
  AfterStruct: true
  BeforeCatch: true
  BeforeElse: true
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
ColumnLimit: 0
Cpp11BracedListStyle: true
MaxEmptyLinesToKeep: 1
SortIncludes: false

(Used whatstyle to analyze).

What do you think about adding some reasonable style format?

WolfgangVogl avatar Dec 05 '18 12:12 WolfgangVogl

The current formatting style is quite consistent with itself. When in doubt, looking at the surrounding code and similar sections should help to clarify things. Although, having a format spec would ease code reviews, so I'll have a look.

What do you specifically find unreasonable regarding the current formatting style?

octobanana avatar Dec 06 '18 21:12 octobanana

Yes, you're right. The formatting is consistent with itself - sorry for the bad explanation/misleading topic. My problem was that I HAVE TO look at the surrounding code to adapt a foreign code style instead of just write code and let a (formatting) tool do it's job.

Just as an example: When do you write spaces with curly braces initializions? => std::string index_file {"index.html"}; You've to find another place with this kind of initializion... some people write std::string index_file { "index.html" }; or std::string index_file{"index.html"}; or std::string index_file{ "index.html" }; Thats annoying extra work with big chance of doing styling wrong.

I couldn't tell you which form of the above example I would write intuitively as I don't really care - I think thats the job of a formatting tool.

WolfgangVogl avatar Dec 07 '18 07:12 WolfgangVogl

I can see how a formatter would make things easier. I haven't had a chance to try out clang-format yet, but I still plan on checking it out.

Interestingly, the example you provided for how spaces are formatted with uniform initialization syntax, has the following surrounding lines:

// the public directory for serving static files
std::string public_dir {};

// default index filename for the public directory
std::string index_file {"index.html"};

// socket timeout
std::chrono::seconds timeout {10};

// serve static files from public directory
bool http_static {true};

// serve dynamic content
bool http_dynamic {true};

// upgrade http to websocket connection
bool websocket {true};

octobanana avatar Dec 11 '18 10:12 octobanana

It was just an proposal and the example was the first that passed through my mind.

"I couldn't tell you which form of the above example I would write intuitively".

WolfgangVogl avatar Dec 11 '18 12:12 WolfgangVogl