Skip to content

Coding Conventions

ehzan edited this page Feb 9, 2023 · 17 revisions

Readability of Code

In computer programming, readability refers to the ease with which a human reader can comprehend the purpose, control flow, and operation of source code. Code readability is essential because programmers spend the majority of their time reading, trying to understand, reusing, and modifying existing source code, rather than writing original source code.[1] It affects other aspects of software quality, most importantly maintainability. Many factors, having little or nothing to do with compiling and executing the code, contribute to readability.

Programs must be written for people to read, and only incidentally for machines to execute.
— Harold Abelson

Coding Conventions [2]

Coding conventions are a set of guidelines that are designed to help improve code readability and make software maintenance easier. Common coding conventions usually cover the following areas:

Some good samples are C# Coding Conventions, PEP (Python Enhancement Proposals), and Sun Microsystems' Code Conventions for Java.

Coding conventions are only applicable to human maintainers and peer reviewers. They are not enforced by compilers. Conventions may be formalized in a documented set of rules that an entire team or company follows, or may be as informal as the habitual coding practices of an individual.

According to Sun Microsystems[3] code conventions are important to programmers for a number of reasons:

  • 80% of the lifetime cost of a piece of software goes to maintenance.
  • Hardly any software is maintained for its whole life by the original author.
  • Code conventions improve the readability of the software, allowing engineers to understand new code more quickly and thoroughly.
  • If you ship your source code as a product, you need to make sure it is as well packaged and clean as any other product you create.

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
— Kent Beck

Code Refactoring [4]

Refactoring refers to a software maintenance activity where source code is modified to improve readability or improve its structure without changing its external behavior. Any change in the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functional attributes can be considered refactoring.

Refactoring is usually motivated by noticing a code smell and is done to bring the source code into conformance with the team's coding conventions. Common refactoring activities are changing identifier names, breaking large methods or functions into smaller ones, and moving methods or whole classes. Failure to perform refactoring can result in accumulating technical debt, on the other hand, refactoring is one of the primary means of repaying technical debt.


1. https://en.wikipedia.org/wiki/Computer_programming#Readability_of_source_code
2. https://en.wikipedia.org/wiki/Coding_conventions
3. https://www.oracle.com/java/technologies/javase/codeconventions-introduction.html
4. https://en.wikipedia.org/wiki/Refactoring

Clone this wiki locally