Joe Honton
1 min readJun 8, 2020

--

John was talking about using classes with nothing but static methods, as namespaces. He thinks that's a bad idea.

I didn't see eye-to-eye with him on that because ECMAScript doesn't have namespaces, and I find them useful in keeping my code organized.

Michael's suggestion is to keep function names simple. That doesn't help me very much when I have several hundred utility functions and I can't remember their names or signatures. So my solution is to compartmentalize them into groups. For example, a file may start with this:

import StrUtils      from './utils/str-utils'
import HeaderUtils from './utils/header-utils'
import DatabaseUtils from './utils/database-utils'

And the body of the file may use these generic helper functions something like this:

let str = `"quoted string"`;
let cleanStr = StrUtils.removeQuotes(str);
let queryString = `%C2%A1Hola%2C%20mundo%21`;
let keyValuePairs = HeaderUtils.splitUrlEncodedValues(queryString);
let javascriptVar = `camelCaseVarName`;
let databaseName = DatabaseUtils.camelCaseToDash(javascriptVar);

This approach makes it clear to me where I can find the definition of each utility function and its cousins.

--

--

Joe Honton
Joe Honton

Written by Joe Honton

Princeps geographus, Read Write Tools

No responses yet