Consider sticking the “kind” of a variable in its name.
For example:
-
What is a JSON
response_bodyexactly — is it parsed (an AST) or raw (a byte sequence)? The variable namesraw_response_bodyandparsed_response_bodymake it clear what to expect from their contents. -
What is the unit? Is a
durationin millisecond, or seconds? I like to add the unit as a suffix, e.g.duration_ms.
This also applies to functions. For example: what is the argument to sleep() — is it milliseconds? seconds? nanoseconds? It’d be neater to have sleep_ns(10000) and not sleep(10000). Or, in a language that has named arguments: sleep(ns: 10000).
Units
Use SI unit abbreviations:
- For seconds, use
s, notsec. - For minutes, use
min, notm(the latter means meters).
What about the type system?
This has less to do with naming, but you can indeed also use the type system (tiny types) to avoid assigning a type representing second to a type representing milliseconds.
However, that is only effective in an IDE with a proper language server. You want to be able to look at a piece of code and tell the “kind” by observing it, rather than compiling or type-checking it (let alone running it).