GithubHelp home page GithubHelp logo

khalyomede / code-convention Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 2 KB

Code conventions from my developper experience, gathered to remind me some best practice to keep the code scalable.

License: MIT License

code-convention's Introduction

Code convention

Set of guidelines I built from my developper experience. Gathered here to remind me how to keep my code scalable over time.

GitHub tag (latest SemVer) GitHub

Summary

Function naming

Function updating a boolean property

  • Use kebab case
  • Prefixed by enable or disable keywords to update a boolean value
class Response {
	static enableFetchingFromCache() {
		Response.fetchFromCache = true;
	}

	static disableFetchingFromCache() {
		Response.fetchFromCache = false;
	}
}

Function returning the value of a boolean property

  • Use kebab case
  • Name is positive
  • Suffixed by enabled
class Response {
	static fetchingFromCacheEnabled() {
		return Response.fetchFromCache === true;
	}
}

Function returning an array

  • Use kebab case
  • Prefixed by get
  • Plural
const Router {
    static _routes = [];

    static getRoutes() {
        return Router._routes;
    }
}

Function checking if has element

  • Use kebab case
  • Name positive
  • Prefixed by has
class Router {
	static _routes = [];

	static hasRoute(route) {
		return Router._routes.includes(route);
	}
}

Function removing an element

  • Use kebab case
  • Singular naming
  • Prefixed with remove
function removeNotification() {}

Function removing multiple elements

  • Use kebab case
  • Plural naming
  • Prefixed with remove
function removeImages() {}

If the subject is not pluralizable, suffix it with list:

function removeFluxList() {}

Variable naming

Array

  • Use kebab case
  • Plural
const repositories = ["rs-json", "browser-worker", "JUR"];
  • If not pluralizable, suffix it by list
const fluxList = ["incoming", "outgoing"];

Booleans

  • Use kebab case
  • Name positive
class Response {
	static fetchFromCache = true;
}

Looping on an array

  • Use kebab case
  • for ... of or foreach ... as variable loop should have singular form
const buttons = document.querySelectorAll("button");

for (const button of buttons) {
	// ...
}
  • regular for index name should be named index
for (let index = 0; index < 5; index++) {
	// ...
}

Number of items in an array

  • Use kebab case
  • Suffixed with count
const languages = ["php", "c#", "nodejs"];
const languagesCount = languages.length;

code-convention's People

Contributors

khalyomede avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.