Not a member?     Existing members login below:

Fundamentals of Computer Programming with C#


Chapter 21. High-Quality
Programming Code
In This Chapter
In this chapter we review the basic rules and recommendations for writing
quality program code. We pay attention to naming the identifiers in the
program (variables, methods, parameters, classes, etc.), formatting and
code organization rules, good practices for composing methods, and
principles for writing quality documentation. We describe the official
"Design Guidelines for Developing Class Libraries for .NET" from Microsoft. In
the meantime we explain how the programming environment can automate
operations such as code formatting and refactoring.
This chapter is a kind of continuation of the previous one – Object-Oriented
Programming Principles. The reader is expected to be familiar with the basic
OOP principles: abstraction, inheritance, polymorphism, encapsulation
and exception handling. Those do greatly affect the quality of the code.
Why Is Code Quality Important?
Let’s examine the following code:
static void Main()
{
int value=010, i=5, w;
switch(value){case 10:w=5;Console.WriteLine(w);break;case
9:i=0;break;
case 8:Console.WriteLine("8 ");break;
default:Console.WriteLine("def ");{
Console.WriteLine("hoho ");}
for (int k = 0; k < i; k++, Console.WriteLine(k -
'f'));break;} { Console.WriteLine("loop!"); }
}
Are you able to comprehend what this code does in a short glance? Does it
do its job correctly, does it contain any errors?
 
 
 
 
Remove