0% found this document useful (0 votes)
29 views10 pages

1 - Coding Standards and Guidelines

Uploaded by

Tanya Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views10 pages

1 - Coding Standards and Guidelines

Uploaded by

Tanya Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Coding Standards and Guidelines

 Coding standards are collections of coding rules, guidelines, and best


practices using the right coding standards — such as C coding standards
 Different modules specified in the design document are coded in the Coding
phase according to the module specification.
 The main goal of the coding phase is to code from the design document
prepared after the design phase through a high-level language and then to unit
tests this code.

What are Coding Standards and Guidelines?

 Good software development organizations want their programmers to maintain


some well-defined and standard style of coding called coding standards.
 They usually make their own coding standards and guidelines depending on
what suits their organization best and based on the types of software they
develop.
 It is very important for the programmers to maintain the coding standards
otherwise the code will be rejected during code review.

Purpose of Having Coding Standards


The following are the purpose of having 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 errors easily.
 It promotes sound programming practices and increases the efficiency of the
programmers.

Coding Standards
Some of the coding standards are given below:
 Limited use of globals: These rules tell about which types of data that can
be declared global and the data that can’t be.
 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:
o Name of the module
o Date of module creation
o Author of the module
o Modification history
o Synopsis of the module about what the module does
o Different functions supported in the module along with their input
output parameters
o Global variables accessed or modified by the module
 Naming conventions for local variables, global variables, constants and
functions: Some of the naming conventions are given below:
o Meaningful and understandable variables name helps anyone to
understand the reason of using it.
o 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).
o It is better to avoid the use of digits in variable names.
o The names of the function should be written in camel case starting
with small letters.
o The name of the function must describe the reason of using the
function clearly and briefly.
 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:
o There must be a space after giving a comma between two function
arguments.
o Each nested block should be properly indented and spaced.
o Proper Indentation should be there at the beginning and at the end of
each block in the program.
o All braces should start from a new line and the code following the
end of braces also start from a new line.
 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.

Coding Guidelines
Coding guidelines give some general suggestions regarding the coding style that to be
followed for the betterment of understandability and readability of the code.
Some of the coding guidelines are given below :
 Avoid using a coding style that is too difficult to understand: Code
should be easily understandable. The complex code makes maintenance and
debugging difficult and expensive.
 Avoid using an identifier for multiple purposes: Each variable should be
given a descriptive and meaningful name indicating the reason behind using
it. This is not possible if an identifier is used for multiple purposes and thus
it can lead to confusion to the reader. Moreover, it leads to more difficulty
during future enhancements.
 Code should be well documented: The code should be properly
commented for understanding easily. Comments regarding the statements
increase the understandability of the code.
 Length of functions should not be very large: Lengthy functions are very
difficult to understand. That’s why functions should be small enough to
carry out small work and lengthy functions should be broken into small ones
for completing small tasks.
 Try not to use GOTO statement: GOTO statement makes the program
unstructured, thus it reduces the understandability of the program and also
debugging becomes difficult.

Advantages of Coding Guidelines


 Coding guidelines increase the efficiency of the software and reduces the
development time.
 Coding guidelines help in detecting errors in the early phases, so it helps to
reduce the extra cost incurred by the software project.
 If coding guidelines are maintained properly, then the software code
increases readability and understandability thus it reduces the complexity of
the code.
 It reduces the hidden cost for developing the software.
Naming Conventions in Programming

What are Naming Conventions?

Naming conventions are a set of rules and guidelines that are used to define
the names of variables, functions, classes, and other entities in
programming. These conventions help ensure that the code is readable,
maintainable, and less prone to errors.

Naming conventions act as a universal language among developers,


facilitating better understanding and collaboration within teams.

Importance of Naming Conventions

1. Readability: Clear and descriptive names make the code easier to


