Section 2 - Whitespace

2A.2.1 Whitespace

Everything I tell you about C++ for the time being will concern syntax that takes place within the braces of a method, and for the first few lectures, the method will be the main() method:

int main()
{
cout << "Hello World!";
return 0;
}

In C++, whitespace, means spaces, tabs and returns. Other than when text is inside quotation marks, "  ", whitespace is unimportant to the compiler. All of the following are equivalent:

int main() { cout << "Hello World\n!";  return 0; }

int main() {
cout << "Hello World\n!";
return 0; }

int main()
{ cout
<<
"Hello World\n!"    ;
return 0      ;
}

int main()
{
cout << "Hello World\n!";
return 0;
}

However, even though they are the same to the compiler, they are not the same to the programmer. Proper style makes the program much easier to read than random or haphazardly written programs.

2A.2.2 Style Reminder building

I prefer a style similar to the last example. As you read my sample program fragments, notice how I indent and try to use a similar, or equally rational style. Do not invent your own style. Use mine, the one in the text book, or the style used in the recommended Elements of C++ Style and adapt that style. Do not mix styles - stick to one.  Be careful: if the book contains a typo, it should be obvious based on the style rules. Don't copy obviously incorrect indentation, even from the text, into your assignments.

I can't say this often enough, because I don't want it to happen:

You will lose points if you do not use correct style.

For the first assignment you can lose 1 point. For the second assignment you can lose 2 points. By the time you're doing your last assignment, you could lose as many as 9 points if you do not indent correctly, even if your program works perfectly. 

These are the facts of this class.