Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

75%
+4 −0
Q&A Is omitting braces for single statements bad practice?

I'm in the "Use the braces. Just use them every time" camp [1]. As others have suggested you or your tooling will catch a lot of cases where you screw up on this, but the ones that slip through can...

posted 4y ago by dmckee‭  ·  edited 4y ago by dmckee‭

Answer
#2: Post edited by user avatar dmckee‭ · 2020-11-08T17:27:36Z (about 4 years ago)
#1: Initial revision by user avatar dmckee‭ · 2020-11-08T17:25:58Z (about 4 years ago)
I'm in the *"Use the braces. Just use them every time"* camp [^1]. As others have suggested you or your tooling will catch a lot of cases where you screw up on this, but the ones that slip through can really hurt.

So, I was surprised to hear [Robert "Uncle Bob" Martin](https://en.wikipedia.org/wiki/Robert_C._Martin) opine that [he's *"on a mission to destroy all braces"* (video link, but to the quote)](https://youtu.be/58jGpV2Cg50?t=4513).

Now it was clear from the context that his preference is to get all the `while` statements into a form like
```
while ( someClearlyNamedCondition() )
    takeClearlyNamedAction();
```
and similarly for `if`, so that there is never a need to have more than one line following the condition (changes to the named action should be made in `takeClearlyNamedAction()`, right?) and the code can be read aloud without ambiguity or difficulty.

Making that work is going to take some serious dedication to clean code and refactoring as you go, but elsewhere in the video series, Uncle Bob talks about the importance that he sees in adopting a discipline in your coding (he has TDD in particular in mind and gives an enlightening demonstration of how he goes about that).


[^1]: This is a change for me and one that has been slow in coming. I'm old enough to have done most of my formative programming in terminals with a severely limited number of lines (hey but at least they were CRTs: many of the people I learned *from* had learned on punch cards and line printers). For a long time I was a proponent of formatting decisions that saved vertical space ([1TBS](https://en.wikipedia.org/wiki/Indentation_style#Variant:_1TBS_(OTBS)), leaving off unnecessary brackets, and so on). Even then I would sometimes print code so that I could examine it in the large.