Quick Google Search

“Coding” and “Programming “ are interchangeably used in Programming World .


“Coding” and “Programming “ are interchangeably used in Programming World (“code”
refers to “program”). Readability can be referred as how far your code can be readable. So for
better readability it is necessary to code with good style and indentation (Indentation refers to
proper spacing and alignment). And so we’ve got  lots of coding styles. Indian Hill style &
Hungarian Style are the most popular among other coding styles. But I have found that no coding
style is perfect. And I have developed a new coding style named as WAR (Wesley and Rajesh).
Let me introduce WAR coding style in the end of this chapter!

3.1 Indian Hill Style
  Indian Hill Style is one of the most popular coding styles used by most of the real
programmers. If you know Java, you might be already aware of Indian Hill Style. I hope the
following fragments would help you to identify Indian Hill Style.

 /* Here is a comment.
  * This is for demo.
  */
enum day { SUN=1, MON, TUE, WED, THU, FRI, SAT };
struct date {
 int  dd; /* day no. 1-31 */
 enum day dname; /* weekday name */
 long  yyyy; /* year */
};
/* Another comment.
 * Purpose of the function.
 */
 int
foo ( foo1_t const *f1, foo2_t *f2 )
{
for (...) {
  while (...) {
   ...
   if (error)
    goto error;
  }
 }
 ...


 A to Z of C
error:
 clean up the error
return( what );
}

3.2 Hungarian Coding Style
  Visual Basic programmers use Hungarian Coding Style. In this coding style, you can see
that the variables are prefixed with their data types, which is also a disadvantage to this style. The
following code fragment uses Hungarian Coding Style.

int intStudNo;
double dblStudPercentage;

3.3 WAR (Wesley And Rajesh) Coding Style
  I personally feel that none of the above coding style is good and so I developed WAR
coding style. The following are the rules of WAR coding style:

a) All functions written by programmers should begin with capital letter (to differentiate
it with built-in functions) and should not contain underscores.

(e.g.) MyGotoXY( ), Window( ), MsgWindow( )

b)   All global variables should begin with capital letter and must contain underscore.

(e.g.) Next_Tick

c) All local variables should be formed with small letters.

(e.g.) nexttick, tick

d)  All variables should be meaningful. Variables i, j, k, l, m, n are to be used
for iteration purposes.

(e.g.) for( i=0; i<n; ++i )

e) Structure declaration should not accompany with initialization. Initialization should
be done separately for clarity.

(e.g.) struct date
{
      int dd;
     int mm;
      int yyyy;
 };
struct date dob = { 10, 10, 2001 };


f) Structure that won’t require more than one name can be typedefed.
(e.g.) typedef struct
 {
      BYTE fileid;
   :
   :
 } FILEHEADER;
g)  The definition with typedef or #define should contain only capital letters.
(e.g.)    typedef int BOOLEAN;
     #define  TRUE   (1)
  #define  FALSE  (0)
h)  All declarations should precede functions, all functions should precede main( ).
i)  Don’t use goto statement.
j)  Don’t use more than one return statement in a single function.
k) Try to avoid use of  exit( )  in programs. But  exit( )  can appear in the
beginning of the program or on a separate procedure for checking errors.
l)  Don’t use continue and break, instead use BOOLEAN variable.

No comments:

Popular Posts