Skip to content

Code Conventions

Harman Lamba edited this page Aug 24, 2020 · 2 revisions

Commenting Conventions

  • Comments should only be written as necessary - this article does a good job of explaining when to / not use comments - "Good code comments explain why things are done, not what is done".
  • Place the comment on a separate line, not at the end of a line of code.
  • Begin comment text with an uppercase letter. End comment text with a period.
  • Insert one space between the comment delimiter (//) and the comment text, as shown in the following example:
πŸ‘Ž //I am bad at comments
πŸ‘ // I will write good comments

Layout Conventions

  • Use default code editor (with smart indenting)
  • Write only one statement per line
  • Add at least one blank line between method definitions and property definitions.
  • Use parentheses to make clauses in an expression apparent, as shown in the following code.

C# Conventions

For C# development, coding conventions defined by Microsoft C# guidelines will be followed.

JS Conventions

For React development, coding conventions defined by Google's styling guide will be followed.

Components

Whenever possible, functional components with an arrow function will be used.

πŸ‘Ž class Component extends React.Component {}  
πŸ‘Ž function Component() {}  
πŸ‘ const Component = () => {}  

Functions

Functions will be defined using arrows

πŸ‘Ž function DoSomething() {}  
πŸ‘ const DoSomething = () => {} 

Naming Conventions

Pascal Case

  • Custom Components: const MyComponent = () => {}

  • Component/CSS Files: my-component.js

Camel Case

  • Fields: let isEmpty = true

  • Functions: const onClick = () => {}

  • Normal JavaScript files: helper-functions.js

Comments

  • /** **/ Higher level comments
  • // In line comments

Strings

  • Single quotes, not double: import React from 'react'

Redux

Thunk

  • Dispatching: The action type must always be dispatched. If the data being dispatched is an object containing two or more properties, the data should be wrapped in payload. Otherwise, if the data being dispatched is one data type (e.g. a string array) then it can be dispatched as is.