Why is it java code indented as BSD KNF Style and C C++ code indented as Allman or BSD style?

Posted by Caffeine on Programmers See other posts from Programmers or by Caffeine
Published on 2012-03-19T08:58:15Z Indexed on 2012/03/19 10:16 UTC
Read the original article Hit count: 288

Filed under:
|
|

I do understand that coding convention is a matter of preference, and that different coding conventions have different subtle advantages or shortcomings, and depending on what one wants, one should choose his/her style. But why is usually Java written where the opening brace is on the same line as the function definition of control statement, and in C or C++ the curly braces have a line of their own?

BSD KNF style

if (data != NULL && res > 0) {
        if (JS_DefineProperty(cx, o, "data",
            STRING_TO_JSVAL(JS_NewStringCopyN(cx, data, res)),
            NULL, NULL, JSPROP_ENUMERATE) != 0) {
                QUEUE_EXCEPTION("Internal error!");
                goto err;
        }
        PQfreemem(data);
} else {
        if (JS_DefineProperty(cx, o, "data", OBJECT_TO_JSVAL(NULL),
            NULL, NULL, JSPROP_ENUMERATE) != 0) {
                QUEUE_EXCEPTION("Internal error!");
                goto err;
        }
}

Allman or BSD Style

if (x == y)
{
    something();
    somethingelse();
}

Courtesy: http://en.wikipedia.org/wiki/Indent_style

© Programmers or respective owner

Related posts about java

Related posts about c++