Active TopicsActive Topics  Display List of Forum MembersMemberlist  CalendarCalendar  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin


 One Stop Testing ForumQuality Assurance @ OneStopTestingQuality Methodologies / Streams @ OneStopTesting

Message Icon Topic: What is a good code?

Post Reply Post New Topic
Author Message
vidhya
Senior Member
Senior Member


Joined: 24Mar2007
Online Status: Offline
Posts: 114
Quote vidhya Replybullet Topic: What is a good code?
    Posted: 26Mar2007 at 2:06am
Ques:What is a good code?
 
Ans:Good code' is code that works, is bug free, and is readable and maintainable. Some organizations have coding 'standards' that all developers are supposed to adhere to, but everyone has different ideas about what's best, or what is too many or too few rules. There are also various theories and metrics, such as McCabe Complexity metrics. It should be kept in mind that excessive use of standards and rules can stifle productivity and creativity. 'Peer reviews', 'buddy checks' code analysis tools, etc. can be used to check for problems and enforce standards.
For C and C++ coding, here are some typical ideas to consider in setting rules/standards; these may or may not apply to a particular situation:
  • minimize or eliminate use of global variables.
  • use descriptive function and method names - use both upper and lower case, avoid abbreviations, use as many characters as necessary to be adequately descriptive (use of more than 20 characters is not out of line); be consistent in naming conventions.
  • use descriptive variable names - use both upper and lower case, avoid abbreviations, use as many characters as necessary to be adequately descriptive (use of more than 20 characters is not out of line); be consistent in naming conventions.
  • function and method sizes should be minimized; less than 100 lines of code is good, less than 50 lines is preferable.
  • function descriptions should be clearly spelled out in comments preceding a function's code.
  • organize code for readability.
  • use whitespace generously - vertically and horizontally
  • each line of code should contain 70 characters max.
  • one code statement per line.
  • coding style should be consistent throught a program (eg, use of brackets, indentations, naming conventions, etc.)
  • in adding comments, err on the side of too many rather than too few comments; a common rule of thumb is that there should be at least as many lines of comments (including header blocks) as lines of code.
  • no matter how small, an application should include documentaion of the overall program function and flow (even a few paragraphs is better than nothing); or if possible a separate flow chart and detailed program documentation.
  • make extensive use of error handling procedures and status and error logging.
  • for C++, to minimize complexity and increase maintainability, avoid too many levels of inheritance in class heirarchies (relative to the size and complexity of the application). Minimize use of multiple inheritance, and minimize use of operator overloading (note that the Java programming language eliminates multiple inheritance and operator overloading.)
  • for C++, keep class methods small, less than 50 lines of code per method is preferable.
  • for C++, make liberal use of exception handlers
MBA Examination papers



Post Resume: Click here to Upload your Resume & Apply for Jobs

IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.484 seconds.
Vyom is an ISO 9001:2000 Certified Organization

© Vyom Technosoft Pvt. Ltd. All Rights Reserved.

Privacy Policy | Terms and Conditions
Job Interview Questions | Placement Papers | Free SMS | Freshers Jobs | MBA Forum | Learn SAP | Web Hosting