Monday, October 14, 2024 23:11

Table of contents >> Introduction > Formatting codes

Formatting codes

Formatting codes refers to the process of adding spaces, new lines and tabs, with the sole purpose of improving the visibility and readability of our codes. The compiler does not care of these so-called “white spaces”. For it, they have no meaning. Consider these four pieces of codes:





As you might have guessed, the above codes are identical, they all compile and they all produce the same program, behaving the same in all 4 cases. BUT!

You have to agree, all variations except the first one are hard and VERY hard to read and understand. Consider having a 5000 lines program written on a single line!

Visual Studio deals with formatting your code by default. However, there are cases when this auto-formatting will fail. In that case, go to Edit menu, chose Advanced and click Format Document

Visual Studio auto formatting documents

That will re-format your code (aside of the times when you have an error in your codes, in which case, obviously, the IDE does not know what your program should look like).

The concepts explained in this lesson are also shown visually as part of the following video:

Tags:

Leave a Reply



Follow the white rabbit