C Programming Style (Different Indentation Rules) - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

C Programming Style (Different Indentation Rules)

Share This
At the time of writing a program, you are free to write it without following any styling rule, as the C programming language is a free format language. You may place starting and closing brace at any place without violating programming logic. You may use new lines; you may name the variables and functions without obeying any rule. But to be a good programmer, you should follow some rules, that may be defined by you.

Advantages and Disadvantages


The advantage of C language is that a user is free to choose a style according to her choice. The user has full freedom to structure the program to make it more readable.

But the disadvantage is that if the user does not follow strict style rules, which are conventionally used. It will be difficult to understand by others.

Conventional rules and purpose


The reasons for choosing a programming style are:
  • When the program size grows, it's difficult to manage if programs are not properly organized and indented. Indentation is very important to understand starting and end points of a function or block of code.
  • The names of the variables and functions should be meaningful so that any other developer can understand the logic.
  • Names of the local, and global variables, macros, and functions should be based on some convention. So that at any point a programmer can distinguish them.
  • Moreover, code should be documented by single or multi-line comments. So, the purpose of the variable or function can be understood without understanding the logic of the whole program.

Indentation Rules


Indentation is very important in any programming domain. Though, most programmers are reluctant to follow it.

In computer programming, an indentation style is a convention, in some languages it's mandatory. In C programming language, indentation is not mandatory, but it improves readability. However, the additional whitespaces are insignificant.

Indentation helps in:
  • conveying a better structure of a program to the readers and developers.
  • clarifying the control flow.
In languages like Python, indentation is used to determine the structure instead of using braces or keywords.

Proper code indentation helps to read, understand, modify, and maintain code easily.

Indentation has no effect execution time or size of the finished program. It makes the code more readable if properly maintained. So, we should follow proper spacing throughout our coding and it should be consistent.

There are four types of Bracing Styles as shown below:


1TBS


#include <stdio.h> int main (void) { printf("Hello World!"); return 0; }



Allman


#include <stdio.h> int main (void) { printf("Hello World!"); return 0; }



Whitesmith


#include <stdio.h> int main (void) { printf("Hello World!"); return 0; }



GNU


#include <stdio.h> int main (void) { printf("Hello World!"); return 0; }



Happy Exploring!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

About BunksAllowed