Nothing Special   »   [go: up one dir, main page]

Coding Standards_for students

Download as pdf or txt
Download as pdf or txt
You are on page 1of 33

CODING STANDARDS

Prepared by: JOSELLE D. CONCEPCION, MIT


WHAT ARE CODING STANDARDS?
Coding standards, also known as coding guidelines or programming
style guides, are rules and conventions that developers follow when
writing code.
These guidelines cover aspects such as code formatting, naming
conventions, and file organization.
They ensure consistency and readability across the codebase,
regardless of who writes it.
BENEFITS OF 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.
STYLE GUIDES
A style guide is a set of rules defining how code should be written and
organized.
▪ Java: Java Style Guide https://google.github.io/styleguide/javaguide.html
▪ PHP: PSR-12 https://developer.wordpress.org/coding-standards/wordpress-coding-
standards/php/
• Python - PEP 8 – Style Guide for Python Code
• JavaScript - Airbnb JavaScript Style Guide
• C# - C# Coding Convention
• Go - Uber Go Style Guide
• C++ - C++ Core Guidelines
• PHP - PSR-12: Extended Coding Style
1
2

3
NAMING CONVENTIONS
Key aspect of coding standards that help ensure that code is
understandable, maintainable, and consistent across teams and
projects.
Proper naming conventions make code more readable and allow
others (or your future self) to understand its purpose and structure
at a glance.
Each language and development environment might have its own
conventions, but there are common practices that developers follow
across various programming languages.
GENERAL NAMING CONVENTIONS
CATEGORIES:
1.Variables: Descriptive names that reflect the role or purpose of
the variable.
2.Functions/Methods: Use verbs that describe the action or
purpose of the function.
3.Constants: Names that remain constant throughout execution.
4.Classes/Interfaces: Names representing objects, entities, or roles.
5.Files and Modules: File names reflect the purpose or content of
the file.
▪ 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:
▪ firstName / lastName

▪ Like in camel case, you start the name with a small letter in snake
case. If the name has multiple words, the later words will start with
small letters and you use a underscore (_) to separate the words.
▪ last_name / first_name
▪ Variables should have names
that clearly represent their
purpose or the data they
hold.Use camelCase (for
JavaScript, Java, C#, etc.) or
snake_case (for Python, Ruby)
depending on the language's
convention.
▪ Names in pascal case start with a capital letter. In case of the
names with multiple words, all words will start with capital letters.
▪ FirstName / LastName

▪ Kebab case is similar to snake case, but you use a hyphen (-)
instead of an underscore (_) to separate the words.
▪ first-name / last-name
FUNCTION/METHODS
▪ Functions should
describe the action
they perform, using
verbs or verb phrases.
It should be clear
what the function is
supposed to do just
by reading the name.
CONSTANTS
▪ Names that remain constant
throughout
▪ executionConstants are often
written in
SCREAMING_SNAKE_CASE or
PascalCase depending on the
language, and they should
represent values that do not
change during the program
execution.
CLASSES/INTERFACES
▪ Names representing objects,
entities, or roles
▪ Classes and interfaces should
use PascalCase, and they
should represent nouns or
entities in the application (e.g.,
objects, models, services).For
interfaces, the name should
describe a behavior or
capability.
FILE AND MODULES
▪ File names reflect the purpose or
content of the file
▪ File names should reflect the
content or purpose of the file.
Use snake_case (Python) or
kebab-case
(JavaScript/HTML/CSS), or
PascalCase if naming convention
allows.
SUMMARY: NAMING CONVENTIONS
INDENTION STYLES
K&R (KERNIGHAN & RITCHIE) STYLE
▪ Used in: C, C++, Java, JavaScript,
PHP, and many other languages.
▪ Key Point: The opening curly
brace { is placed on the same line
as the control statement (if, for,
function, etc.).
▪ Indentation: Typically 4 spaces
(or tabs) for each level of
indentation.
ALLMAN STYLE
▪ Used in: C#, some C/C++
projects.
▪ Key Point: The opening curly
brace { is placed on a new
line.
▪ Indentation: Typically 4
spaces.
WHITESMITHS STYLE

▪ Used in: Less common, but


some C or older projects.
▪ Key Point: The opening
curly brace { is indented to
align with the code block.
▪ Indentation: Typically 4
spaces
GNU STYLE
▪ Used in: GNU projects, primarily
in C.
▪ Key Point: The opening curly
brace { is placed on a new line,
but it is indented.
▪ Indentation: Typically 2 spaces
for block indentation, 2 spaces
for braces
HORSTMANN STYLE
▪ Used in: Java projects.
▪ Key Point: Similar to K&R,
but the else and the
closing curly brace are
placed on the same line.
▪ Indentation: Typically 4
spaces
PYTHON INDENTION STYLE
▪ Used in: Python (strictly
enforced by the language).
▪ Key Point: Python does not
use braces for code blocks.
Instead, indentation itself
is used to denote block
structure.
▪ Indentation: Typically 4
spaces (the standard in
Python)
LISP AND SCHEME STYLE
▪ Used in: Lisp, Scheme, and
other functional programming
languages.
▪ Key Point: Parentheses are
used to denote structure, and
indentation aligns the code
based on parentheses
nesting.
▪ Indentation: Typically 2
spaces.
INDENTION BEST PRACTICES
▪ Be consistent: Stick to a consistent number of spaces or tabs across the entire
project.
▪ Avoid mixing tabs and spaces: Mixing them can cause alignment issues,
especially in shared or cross-platform environments.
▪ Use spaces over tabs: Many style guides (Python’s PEP 8, Google Java Style
Guide, etc.) recommend using spaces because they ensure consistent appearance
across editors.
▪ Choose a standard for your team or project: Whether it's 2 or 4 spaces or tabs,
ensure the entire team follows the same indentation rules.
▪ Use automated tools: Linters (like ESLint for JavaScript, Pylint for Python) and
formatters (like Prettier, Black, or clang-format) can enforce indentation rules
automatically.
LANGUAGE-SPECIFIC
INDENTATION GUIDELINES
SUMMARY: INDENTION STYLES
ACTIVITY: GROUP
▪ Source Code (working)
▪ 2 Major Functions of your system
▪ Printed: Lesson Learned: Reflection on Coding Standards (cite examples
on your code)

ACTIVITY: INDIVIDUAL
▪ Create a CONTACT ME page/screen
▪ Identify the programming language you are going to use (ex. PHP & CSS)
▪ Write the whole code using proper coding standards
▪ Printed: Lesson Learned: Reflection on Coding Standards (cite examples on
your code)

You might also like