Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 17

Coding

Standard
SQL Coding Standards
 SQL (Structured Query Language) coding standards are a set of guidelines for
writing SQL code in a consistent and organized manner.

 They help to ensure that SQL code is clear, readable, and maintainable and make it
easier for developers to work together on large projects.

 Some common elements of SQL coding standards include:

1. Naming conventions: This involves using consistent and descriptive names for tables,
columns, indexes, and other elements of the database.

2. Indentation and white space: Proper indentation and use of white space can greatly
improve the readability of SQL code.
3. Comments: Comments should be used to explain the purpose of code and any non-
obvious logic.

4. Formatting: This includes guidelines for line length, use of blank lines, and placement
of parentheses.

5. Code organization: SQL code should be organized in a logical and easy-to-understand


manner.

6. Data types: Consistent use of data types for columns and variables in the database
should be followed.

7. Keywords: SQL keywords should be written in uppercase to make it easier to identify


them.
 Here is an example of SQL coding standards:
1.Naming conventions:
-- Table names should be written in snake_case
CREATE TABLE employees (
-- Column names should also be written in snake_case
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50)
);
-- Index names should be descriptive and include the table name
CREATE INDEX idx_employees_first_name
ON employees (first_name);

2.Indentation and white space:


-- Proper indentation should be used to improve readability
SELECT
first_name,
last_name
FROM
employees
WHERE
employee_id = 123;
3.Comments:
-- Use comments to explain the purpose of the code
SELECT
-- This is the first name column
first_name,
last_name
FROM
employees
WHERE
employee_id = 123;

4.Formatting:
-- Use consistent formatting for line length and blank lines
SELECT
first_name,
last_name
FROM
employees
WHERE
employee_id = 123;
5.Keywords:
-- SQL keywords should be written in uppercase
SELECT
FIRST_NAME,
LAST_NAME
FROM
EMPLOYEES
WHERE
EMPLOYEE_ID = 123;

 These are just a few examples of the elements that can be included in SQL coding
standards.
 By following these and other guidelines consistently, SQL code becomes more
readable, maintainable, and easier to work with for teams of developers.
Java Coding Standards
 Java Coding standards refer to a set of guidelines for writing and formatting Java
code that make it easier to maintain and understand.
 These standards help to ensure consistency in the codebase and improve its
readability, maintainability, and overall quality.
 Some common elements of Java coding standards include:
1. Naming conventions: This includes conventions for naming variables, classes, methods,
and other elements of the code. For example, class names should be written in
PascalCase, while variable names should be written in camelCase.
2. Indentation and white space: Proper indentation and use of white space can make code
more readable and understandable.
3. Comments: Comments should be used to explain the purpose of code and any non-
obvious logic.

4. Formatting: This includes guidelines for line length, use of blank lines, and placement
of curly braces.

5. Code organization: This includes guidelines for organizing code into classes,
methods, and packages.

6. Exception handling: Guidelines for handling exceptions and error conditions should
be followed.

7. Code documentation: Java code should be documented using JavaDoc to provide


information about classes, methods, and variables for future reference.
 Here is an example of coding standards
1.Naming conventions:
// Class names should be written in PascalCase
public class Employee {
// Variables should be written in camelCase
private String firstName;
private String lastName;

// Method names should also be written in camelCase


public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getFirstName() {


return firstName;
}
}
2.Indentation and white space:
// Proper indentation should be used to improve readability
if (x > 0) {
System.out.println("x is positive");
} else {
System.out.println("x is not positive");
}
3.Comments:
// Use comments to explain the purpose of code
int x = 5; // Declare and initialize x

// Use JavaDoc comments to document classes and methods


/**
* This is the Employee class
*/
public class Employee {
/**
* This method returns the first name of the employee
* @return the first name
*/
public String getFirstName() {
return firstName;
}
}
4.Formatting:
// Use consistent formatting for line length and blank lines
public class Employee {
private String firstName;
private String lastName;

public void setFirstName(String firstName) {


this.firstName = firstName;
}

public String getFirstName() {


return firstName;
}
}
5.Code organization:
// Organize code into classes and methods in a logical manner
public class Employee {
private String firstName;
private String lastName;

public void setFirstName(String firstName) {


this.firstName = firstName;
}

public String getFirstName() {


return firstName;
}
}

public class Address {


private String street;
private String city;
private String state;

// ...
}
C# .Net Coding Standards
 C# .Net coding standards are a set of guidelines and best practices that developers should
follow while writing code in C# .Net.

 These standards help to maintain consistency, readability, and maintainability of the


codebase.

 Some of the commonly followed coding standards in C# .Net include:

1. Naming conventions: names of variables, classes, methods, and other code elements should be
descriptive and follow a consistent naming scheme, such as using PascalCase for class names,
method names, and properties names and camelCase for Variable names.

2. Formatting: code should be well-formatted, indented, and spaced to make it easier to read and
understand.
3. Commenting: meaningful comments should be added to explain the purpose of the
code and provide context.

4. Error handling: appropriate error handling mechanisms should be in place to catch


and handle exceptions, such as using try-catch blocks.

5. Security: the code should be secure and not vulnerable to common security threats
such as SQL injection, cross-site scripting, and others.

 Here's an example of coding standards in C#:


// Naming Conventions
// Class names should start with a capital letter and use PascalCase
public class Employee {
// Private fields should start with an underscore and use camelCase
private int _employeeId;
private string _employeeName;

// Public properties should start with a capital letter and use PascalCase
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }

// Method names should start with a verb and use PascalCase


public void GetDetails() {
// Variable names should start with a lowercase letter and use camelCase
int age = 25;

// Code formatting
if (age > 18) {
// Commenting
// This block of code is used to display the employee's details
Console.WriteLine("Employee ID: " + EmployeeId);
Console.WriteLine("Employee Name: " + EmployeeName);
Console.WriteLine("Age: " + age);
}

// Error handling
try {
// Code that may throw an exception
}
catch (Exception ex) {
// Log the exception
Console.WriteLine("Error: " + ex.Message);
}
}
}
Queries

You might also like