Monday, October 15, 2012

What make Quality of Code/ How to measure?



What make Quality of Code/ How to measure?

To make sure that your code is well running together with the other, you might need to have standard or tools that you and your team could work

Code Metrics

Code metrics is a set of software measures that provide developers better insight into the code they are developing. By taking advantage of code metrics, developer can understand which types or methods should be rework or have more tests.
There are some common measures that we could use;

  •           Total line of code
  •           Line of duplicate code
  •           Unit test coverage
  •           Coding standard violation
  •           Program execution time
  •           Program load time
  •           Ratio of comment and code

Code Standard

MISRA-C is software development standards for C programming language develop by MISRA (Motor Industry Software Reliability Association). Many developers from embedded systems specification always refer to MISRA C Standard for the work that needs high reliability.
MISRA also has more users outside the original specification. They realized that in many areas of an automobile design, safety, portability and reliability is importance. They has evolved as a widely accepted model for best practices by leading developers in sectors including aerospace, telecom, medical devices, defense, railway and others.
The result was a set of “Guidelines for the use of the C language in Vehicle-Based Software” or “MISRA C”. The first published guideline comprises a 70-page document that describes a workable subset of C to avoid many of well-known problems. The MISRA C document contains 8 chapters and 2 appendices and was obviously written by experienced embedded programmers. Chapters 1 through 6 contain important information about the rationale for MISRA C and how to interpret the rules. These Chapters should be read prior to diving in to the actual rules, which are found in Chapter 7. MISRA C document is available at www.misra.org.uk for about $50.

Friday, October 12, 2012

Quality of Code



Quality of Code

There are many definitions for Quality of code from my research this few days. As we know, we try to improve our code, not only for the author but also other people in the team. If I could list what are the good code should be, it should be like this;
  • No redundant or repeat code: if you have several lines of code with the same action, you should make it to the new function. For this advantage, you will have another short command that can reuse many times.
  • Code readable 
    • Use good name for function or variable
    • Good comment and document
    • But if you have a good code it should understandable without comment. Source code itself says what the code does and how
  • Right responsibility for each function: one responsibility for one function.
  • Optimize resource/efficient: Poorly written code will not take account of resource usage, for example it will not cache information it could cache, or it will create new objects when it did not need to. These issues lead to hard to maintain applications when deployed and used.
  •  Well organized: should be easy to find what variable goes to which function, where you locate your code.
  •  Have code review: ask some other person for each some important part