[Solved] Where should we put the opening brace of a class in 1TBS style? [closed]


There is unlikely to be an objective answer to this, as both the K&R and 1TBS styles emerged in the context of the C programming language, where there were no class definitions.

Since derivative languages of C that support classes (e.g., C++, Java, etc.) share most of the syntax, it is only natural that the brace-style conventions that emerged for C would be used in and adapted for these derived languages. But they would be precisely that—derivations and adaptations. This is why the Wikipedia article mentions “Java” as a “variant” of the K&R style.

There is no right place or wrong place to put the opening brace for a class definition, even when following K&R or 1TBS styles, since classes aren’t part of either of those two styles. Inevitably, you’ll be following some variant of those original styles that includes a convention for class definitions, and, in a variant, any convention you choose is valid.

Ultimately, it matters not. Write the code in the way you think is readable (if you’re writing it from scratch) or in the way that conforms to the other existing code files in the project. Conventions are merely that: conventions. There’s no objective answer, and it doesn’t matter.

1

solved Where should we put the opening brace of a class in 1TBS style? [closed]