• This repository has been archived on 01/Jan/2022
  • Stars
    star
    164
  • Rank 230,032 (Top 5 %)
  • Language
  • Created over 13 years ago
  • Updated about 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Idiomatic, widely-used code style guides for various programming languages.

Code style guides

It is good to write code idiomatically in each language and not bring, for example, Python experience to JavaScript. The doc describes idiomatic & widely-used by the languages communities styles of coding.

Table of contents

All languages

  • Readability counts.
  • Be consistent.
  • Don't repeat yourself.
  • Flat is better than nested.
  • Beautiful is better than ugly.
  • Simple is better than complex.
  • Add blank line to the end of every file.
  • Limit lines to 80 characters.

CoffeeScript

  • Follow polarmobile/coffeescript-style-guide.
  • Follow TomDoc as a documentation specification.
  • Write code in a functional style. Less side effects == less errors. Examples:
    • Use array methods (Array::forEach, Array::filter etc.) instead of for..in loops. for loops don't create scope so it's easier to introduce bugs. Object.keys() are preferred to for..of.
    • Avoid break-s and continue-s.
    • Try to not redefine once defined vars where it's possible.

LiveScript

Ruby

Python

JavaScript

  • Two spaces indentation.

  • Single quotes are preferred over double. Reason: HTML uses double quotes.

  • Use void 0 instead of undefined, because undefined could have been redefined.

  • Write code in functional style with minimum side effects. See coffeescript section for more info.

  • Don't use function statements. Instead, create anonymous functions and assing them to vars for consistency with other vars.

    // No
    function doThing(a, b) {return a * b;}
    
    // Yes
    var doThing = function(a, b) {return a * b;};
  • Avoid global vars where you can. If you use them, specify it explicitly.

    window.globalVar = ...;
  • Use one var per variable.

    var a = 5;
    var b = 6;
    var $this = $(this);
    // Exception.
    var a, b, c, d, $this;
  • Use '_this' variable to push current context to the closures.

    var a = {
     b: function() {
       var _this = this;
       $(some).click(function(event) {
         _this.c();
       });
     }
    };
  • Event callback should name event data variable as 'event', not 'e' etc.

    $('#item').click(function(event) {
      $.storage.set('item', $(this).val());
    });
  • Do not use quotes in object keys.

    // No
    {'a': 'testtest'}
    
    // Yes
    {a: 'testtest'}
  • Use '===' for comparing instead of '=='. JavaScript is weakly typed language, so 5 == '5'. This ambiguity could lead to hard-to-find bugs.

    if (a === 5) {
      ...
    }
    if ($(this).val() === 'something') {
      ...
    }
    if (typeof a === 'undefined') {
      ...
    }
    
    // Exception: this compares both to 'null' and 'undefined'.
    if (item == null) {
    
    }
  • Cache list length into a variable. You could afford 2x loop performance increase with this on some browsers.

    for (var i = 0, length = someList.length; i < length; i++) {
      doSomething(someList[i]);
    }
  • Avoid bitwise operators if possible.

  • Avoid with & implied typecasting.

HTML

  • Two spaces indentation.

