I'm a bit of a sucker for tidy code, so I like to have everything indented and flowing, if you know what I mean.
private void myFunc()
{
while(true)
{
//do this
}
}
etc. Now, I know that in a text file, the tab character or four spaces or whatever is actually stored in there, ready for the next time I open it.
If I go to compile this though, am I going to see any benefit in output filesize / compilation performance by not having tidy formatting and indentation, or does the compiler just ignore everything that isn't important?
Whitespace is a term that refers to characters that are used for formatting purposes. In C++, this refers primarily to spaces, tabs, and (sometimes) newlines. The C++ compiler generally ignores whitespace, with a few minor exceptions. For example, all the 4 lines below mean the same thing −
C isspace()The isspace() function checks whether a character is a white-space character or not. If an argument (character) passed to the isspace() function is a white-space character, it returns non-zero integer. If not, it returns 0.
Definition of white space : the areas of a page without print or pictures.
Whitespace is a programming language that only uses spaces, linefeeds, and tabs – the interpreter ignores all other characters. Each command in the Whitespace language consists of a series of tokens. Stack-based languages work using a global stack.
One of the compilation steps is known as tokenization. This step removes all of the whitespace and comments from your code. As long as your code parses correctly, there's no difference between well formatted or poorly formatted code in terms of runtime speed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With