Sign in to follow this  

Unity if statement in for loop, brackets needed?

This topic is 1797 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

You expect people who dont know how to add a compiler option to get the source of clang and flawlessly compile this and be able to integrate this with libstdc++ from gcc?

Share this post


Link to post
Share on other sites
Let's please move away from the personal attacks, and back to the topic of the merits and drawbacks of coding standards. Thanks.

Share this post


Link to post
Share on other sites

You expect people who dont know how to add a compiler option to get the source of clang and flawlessly compile this and be able to integrate this with libstdc++ from gcc?

I expect vendors to ship the best tool for the job. Clang is already the default compiler on OS X, FreeBSD and MINIX - and I hear of testing against the Debian archives, so Ubuntu may be next.

 

You can't really divorce the discussion of coding standards from the discussion of tools. To my mind there are two types of coding standards:

  • Standards that are purely stylistic (i.e. spaces vs tabs)
  • Standards that work around deficiencies in languages/tools (i.e. brace conventions)

The former you can't really have a meaningful debate on, and the latter are only a concern so long as the tools don't account for it.

Share this post


Link to post
Share on other sites
Aside from the provider of the OS, there are other sources for clang binaries. Ex: on Windows you can use cygwin to get clang.

Share this post


Link to post
Share on other sites

When I started programming in C I gained this obsession for using as few characters as possible. To me if you don't need the braces don't use them. However, not everyone has this philosophy and while I now make a special effort to look at whether braces exist or not before I make a modification I recognise the terrible slip ups that have already been mentioned.

 

For the sake of working when tired or as part of a team it probably is better to included them. More importantly teams should probably have a standards document they all follow such that if they see a single line statement they hopefully remember to change it appropriately.

Share this post


Link to post
Share on other sites
I tell my students to always use braces, because this is the kind of thing that trips them up.

On the other hand, at least in my eyes, the situation where braces and indentation do not match is too obvious to be dangerous. In code that is otherwise properly indented, I can't miss it. Never saw a coworker make that mistake either. I find omitting the braces from one-liners makes the code easier to read and understand. Compare this:
foo();

if(condition)
{
    bar();
}

xyzzy();
with this:
foo();

if(condition)
    bar();

xyzzy();
With braces, the visual distance of every line with text is almost the same. It's harder to see that the two lines in the middle are logically related to each other. The version without braces has the same visual rhythm as if you were reading the logic aloud: "foo, (pause), if condition then bar, (pause), xyzzy."

Share this post


Link to post
Share on other sites

use braces even if it is one statement. you wont think other person reading your code to think less about these little subtle things. it makes it more readable in my opinion

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Similar Content

    • By loyalsheep
      Hey guys!
      Check out the trailer of Airavat. It's a minimalist, space survival game (and hard, very hard) 
      Download on GooglePlay: Airavat
       
    • By anomalystudiospt
      Hey, we are new around here!
      Our team spent the last year developing a prototype game called Rise of The Fey, a game that focuses on a dramatic story with a fast paced gameplay.
      Rise of The Fey is a third-person action-adventure RPG set within a fantasy world called Perrah. In Rise you control Kall, a young spaunian looking for revenge after the death of his beloved.

      We would appreciate if you could take a look at our stuff, tell us what you think and possibly help us out on Indiegogo.
      The prototype is in portuguese, sorry about that!
      Have a good one!
    • By juglar
      Hi guys, we are developing a game called BiteOff! based on Zombies topic. BiteOff! is based on a game strategy mechanics, free to play, where the player has a bunch of zombies and he can distribute them along the map landscape to be able to bite and transform all humans into each level. Humans are controlled by artificial intelligence and they differ each other on capabilities based on different weapons that give them three different levels of aggressiveness to defend against the zombies. The zombies are also presented in three types and they are differentiated by their attack, speed, strength and resistance abilities. Through different achievements, (time to eat all humans, score, among others) the player can access four extra skills that can enhance your attack in real time on next levels as power-ups.
      We are launching a crowdfunding campaign in kickico and we need some helps please visit us on the crowdfunding page https://www.kickico.com/es/campaigns/17824/biteoff-the-videogame 
      Twitter @biteoffthegame
      Facebook
      Clickme!
      Website 
      Clickme!
    • By Lord McMutton
      The world of Ethios is held aloft by massive trees known as the Pillars.
  • Popular Now