Whitespace

Started by
7 comments, last by Oluseyi 17 years, 8 months ago
I have been told 2 things about whitespace in a program: 1. Whitespace serves only to make your program more easy to read and has no effect on your program 2. Whitespace DOES have an effect on your program Which is true?
01001001 00100000 01100011 01100001 01101110 00100111 01110100 00100000 01100010 01100101 01101100 01101001 01100101 01110110 01100101 00100000 01111001 01101111 01110101 00100000 01100001 01100011 01110100 01110101 01100001 01101100 01101100 01111001 00100000 01110100 01101111 01101111 01101011 00100000 01110100 01101000 01100101 00100000 01110100 01101001 01101101 01100101 00100000 01110100 01101111 00100000 01110100 01110010 01100001 01101110 01110011 01101100 01100001 01110100 01100101 00100000 01110100 01101000 01101001 01110011 00101110
Advertisement
Depends which language. Python, for example, relies heavily on whitespace to determine scope. C++, on the other hand, does not use it at all (except for rare cases).
Whitespace serves only to make your program more easy to read and has no effect on your program. The only time it should have an effect on your program is if you have it within quotes, " ", in C++ of course, and C.
Most whitespace has no effect on your program in most languages. The most common case in C-style syntaxes is something like >> vs. > > .
To anyone else wishing to reply, I'm pertaining to C++
01001001 00100000 01100011 01100001 01101110 00100111 01110100 00100000 01100010 01100101 01101100 01101001 01100101 01110110 01100101 00100000 01111001 01101111 01110101 00100000 01100001 01100011 01110100 01110101 01100001 01101100 01101100 01111001 00100000 01110100 01101111 01101111 01101011 00100000 01110100 01101000 01100101 00100000 01110100 01101001 01101101 01100101 00100000 01110100 01101111 00100000 01110100 01110010 01100001 01101110 01110011 01101100 01100001 01110100 01100101 00100000 01110100 01101000 01101001 01110011 00101110
Well,

const int variable;

is different from

constintvariable;
In C or C++ neither whitespace nor comments have an effect on the compiled program.

Whitespace is defined as the space between function names, arguments, types, keywords, class names, operators or any other identifiers. Wherever a single space is valid, many spaces or line breaks will also be valid.

*edit: and as the above poster mentioned, you require at least one space between each identifier.
_______________________"You're using a screwdriver to nail some glue to a ming vase. " -ToohrVyk
Indeed, thanks all for your comments

Just figured I'd double check that before I went and did anything stupid with my coding skills.
01001001 00100000 01100011 01100001 01101110 00100111 01110100 00100000 01100010 01100101 01101100 01101001 01100101 01110110 01100101 00100000 01111001 01101111 01110101 00100000 01100001 01100011 01110100 01110101 01100001 01101100 01101100 01111001 00100000 01110100 01101111 01101111 01101011 00100000 01110100 01101000 01100101 00100000 01110100 01101001 01101101 01100101 00100000 01110100 01101111 00100000 01110100 01110010 01100001 01101110 01110011 01101100 01100001 01110100 01100101 00100000 01110100 01101000 01101001 01110011 00101110
Use whitespace liberally. The primary function of modern production code is to communicate with other programmers. Whitespace makes that easier.

This topic is closed to new replies.

Advertisement