Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - My 1st stupid question...

Reply to topic
Author Message
  • Joined: 03 Sep 2007
  • Posts: 352
  • Location: Canada
Reply with quote
My 1st stupid question...
Post Posted: Thu Jul 27, 2000 2:46 am
Er... My book does'nt (yet) explain to me why when we use the " { " braces the next statements have to be a few spaces to the right (& when using " } " the next ones have to be a few spaces left). I think it's just to keep the source readable (easy to folow & debugg?) but I just whant to make sure... If it's not for astetics purposes then, could someone explain it to me? *please*

Thank you.
  View user's profile Send private message
  • Site Admin
  • Joined: 25 Oct 1999
  • Posts: 2029
  • Location: Monterey, California
Reply with quote
Post Posted: Thu Jul 27, 2000 3:11 am
Quote
> Er... My book does'nt (yet) explain to me why when we use the " { " braces the next statements have to be a few spaces to the right (& when using " } " the next ones have to be a few spaces left). I think it's just to keep the source readable (easy to folow & debugg?) but I just whant to make sure... If it's not for astetics purposes then, could someone explain it to me? *please*

See why I don't like the book? It should have explained up front that spacing and formatting is entirely up to your own discression.

You never have to do it, I do it to keep it readable (I even do my html that way). When you get several nested loops or conditionals, it can be a bit confusing to decode in your mind which parts are nested and which are not. With visual cues like this (and contextual coloring in some IDE's) you can more quickly navigate your code by 'gestalt' (err...) without investing conscious thought that should be spent analyzing the problem, writing code, etc...

It's also handy because it helps you make sure you have a matching } for every {, and it's in the right place (like when you leave one off, the compiler doesn't say "Error: Missing '}'" most of the time, but gives a string of 'errors' that don't directly relate to the real mistake you made.)

I break the rules when I think it's more readable and when I think the extra white space would be needlessly wasteful:

if(argc < 2) {printf("Usage: filezoik [filename]
"; return 0;}

  View user's profile Send private message Visit poster's website
  • Joined: 29 Jun 1999
  • Posts: 68
  • Location: Houston TX
Reply with quote
Post Posted: Thu Jul 27, 2000 4:14 pm



Quote
> I break the rules when I think it's more readable and when I think the extra white space would be needlessly wasteful:
>
> if(argc < 2) {printf("Usage: filezoik [filename]
"; return 0;}
>


Strictly following rules like this can make code very easy to work with (especially years later). I have code that I wrote over three years ago that I can still modify and understand.
A little time now, save a bunch of time later....

* Kokopeli:
* ...when he left, the crops were plentiful and all the women were pregnant.
  View user's profile Send private message Visit poster's website
  • Joined: 03 Sep 2007
  • Posts: 352
  • Location: Canada
Reply with quote
Post Posted: Thu Jul 27, 2000 9:38 pm
Quote
> > I break the rules when I think it's more readable and when I think the extra white space would be needlessly wasteful:
> >
> > if(argc < 2) {printf("Usage: filezoik [filename]
"; return 0;}
> >


> Strictly following rules like this can make code very easy to work with (especially years later). I have code that I wrote over three years ago that I can still modify and understand.
> A little time now, save a bunch of time later....

> * Kokopeli:
> * ...when he left, the crops were plentiful and all the women were pregnant.

Thanks guys ;)

Er... Kokopeli, the flute guy?
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!