1. Check for all the warnings given on
compiling of the code and try to remove the warnings
2. Perform Code analysis tool and check for the following
a. Constraint Violators
b. Redundancies in Code
c. Redundancies in Symbol Declarations
d. And most important – Solve the
Compiler Error
3. “null” check needs to be performed
where every application to avoid Null
Reference Exception error.
4. Naming Conventions should be
followed with all variables following Camel Casing , and Class names following
Pascal Casing.
This rule helps in making Code better readable and this makes it more
maintainable.
5. Liskov substitution – Any derived
class should not modify the behaviour of the Base Class.
6. Code Reusability – Extract the piece
of the code that is to be used multiple times and modularize the code.
Developers when detect the requirements coming in are causing the code to get repetitive
then the Generic methods should be introduced having this common piece of code
which is then been used by other developers.
7. Code Consistency – Variable type
should remain consistent , so if something is defined as int then it should not
become int32 in any other layer.
Use of Stringbuilder should be
promoted instead of String if string concatenation is present.
8. Disposing of unmanaged objects - For
the majority of the objects that your app creates, you can rely on the .NET
Framework's garbage collector to handle memory management. However, when you
create objects that include unmanaged resources, you must explicitly release
those resources when you finish using them in your app. The most common types
of unmanaged resource are objects that wrap operating system resources, such as
files, windows, network connections, or database connections.
9. Correct implementation of Exception
Handling – try \ catch and finally blocks and logging the exceptions correctly.
10. Code Writing Rules
a. Avoid nested for / foreach loops and
nested if conditions where possible.
b. No function should have more than
30-40 lines. If the function code is increasing then it is advisable to break
it in more methods.
c. Try using LINQ queries and LAMBDA
expressions to improve Code readability.
d. Proper usage of var, object and
dynamic keywords.
e. Use of correct access specifier ie
public, private, protected based on the need \ scope of the method , variable.
f. Mark a class as sealed or static or
abstract based on the need.
g. Use Constants and readonly where
required.
h. Write correct and proper code
comments.
Comments
Post a Comment