Beruflich Dokumente
Kultur Dokumente
B:hEmAl rAJYAGURU,gujarat
Cod guidlin
Coding Guidelines
Submitted To:
Prof. Rahul Dev Singh
CE Department
NIT-Kurukshetra
Presented By:
Hemal Rajyaguru
M. Tech-211519
NIT-Kurukshetra
Naming Conventions
My name is Bond. James Bond.
It is very important to give
meaningful names to all your
constructs.
e.g. A name like
getAverageHeight() or
get_avg_height() gives us much
more information then calculate().
Variable Naming
As a rule of thumb : bigger the scope bigger the name.
The reason for it is that many people will be using the global across different files in
different contexts, and every one should be sure of its usage.
If the scope of variable is limited, then it can have smaller name. For example, It is OK
to call a variable i which is used as a loop counter or index variable, provided it is not
used to do anything else significant.
Some names do have standard abbreviation, for e.g. max. So, calling a
variable maxLength gives us the same amount of information as
maximumLength, but using the former saves some keystrokes .
Names starting with _ (underscore) and __ (two underscores) are
reserved for compiler writers. These should be avoided.
There are 2 common practices to separate words in a multiple word
name:
using _ or capitalization. For e.g., a routine for getting maximum length
can be called either max_length or or maxLength.
We are planning to follow 2nd practice (maxLength), unless there are
serious objections to it. Since we shall definitely use STL, and STL uses
first style of names, it will allow us to distinguish between STL variable
and inhouse variables.
If an abbreviation is contained in a name, it should not be used in all
uppercase form.
for example: use getHtmlPage // not getHTMLPage
Constants
Classes
Functions
The start brace "{" and end brace "}" for a function should be in
first column (and preferably alone in that line). That makes easy
navigation to start and end of a function.
Comments and
Documentation
Comments are free but facts are sacred(holly/useful). -- Charles
Prestwich Scott
Start each file with a copyright notice, followed by a description of the
contents of the file.(Include author name, date, developed at,etc)
(Note: Here I am not talking about the documentation as in design-document
or user-guide, but documents which explain working of some part of the code
and passed among generation of developers to understand the source code.)
Comments and Documentation are aid to understand the code. They
help us in following the program flow, and skip parts for which we are not
interested in details.
If one is not careful, then they become rewriting of what is already written in
the code. So, they have same problems as duplication of source code:
consistency, maintenance etc. These should be minimized by making the code
self explanatory.
Classes
The loftier the building, the deeper must the foundation be laid. -Thomas Kempis
don't make your modifier routines public thereby allowing every class to
modify the data and thus creating a cause for potential havoc. Instead: Make
the modifiers private.
Some routines/interfaces are inherently used by every one - for e.g. push/pop
routines of a generic Stack class. Only such routines must be made public.
Separate the core algorithm/strategy to be implemented in a separate class
from the actual class consisting of data and data management/bookkeeping
routines.
Ensure that your classes are not bloated. If you have a class which has a huge
amount of data and methods, it means that you have not designed to correct
level of granularity and hence need to break this bloated class into more
classes.
Keep optional compiler warnings on. Most of the compilers can warn
for legal language idioms which can be used in mistaken way and for
non-portable code.
So as a good programmer you should notice error as well as
warnings.
Miscellaneous
Programming today is a race between software engineers running to
build bigger and better idiot-proof programs, and the University trying
to produce bigger and better idiots. So far, the University is winning.
-- Hemal Rajyaguru(Inspired from Rich cook)
Some of the processes which help in developing good software are: Having
functional specifications, design document, and other helper documents ready
before start of coding.
Some of the important tools used for code tuning in large software development
are:
Lint tools (lint, splint) - To catch portability problems
Debuggers (gdb, dbx) - To catch logical errors
Memory Profilers (purify, mempetrol, valgrind) - To detect memory leaks,
unutilized memory use etc.
Code coverage tools (purecov, tcov, gcov) - To look for the part of code which
did not get exercised.
Code Profilers (quantify, gprof, prof, vprof) - Used for optimizing the
performance
Look for the tools available for your platform, learn them and use them
extensively.
References
The man who doesn't read good
books has no advantage over the
man who can't read them. -Mark Twain (1835 - 1910)
So try to refer concrete and well
knowledgeable reference while
learning coding.
Golden Words
If you want to please the audience, please yourself
first
I think programming is first about you.
I may sound a little selfish here but let me explain. I deeply
believe that if you are intimately connected to the works you
play, the audience will do so.
If you are convinced your program and playing are wonderful,
you can convince an audience.
Eg:JAI BHADRAKALI
Eg:eclipse
for(int i=0;i<10;i++)
{
printf(i=%d\n,i);
}
Thanks!!!!!!!!!
Enjoy Coding!!!!!!!!!!!!!!!!!!!!!