Choosing between naming conventions and semantics with Node.js module imports

Viewed 1228

When importing modules in Node.js, it's fairly common (and greatly aids in readability) to use capitalization when importing classes and camel case when importing anything else:

let Transform = require('stream').Transform;
let util = require('util');
let fs = require('fs');

And yet, imported modules really should be constants, as it makes little sense to allow the value of a function or class from an imported module to change:

const Transform = require('stream').Transform;
const util = require('util');
const fs = require('fs');

But naming conventions would dictate that constants should always use all caps and underscores:

const PI = 3.14159265358979;
const AVOGADRO_NUMBER = 6.02214086e23;

So therein lies a conflict: It is typically semantically confusing to use all caps and underscores in naming imported modules, and yet it is semantically illogical to not make an imported module, class, or function a constant.

So either imported modules should use all caps and underscores, sacrificing some readability and knowledge of which role (function/variable or class) is filled by the imported module:

const RIEMANN_ZETA = require('riemann-zeta');
let nonTrivialZero = RIEMANN_ZETA(s);

Or imported modules should use camelCase or capitalization based on role, sacrificing congruence between constant status and notation:

const riemannZeta = require('riemann-zeta');
let nonTrivialZero = riemannZeta(s);

Or imported modules should be imported as non-constant, maintaining all naming conventions but sacrificing logical use of modules as immutable once imported:

let riemannZeta = require('riemann-zeta');
let nonTrivialZero = riemannZeta(s);

Which makes the most sense?

0 Answers
Related