CSS

  • Two spaces indentation.

  • Use lowercase hex colors (e.g. #fff) instead of color names (e.g. white).

  • Use * {box-sizing: border-box;}.

  • Use hyphens between class names, not camelCase or under_scores.

  • Use only classes for styling most of the time (no #ids, elems etc).

  • Don't use inline styling.

  • Profile your selectors with webkit inspector.

  • Use tree-style indentation.

    .signup-page {
      background: #0d0; }
      .signup-button {
        padding: 10px;
        background-image: url("../img/signup.png"); }
    
    /* This looks cool if you use Stylus etc. */
    .chat-page {
      font-size: 0.9em; }
      .identity {
        margin-bottom: 20px; }
        .identity-profile {
          height: 4em; }
        .identity-nickname {
          float: left;
          width: 165px; }
        .identity-avatar {
          float: right; }
        .identity-updates {
          margin-top: 10px; }
        .identity-status {
          height: 30px; }
        .identity-current-mood {
          padding-left: 5px; }
        .identity-button {
          float: right; }
  • Use this sequence of properties

    .item {
      position: static;
      z-index: 0;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
    
      display: block;
      visibility: hidden;
      float: none;
      clear: none;
      overflow: hidden;
      clip: rect(0 0 0 0);
    
      box-sizing: content-box;
      width: auto;
      min-width: 0;
      max-width: 0;
      height: auto;
      min-height: 0;
      max-height: 0;
      margin: 0;
      padding: 0;
    
      table-layout: fixed;
      empty-cells: show;
      border-spacing: 0;
      border-collapse: collapse;
      list-style: none;
    
      font: 1em sans-serif;
      font-family: Arial, sans-serif;
      font-size: 1em;
      font-weight: normal;
      font-style: normal;
      font-variant: normal;
    
      content: "";
      cursor: default;
      text-align: left;
      vertical-align: top;
      line-height: 1;
      white-space: normal;
      text-decoration: none;
      text-indent: 1;
      text-transform: uppercase;
      letter-spacing: 1;
      word-spacing: normal;
    
      opacity: 1;
      color: #d00;
      text-shadow: 5px 5px 5px #d59;
      border: 1px solid #d00;
      border-radius: 15px;
      box-shadow: inset 1px 0 0 #fff;
      background: #fff url("../i/bg.png") no-repeat 0 0; }

Objective-C

Scala

Erlang

  • Follow the official Programming Rules and Conventions.
  • Use types and function specifications and discrepancy analysis.
  • Avoid if-s, throw-s and catch-es whenever possible.

Git

  • Keep your repository clean. Don’t commit big files unless they absolutely require git. Even in this case, prefer storing all big files in a separate submodule. That’s because git history can become very big and it will be pain for others to use the repo.

  • Structure your commit message like this:

    One line summary (less than 50 characters)
    
    Longer description (wrap at 72 characters)
    
  • Commit summary:

    • Less than 50 characters
    • What was changed
    • Imperative present tense (fix, add, change): ("Fix bug 123.", "Add 'foobar' command.", "Change default timeout to 123."). Commits in past tense look weird to other developers e.g. the change ain’t happened yet and there’s question like “What will applying the patch do?” and you answer to this shit like “it will remove utils.wrapMethod.”. Also it’s official git style
    • End with period
  • Commit description:

    • Wrap at 72 characters
    • Why, explain intention and implementation approach
    • Present tense
  • Commit atomicity:

    • Break up logical changes
    • Make whitespace changes separately
  • Branch naming:

    • Use hyphens as word separator.
    • Use namespaces, for example,
      • topics/topic-name namespace every time you want to create a pull request and just in everyday. Use hyphens between words. Examples: topics/fix-fs-utils, topics/add-reddit-button.
      • versions/x.y namespace for supporting old versions. Examples: versions/1.0, versions/2.1.

License

The MIT License (MIT)

Copyright (c) 2013 Paul Miller (http://paulmillr.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

chokidar

Minimal and efficient cross-platform file watching library
JavaScript
10,957
star
2

encrypted-dns

DNS over HTTPS config profiles for iOS & macOS
3,316
star
3

es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
JavaScript
3,114
star
4

dotfiles

Colourful & robust configuration files and utilities for Mac, Linux & BSD
Shell
1,199
star
5

exoskeleton

Faster and leaner Backbone for your HTML5 apps
JavaScript
880
star
6

noble-secp256k1

Fastest 4KB JS implementation of secp256k1 signatures and ECDH
JavaScript
757
star
7

noble-curves

Audited & minimal JS implementation of elliptic curve cryptography.
JavaScript
675
star
8

noble-hashes

Audited & minimal JS implementation of hash functions, MACs and KDFs.
JavaScript
573
star
9

console-polyfill

Browser console methods polyfill.
JavaScript
436
star
10

noble-ed25519

Fastest 4KB JS implementation of ed25519 signatures
JavaScript
419
star
11

readdirp

Recursive version of fs.readdir with streaming api.
JavaScript
382
star
12

top-github-users

GitHub top-1000 generation script
CoffeeScript
259
star
13

ostio

Your open-source talks place.
JavaScript
247
star
14

noble-bls12-381

DEPRECATED: use noble-curves instead. Fastest JS implementation of BLS12-381.
TypeScript
202
star
15

noble-ciphers

Auditable & minimal JS implementation of Salsa20, ChaCha and AES
TypeScript
188
star
16

micro-eth-signer

Minimal library for Ethereum transactions, addresses and smart contracts.
JavaScript
187
star
17

scure-btc-signer

Audited & minimal library for creating, signing & decoding Bitcoin transactions.
JavaScript
151
star
18

qr

Minimal node.js & browser QR Code Pattern reader and generator
JavaScript
137
star
19

scaffolt

Dead-simple JSON-based scaffolder.
JavaScript
125
star
20

scure-bip39

Secure, audited & minimal implementation of BIP39 mnemonic phrases
TypeScript
119
star
21

scure-base

Secure, audited & 0-deps implementation of bech32, base64, base32, base16 & base58
JavaScript
114
star
22

async-each

No-bullshit, ultra-simple, 40-lines-of-code async parallel forEach / map function for JavaScript.
JavaScript
105
star
23

noble-post-quantum

Auditable & minimal JS implementation of public-key post-quantum cryptography
TypeScript
82
star
24

scure-starknet

Audited & minimal JS implementation of Starknet cryptography.
JavaScript
69
star
25

ostio-api

Your open-source talks place. Rails backend.
Ruby
69
star
26

tx-tor-broadcaster

CLI utility that broadcasts BTC, ETH, SOL, ZEC & XMR transactions through TOR using public block explorers
JavaScript
68
star
27

micro-sol-signer

Create, sign & decode Solana transactions with minimum deps
JavaScript
61
star
28

scure-bip32

Secure, audited & minimal implementation of BIP32 hierarchical deterministic (HD) wallets.
TypeScript
61
star
29

micro-web3

Typesafe Web3 with minimum deps: call eth contracts directly from JS. Batteries included
TypeScript
59
star
30

native-notifier

Use native system notifications in node.js without third-party libraries
JavaScript
56
star
31

chieftain

New generation imageboard. Built with Python / Django.
Python
49
star
32

micro-ordinals

Minimal JS library for ordinals and inscriptions on top of scure-btc-signer
JavaScript
43
star
33

micro-key-producer

Produces secure keys and passwords. Supports SSH, PGP, BLS, OTP and many other formats
TypeScript
43
star
34

loggy

Colorful stdstream dead-simple logger for node.js.
JavaScript
42
star
35

micro-ftch

Wrappers for built-in fetch() enabling killswitch, logging, concurrency limit and other features.
JavaScript
40
star
36

Array.prototype.find

Simple ES6 Array.prototype.find polyfill for older environments.
JavaScript
38
star
37

micro-packed

Define complex binary structures using composable primitives
TypeScript
38
star
38

micro-otp

One Time Password generation via RFC 6238
JavaScript
35
star
39

micro-bmark

Benchmark your node.js projects with nanosecond resolution.
JavaScript
34
star
40

pushserve

Dead-simple pushState-enabled command-line http server.
JavaScript
32
star
41

LiveScript.tmbundle

A TextMate, Chocolat and Sublime Text bundle for LiveScript
Python
31
star
42

jage

age-encryption.org tool implementation in JavaScript
TypeScript
29
star
43

read-components

Read bower and component(1) components
JavaScript
28
star
44

Array.prototype.findIndex

Simple ES6 Array.prototype.findIndex polyfill for older environments.
JavaScript
28
star
45

mnp

My new passport
JavaScript
28
star
46

nip44

NIP44 spec and implementations of encrypted messages for nostr
C
26
star
47

github-pull-req-stats

Stats from GitHub repos about accepted / closed pull requests.
JavaScript
25
star
48

micro-aes-gcm

0-dep wrapper around webcrypto AES-GCM. Has optional RFC 8452 SIV implementation.
JavaScript
25
star
49

steg

Simple and secure steganography
TypeScript
23
star
50

micro-password-generator

Utilities for password generation and estimation with support for iOS keychain
TypeScript
18
star
51

tag-shell

Use ES6 template tags for your node.js shell commands.
JavaScript
17
star
52

papers

Papers i've read and / or wanted to save
17
star
53

micro-should

Simplest zero-dependency testing framework, a drop-in replacement for Mocha.
JavaScript
17
star
54

noble-ripemd160

Noble RIPEMD160. High-security, easily auditable, 0-dep, 1-file hash function
TypeScript
17
star
55

bls12-381-keygen

BLS12-381 Key Generation compatible with EIP-2333.
TypeScript
16
star
56

micro-promisify

Convert callback-based JS function into promise. Simple, 10LOC, no deps.
JavaScript
16
star
57

micro-base58

Fast and beautiful base58 encoder without dependencies.
TypeScript
15
star
58

micro-rsa-dsa-dh

Minimal JS implementation of older cryptography algorithms: RSA, DSA, DH.
TypeScript
15
star
59

lastfm-tools

Last.FM data reclaimer (backuper, helper and analyzer).
Ruby
14
star
60

fetch-streaming

Simple XMLHTTPRequest-based `fetch` implementation for streaming content.
JavaScript
14
star
61

micro-ed25519-hdkey

Minimal implementation of SLIP-0010 hierarchical deterministic (HD) wallets
JavaScript
14
star
62

unicode-categories

ECMAscript unicode categories. Useful for lexing.
12
star
63

noble.py

Noble cryptographic libraries in Python. High-security, easily auditable, 0-dep pubkey, scalarmult & EDDSA.
Python
11
star
64

argumentum

No-bullshit option parser for node.js.
JavaScript
8
star
65

trusted-setups

Easily access trusted setups in JS. Includes KZG / ETH
JavaScript
7
star
66

micro-es7-shim

No-bullshit super-simple es7 collections shim for Array#includes, Object.values, Object.entries
JavaScript
7
star
67

jsbt

Build tools for js projects. Includes tsconfigs, templates and CI workflows
JavaScript
7
star
68

eth-vectors

Comprehensive official vectors for ETH
JavaScript
7
star
69

micro-ff1

Format-preserving encryption algorithm (FPE-FF1) specified in NIST Special Publication 800-38G.
TypeScript
6
star
70

backup

Backup of all my projects in a single signed file
JavaScript
6
star
71

quickly-copy-file

Quickly copy file from one path to another. No bullshit, ultra-simple, async and just one dep.
JavaScript
6
star
72

microtemplates

John Resig's micro-templates aka underscore templates. No-bullshit and small
JavaScript
6
star
73

popular-user-agents

Regularly updated list of popular user agents aka browser versions
JavaScript
6
star
74

paulmillr.github.io

JavaScript
5
star
75

roy.tmbundle

Roy TextMate, Chocolat & Sublime Text 2 bundle
5
star
76

qr-code-vectors

QR Code test vectors
Python
4
star
77

paulmillr

4
star
78

aesscr

Use AES-256-GCM + Scrypt to encrypt files.
JavaScript
3
star
79

universal-path

Cross-platform universal node.js `path` module replacement that works better with Windows
JavaScript
2
star
80

fcache

fs.readFile cache for node.js build systems & watchers
JavaScript
2
star
81

rn-bigint

Java
1
star
82

packed

https://github.com/paulmillr/micro-packed
1
star
83

unused-test-repo

JavaScript
1
star