Ariwor / cpp-shenanigans

Just C++ plays
0 stars 2 forks source link

Include brackets #1

Closed athatheo closed 3 years ago

athatheo commented 3 years ago

Brackets: i) Make the code clearer. ii) Are crucial since if you don't include them, only the first line in the if will be executed.

Ariwor commented 3 years ago

Yeap, I know.

i) I agree ii) Since there is only one statement, I omitted the curly braces. I thought (read?) that this is the cleaner way if there is only one statement.

athatheo commented 3 years ago

Sure thing. You can accept this pull request for a quick fix :)

kongr45gpen commented 3 years ago

It's best practice to NEVER omit curly braces from if statements.

The reasons are 2:

  1. Maintainability. If you want to add a new line later on, you won't have to bother with the braces :)
  2. Security. There have been security bugs in the past because incorrect indentation was used with unbraced conditionals! Check the known goto fail fiasco! https://embeddedgurus.com/barr-code/2014/03/apples-gotofail-ssl-security-bug-was-easily-preventable/