+ 1

How do you format curly braces?

How do you format curly braces when writing code in C++ or any other programming language that uses curly braces this way? https://sololearn.com/compiler-playground/c3nvsNT4CImI/?ref=app Like that? (1) https://sololearn.com/compiler-playground/cF3Ul3hUUtqT/?ref=app Or like that? (2)

15th Jan 2025, 6:50 AM
MattMad
MattMad - avatar
2 Respuestas
+ 3
My personal preference is option 1. When writing code within a team I follow the style used by the company. Sometimes I work on legacy code that used a different style than newer code. Then I will adapt to match the older style in the legacy code. In my opinion consistency and uniformity are what make code readable more-so than any specific style.
15th Jan 2025, 7:25 AM
Brian
Brian - avatar
+ 3
I also use style 1 for my own code. And many text editors which have "code completion" feature will also use style 1. Style 2 adds too many wasted lines which results in lot more scrolling unless you are using a text editor with "code collapse" feature. But as mentioned, you will want to match style to what already there when maintaining/updating existing code.
15th Jan 2025, 7:41 AM
Shardis Wolfe