Why whitespace such as spaces, tabs and newline is ignored while programming? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Why whitespace such as spaces, tabs and newline is ignored while programming?

I asked this question because If spaces are ignored, it means int main () and intmain() are same but compiler gives us an error.

5th Oct 2017, 1:32 PM
Akash papnai
Akash papnai - avatar
3 Antworten
+ 3
continuous white spaces are ignored so developers can make their code readable. it does not matter how many spaces are there between two tokens but "intmain()" and "int main()" have a difference of being one and two tokens so the problem occurs.
5th Oct 2017, 1:36 PM
rishabh agarwal
rishabh agarwal - avatar
+ 9
The compiler doesn't really ignore as it still need to parse/understand the syntax separated by space like you've mentioned. It's just the case that MULTIPLE whitespaces is redundant or unnecessary as compiler still treat it the same.
5th Oct 2017, 1:37 PM
Zephyr Koo
Zephyr Koo - avatar
+ 2
* Important note: All spaces are not whitespace. Compilers ignore whitespace, but not all spaces. An example is Python. You must put spaces for code blocks! Considering note above, they aren't same (int main() and intmain()). Programming languages are the same as real languages. How can you understand my sentence if I ignore all spaces between words? At least, it's so hard and takes down your reading speed. Besides, you may read my sentence in a wrong way. If I merge two words, it would be readable in many ways. Finally, consider we are humans, what you expect from bots and computers, better to say, parsers and compilers?
5th Oct 2017, 1:44 PM
$machitgarha
$machitgarha - avatar