You are on page 1of 26

Coding Practices

Coding Standards
01 What is Coding?

02 Goals of Coding
CONTENTS
03 Coding Practices

04 Coding Standards
01
Coding in Software Engineering?
01 What is Coding?

Coding:

 The coding is the process of transforming the design of a


system into a computer language format.

This coding phase of software development is concerned with


software translating design specification into the source code.

Coding is done by the coder or programmers who are


independent people than the designer.
02
Goals of Coding
02 Goals of Coding

1 2 3
To translate the design
of system into a To reduce the cost Making the program
computer language of later phases more readable
format
It increases code
The coding is the process of The cost of testing
understanding having
transforming the design of a and maintenance can
readability and
system into a computer be significantly
understandability as a clear
language format, which can be reduced with
objective of the coding
executed by a computer and efficient coding.
activity can itself help in
that perform tasks as specified
producing more maintainable
by the design of operation
software.
during the design phase.
02 Goals of Coding

Characteristics of Programming Language


For implementing our design into code, we require a high-level functional
language. A programming language should have the following characteristics:

 Readability  Error checking

 Portability  Modularity

 Generality  Quick translation

 Brevity  Efficiency

7
03
Coding Practices
03 Coding Practices

Coding Practices?

 Coding best practices are a set of informal rules that the


software development community employs to help improve
software quality.
03 Coding Practices

How Are Best Practices Relevant in Software Engineering?

 In the software engineering community, standardized coding conventions help keep the
code relevant and useful for clients, future developers, and the coders themselves. Any
professional programmer will tell you that the majority of their time is spent reading
code, rather than writing it. You are more likely to work on existing code than to write
something from scratch. So it’s important that your code is easy to understand for
other engineers.

Best Practices that will help to write production-level code and ultimately make you a
better developer are:

10
03 Coding Practices

1. Enhance Code Readability

 Try to always write code that can be easily understood by


others.

 Professionally written code is clean and modular. It is easily


readable, as well as logically structured into modules and
functions. Using modules makes your code more efficient,
reusable, and organized.

 The debugging process should be much smoother for yourself,


or for other engineers who need to edit your work.
03 Coding Practices

2. Ensure Your Code Works Efficiently

 In order to optimize your code, you need to make sure it executes the
function quickly Because In the world of software engineering,
writing code quickly and correctly is pointless if the end product is
slow and unstable.

3. Refactor Your Code

 Refactoring is basically improving the structure of your code, without making


modifications to its actual functionality. If you have multiple blocks of code that do
similar things, it’s useful to refactor them into a single function. This will allow you
to simplify your code. And if you want to change how that function works, you (or
any other engineer) only need to update one function rather than several.

12
03 Coding Practices

4. Develop A Professional Coding Style

 A professional coding approach is not an exact science. It’s a mindset that


can only be developed over time, by reading and writing a lot of code, and
developing your software engineering knowledge.

 There are a number of principles that will help you develop an effective
coding style. Some of them are:

 Using descriptive names for functions and variables


 Implementing modularity in your code
 Avoiding excessive indentation

Therefore, whether your code is general or production quality, it should always


follow good coding convention.
13
03 Coding Practices

5. Use Version Control

 Version control refers to a software engineering framework that tracks all


changes and synchronizes them with a master file stored on a remote server.

 Using version control in a professional project will give you the following
benefits:

 In case your system crashes, the entire code is backed up on the server.
 All members of the software engineering team can sync their changes
regularly by downloading them from the server.
 Numerous developers can work independently to add/remove features or
make changes to a single project, without impacting other member’s work.
 If serious bugs are created, you can always return to a previous, stable
version of the codebase that was known to work.
14
03 Coding Practices

6. Test Your Code

 Testing ensures the code gives the desired result and meets all necessary
user requirements.

 Unit tests are used to test small, self-contained parts of the code logic.
These engineering tests are designed to cover all possible conditions.

 The process of writing the test is beneficial in itself. It requires you to figure
out the behavior of your code and how you’re going to test it.

 Small and regular tests are better than one large test after completion. This
approach helps maintain a modular structure and will result in a higher
quality end product.

15
03 Coding Practices

7. The KISS Principle

 It stands for “Keep It Simple, Silly”.

 The keyword here is “Simple,” and the idea is to keep your code as
concise as possible. In the context of coding, this means making your
code meaningful, to-the-point, and avoiding unnecessary engineering
work.

 The KISS Principle ensures that your code has high maintainability. You
should be able to go back and debug it easily, without wasting time
and effort.

16
03 Coding Practices

8. The YAGNI Principle

 YAGNI means “You Aren’t Gonna Need It”.

 This principle focuses on eliminating any unnecessary coding and


works in tandem with the KISS principle.

9. The DRY Principle

 DRY (Don’t Repeat Yourself) Principle aims at reducing repetition


and redundancies within the software engineering process. This is
achieved by replacing repetitions with abstractions or by grouping
code into functions.

17
03 Coding Practices

General Tips

Some tips and techniques can be applied to any coding language and are
useful in improving the overall quality of your code:

 Allocate appropriate names to all functions, variables, and methods.


This will make your code easier to read, understand, and debug.

 Always use the common or native language of the developer for


names and descriptive texts. Avoid abbreviations as much as possible
to reduce ambiguity.

 Use consistent indentation and alignment while formatting your code


for better readability.

18
04
Coding Standards
04 Coding Standards

Coding Standards
 A coding standard gives a uniform appearance to
the codes written by different engineers.

 It improves readability, and maintainability of the


code and it reduces complexity also.

 It helps in code reuse and helps to detect error


easily.

 It promotes sound programming practices and


increases efficiency of the programmers.
04 Coding Standards

Some of the coding standards are given below:

1.Limited use of globals

 These rules tell about which types of data that can


be declared global and the data that can’t be.
04 Coding Standards

2.Standard headers for different modules

 For better understanding and maintenance of the code, the header of different
modules should follow some standard format and information. The header
format must contain below things that is being used in various companies:

 Name of the module


 Date of module creation
 Author of the module
 Modification history
 Synopsis of the module about what the module does
 Different functions supported in the module along with their input output
parameters
 Global variables accessed or modified by the module
04 Coding Standards

3. Naming conventions for local variables, global variables, constants and functions

 Some of the naming conventions are given below:

 Meaningful and understandable variables name helps anyone to understand the


reason of using it.
 Local variables should be named using camel case lettering starting with small
letter (e.g. localData) whereas Global variables names should start with a capital
letter (e.g. GlobalData). Constant names should be formed using capital letters
only (e.g. CONSDATA).
 It is better to avoid the use of digits in variable names.
 The names of the function should be written in camel case starting with small
letters.
 The name of the function must describe the reason of using the function clearly
and briefly.
04 Coding Standards

4. Indentation

 Proper indentation is very important to increase the readability of the code. For
making the code readable, programmers should use White spaces properly.
Some of the spacing conventions are given below:

 There must be a space after giving a comma between two function arguments.
 Each nested block should be properly indented and spaced.
 Proper Indentation should be there at the beginning and at the end of each
block in the program.
 All braces should start from a new line and the code following the end of braces
also start from a new line.
04 Coding Standards

5. Error return values and exception handling conventions

 All functions that encountering an error condition


should either return a 0 or 1 for simplifying the
debugging.
Thank you
for listening

You might also like