DEV Community

Discussion on: Abbreviations in code: yay or nay?

Collapse
 
jdforsythe profile image
Jeremy Forsythe • Edited

It really depends on the word and the context.

If the word has a well-known abbreviation (such as dept) then it can be okay, but I only typically abbreviate if I'm in an anonymous function or short-lived scope. The shortness of the variable name hints at the short life of the variable. In other words, I didn't take much time writing the name because it will be gone soon.

However for something that doesn't have a well known abbreviation, I typically use the first letter in these scenarios. And if a variable is meant to live longer or be more important, it gets a full name.

I will agree that it may take an extra few milliseconds if you want to know the name of the thing, but the name of variables in these contexts is of much less importance and it is more apparent to the reader that the variable is of less importance than the others around it which can't be done if you write full names for every variable.

Of course there are exceptions to every rule. If convention says to use ctx, like with Koa, then you use ctx.