General Guidelines for Good Programming – Part 2

General Guidelines for Good Programming – Part 2

Hi Friends, If you have missed Part 1 of General Guidelines for Good Programming, make sure you read that first.

Nested Loop:

If you have several nested loops, assign longer names to the loop variables to improve readability. Java Example of Good Loop Names in a Nested Loop


for ( teamIndex = 0; teamIndex < teamCount; teamIndex++ )
{    for ( eventIndex = 0; eventIndex < eventCount[ teamIndex ]; eventIndex++ )
    {
      score[ teamIndex ][ eventIndex ] = 0;
   }
}

Diagrams:

Draw a Diagram Diagrams are another powerful heuristic tool. A picture is worth 1000 words—kind of. Picture can represent the problem at a higher level of abstraction.

Routine Parameters:

Don’t use routine parameters as working variables It’s dangerous to use the parameters passed to a routine as working variables. Use local variables instead. For example, in the following Java fragment, the variable inputVal is improperly used to store intermediate results of a computation

int Sample( int inputVal )
{

   inputVal = inputVal * CurrentMultiplier( inputVal );
   inputVal = inputVal + CurrentAdder( inputVal );// ... At this point, inputVal is no longer contains a input value longer
}

good programming

Reuse Code:

The single biggest way to improve both the quality of your code and your productivity is to reuse good code. Check whether the code is available in library or any algorithms are available. Make sure you are not doing more work than necessary.

How to Optimize?

It’s usually a waste of effort to work on efficiency at the level of individual routines. The big optimizations come from refining the high-level design, not the individual routines. You generally use micro-optimizations only when the high-level design turns out not to support the system’s performance goals, and you won’t know that until the whole program is done. Don’t waste time scraping for incremental improvements until you know they’re needed.

These are the points that I have gathered from the Book ‘Code Complete’ written by Steve McConnell. Every Software Engineer Should read this book at least once. It contains lots of guides with real-time usage which can make you a better programmer.

YOU CAN BUY  THE BOOK USING THE BELOW LINK

General Guidelines Series

General Guidelines For Good Programming Part 1

General Guidelines for Good Programming | Part-3

General Guidelines for Good Programming | Part-4

Follow For Instant Updates

Join WhatsApp Group: link
Join our Telegram Channel: link
Like our Facebook Page:  link
Subscribe to our Youtube channel: link

Sree Hari Sanjeev

The founder of Wisdom Overflow. Software Developer at Zoho Corporation.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x