Indenting and White Space

Another thing that is ignored by the compiler that is very useful for yourself or other programmers is using indenting and white space.

Which of the two pieces of code are easier to read?

int main(){printf(“I’m gonna MOVE!”);motor(0,100);motor(2,100);sleep(5);ao();printf(“I moved!”);}

or

int main()

 {

printf(“I’m gonna MOVE!”);

motor(0,100);

 motor(2,100);

sleep(5);

ao();

printf(“I moved!”);

}

The compiler will compile them both.  In fact, they look the same to the compiler. But do they look the same to you? The  areas that have no characters in them is called white space. By using spaces, tabs, and returns we can make the code easier to read and understand.

some tips:

Make sure that each line that ends with a ; gets its own line, and that you indent the lines

between the ‘{‘ and the ‘ }’.   And when you have further layers – you indent more:

(The KISS C/IDE has an edit feature aid for this: “Indent All”)

{

{

{

{

{

//Nesting!

}

}

}

}

}

Above was a silly example.

So remember – use white space and indenting to make your code readable for people!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s