Wednesday, April 24, 2019 03:55

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 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

formatting codes

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).




Leave a Reply