Best Practices - Programming

Discussion in 'Programming' started by rahulnaskar, Oct 21, 2006.

  1. rahulnaskar

    rahulnaskar New Member

    Joined:
    Aug 26, 2004
    Messages:
    25
    Likes Received:
    2
    Trophy Points:
    0

    Introduction



    This is an article on our day-to-day programming practices. The article is targeted from beginners to pro who are involved in programming hands on. Life glides when we begin programming and our projects are small, the factorials, finding out primes and so on. When we master the skill set of branching, looping, expressions etc the next program waiting for us is a project of some size, which matters. Trouble begins when we find that our source is not confined in one screen only and spans across multiple files. Beginning from here on, we, the lazy programmers, start doing mistakes, which are repeated throughout our lifetime and never gets corrected (I am not an exception and hence this article).

    Most of us, except a few god-gifted, who are pro in the industry still continues to do the same. Hence let's find out some of the best practices prescribed and found over our experiences of coding. The set to avoid and the set to follow.

    1. Naming Convention



    Naming variables are one of the major issues in programming. Include the scope in name, include datatype and many more are the frequently asked questions and issues, lets try and find out how to find the best of practices.

    General Convention



    For some special reason (I wish it be different) spaces are not allowed in a variable name. To avoid make it the way it’s said “start with lowercase and make it mixed case”. Different logical units of a variable should start with uppercase letters. Prefix the same with datatype, e. g., intMarksObtained, chrFirstName. Follow fixed length convention for the datatype prefix except for cases the need be. Hungarian notation varies in length for prefixing the datatype

    Naming Objects



    I prefer prefixing objects with obj. Other conventions include prefixing with class name in full or short. Choosing amongst them is a matter of personal choice.
    Never combine hierarchical information of an object in variable names, it will complicate life rather than making things simple, e. g., AutoCarMyCar or AutoCarFriends describes the variable beyond it’s class information. Don’t try such naming standards, won’t make your life easy. A better approach would be making it objMyCar or carMyCar.

    Naming Class Members



    In general two practices are commonly followed prefixing or suffixing members with “_” (underscore). Recommendations are that suffix of _ should be used, which increases readability. I prefer, though, prefixing it; which increases my readability.
    Follow general guidelines for naming following _, e. g., _intPosition.

    Scope Incorporation



    There are suggestions that scope be included in a placeholder to identify the scope of a variable/member, e. g. lintPosition, indicating local variable or pintNoOfRecords, indicating a global variable. I don’t find this particular convention useful unless we are maintaining or modifying extremely ugly piece of code.
    However for global member g_ or g should act as a prefix e. g., gintCounter or g_intCounter. This convention distinctly differentiates our global variables and their uses in different places of the program.

    Iterators



    For historical reasons most programmers use i, j …as iterators. I prefer using this convention only. This practice can be changed to big names if we are dealing with huge number of iterators within a single function, otherwise it should be done the i, j… way only. All programmers (as much as I know) understand or assumes i, j … kind of variables to be iterators. Reuse these iterators at will with a noble practice of adding a single line to reinitialize the iterator with the desired values before using.

    int i;
    i = 0;
    while ( <expr> >= i)
    {
    ….
    }
    i = 0;
    while (<expr> >= i)
    {

    }

    C++ Warning



    Declaration of a variable can be done in any part of a code, hence tendencies go towards declaring and using an iterator. Beware of the fact that if not declared within a block it will draw a compile time error, in case the same name is used for another iteration in later part of the function. Do not bypass this error by putting braces to mark the iteration as a block, as it might not reflect other changes expected to be reflected elsewhere.

    Best Practices - Programming->Classes/Functions >>
     
  2. Nandu

    Nandu New Member

    Joined:
    Jan 6, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    hi rahul my name is nanda kumar.p
    i don't know the basic of programing languages how i easy to study the programing language
    please help me.[:)]
     
  3. satyedra pal

    satyedra pal New Member

    Joined:
    Mar 26, 2010
    Messages:
    93
    Likes Received:
    1
    Trophy Points:
    0
    The term language is a medium for communication.Sharing data between two things or person or anybody is possible if both are understandble to each other.Like this programming language is a artificial language with vocabulary and set of grametical rules for performing specific task.
    A programming language is designed to done computations that will be performed by a machine,like a computer.Programming language is a high level language because compare to computer it is complex and is used for instructing computer.The computer knows machine language, Each CPU has own machine language.
    there are many programming language like c,C++,JAVA,PASCAL,COBOL etc. These programming language have own keywords and syntaxes for arranging pTogram.
    The example of machine language is assembly language perform the task in 0's and 1's format.
    For using your programming language to perform the task,you need to convert your program into machine language so that the computer can understand it.
    This will be done in two steps:
    a)Compile your program.
    b)Execute your program.
    computer program will convert source code written in a particular programming language into computer understable machine code.From machine code computer will find out the query and process that provide result after executing .
     
  4. hanleyhansen

    hanleyhansen New Member

    Joined:
    Jan 24, 2008
    Messages:
    336
    Likes Received:
    8
    Trophy Points:
    0
    Occupation:
    Drupal Developer/LAMP Developer
    Location:
    Clifton
    Home Page:
    http://www.hanseninfotech.com
  5. Klusner

    Klusner New Member

    Joined:
    Jan 24, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    PHP programming language:

    PHP is a programming language and used for the programming and web developing. It’s easy to understand and apply and provide you the same results as others languages. The best feature is the convenience in understanding and it is not complex like other languages.
     
  6. annahussy

    annahussy Banned

    Joined:
    Jun 20, 2012
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    There are so many easy languages are available, and you can learn very easily through so many tutorials as well. If you become masters on that you go for particular one course so that That is easy for you to get one command on language.
     
  7. wilomr11st

    wilomr11st New Member

    Joined:
    Aug 7, 2012
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Home Page:
    http://x.co/lgUx
    hi rahul my name is nanda kumar.p
    i don't know the basic of programing languages how i easy to study the programing language
    please help me.[]
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice