5

Is a common practice to move function's opening brace to next line. How to apply this in class method with astyle (code beautifier)?

example:

// this is an initial C++ code
class Class
{
public:
    static int foo(bool x) {
        if (x) {
            return 42;
        } else {
            return 0;
        }
    }
};

modified version should be:

class Class
{
public:
    static int foo(bool x)
    { // this brace in next line
        if (x) {
            return 42;
        } else {
            return 0;
        }
    }
};

All my attempts working only for global functions.

Mat
  • 202,337
  • 40
  • 393
  • 406
Kokos
  • 442
  • 4
  • 12
  • This is likely related to this issue: http://sourceforge.net/tracker/index.php?func=detail&aid=3259702&group_id=2319&atid=102319 – DRH Apr 06 '12 at 17:07

3 Answers3

2

Both --style=kr / -A3 and --style=linux / -A8 option should apply to class methods as well.

From the docs:

Brackets are broken from namespace, class, and function definitions. Brackets are attached to statements within a function.

gioele
  • 9,748
  • 5
  • 55
  • 80
0

I can confirm that --style=ansi does this in current releases of AStyle (v2.03 here).

DevSolar
  • 67,862
  • 21
  • 134
  • 209
-3

This thing really depends on one's preference and his team's preference. Most IDE's follow the braces that you gave in your first example. They also use colored fillers to point out the starting brace and the endling brace. If you bring your mouse pointer to the ending brace, it will color its starting brace too.

Helper
  • 1
  • 1
  • I would like to downvote your answer, because you it seems you didn't read the question. He didn't ask for an opinion about formatting. But as you are new, you will go on unscathed - for now :-) – Gunther Piez Jan 29 '12 at 11:09