understand. When names accurately describe their purpose, other
developers (and your future self) can quickly grasp the functionality
without needing extensive comments or documentation.
2. Maintainability: Consistent naming reduces confusion and makes it
easier to update and refactor code. When names follow a standard
pattern, finding and modifying the relevant parts of the code becomes
simpler.
3. Collaboration: In a team setting, naming conventions ensure that
everyone follows the same standards, leading to a cohesive codebase.
This consistency helps new team members get up to speed faster and
reduces the risk of misunderstandings.
4. Error Reduction: Well-named variables and functions can help
prevent errors. For instance, using clear and distinct names for
different entities reduces the likelihood of accidentally using the wrong
variable or function.
Common Naming Conventions

Below are some of the commonly used naming conventions in programming,


along with examples:

1. Camel Case:
 Used for naming variables, functions, and methods in many
programming languages like JavaScript, Java, C#, and Python.
 Provides a readable and brief way to name identifiers without spaces
or separators.
 In camel case, you start a name with a small letter. If the name has
multiple words, the later words will start with a capital letter.
 Example: calculateArea, getUserDetails, firstName, lastName.

2. Pascal Case:
 Commonly used for naming classes, structs, and interfaces in object-
oriented programming languages like C#, Java, and TypeScript.
 Helps distinguish classes and structs from other entities in the code.
 In pascal case, you start a name with a capital letter. If the name has
multiple words, the later words will also start with a capital letter.
 Example: UserProfile, HttpClient

3. Snake Case:
 Widely used for naming file names, directories, and variables in
languages like Python, Ruby, and Rust.
 Improves readability, especially when multiple words are used, and
makes it easy to differentiate words.
 In the camel case, you start the name with a small letter in the snake
case. If the name has multiple words, the later words will start with
small letters and you use an underscore (_) to separate the words.
 Example: user_profile, product_details, max_retries, first_name and
last_name.

4. Kebab Case (also known as Spinal Case):


 Primarily used for naming HTML attributes, CSS classes, and
component names in web development frameworks like React and
Angular.
 Provides a clear separation between words and is compatible with
HTML and CSS syntax.
 Kebab case is similar to snake case, but you use a hyphen (-) instead
of an underscore (_) to separate the words.
 Example: first-name and last-name.

5. Upper Case:
 Used for naming constants in many programming languages like C++,
Java, and JavaScript.
 Clearly distinguishes constants from variables and other identifiers,
making the code more self-documenting.
 Example: MAX_VALUE, DEFAULT_TIMEOUT, PI

6. Hungarian Notation:
 Prefixes variable names with one or more lowercase letters indicating
the data type or other information about the variable.
 While it was popular in the past, it is now generally discouraged as it
can make code harder to read and maintain, especially with modern
IDEs that provide type information.
 Example: strName (string), iAge (integer), bIsActive (boolean)
7. Train Case (also known as Hyphen-Separated Case):
 Words are separated by hyphens, and the first letter of each word is
capitalized.
 Sometimes used for naming database tables or columns, especially in
legacy systems or when interoperating with systems that have naming
conventions restrictions.
 Example: User-Profile, Product-Details

8. Flat Case:
 All letters are lowercase, and words are usually concatenated without
separators.
 Used in some programming languages or frameworks that follow a
minimalist naming style or have specific naming guidelines.
 Example: myvariable, calculatesum, persondetails

Best Practices for Naming Conventions

1. Be Descriptive: Choose names that clearly describe the purpose of


the variable, function, or class. Avoid vague names like temp or data.
2. Keep it Short but Meaningful: While names should be descriptive,
they should also be concise. Striking a balance between brevity and
clarity is key.
3. Use Pronounceable Names: Names that are easy to pronounce
improve readability and communication within a team
(e.g., userID instead of usrID).
4. Avoid Abbreviations: Unless they are well-known and universally
understood, avoid using abbreviations. For example,
use calculateAverage instead of calcAvg.
5. Consistent Use of Naming Conventions: Once a convention is
chosen, it should be applied consistently throughout the codebase.
Mixing different styles can lead to confusion.
6. Avoid Using Reserved Keywords: Ensure that your names do not
conflict with reserved keywords in the programming language you are
using.
7. Contextual Naming: Use names that provide context about their
usage. For example, userList is more informative than just list.
8. Refactor When Necessary: Don’t hesitate to rename variables,
functions, or classes if you find a better name that enhances clarity
and readability.

You might also like