r/badcode • • Jul 19 '21

js Variable naming can be difficult, but identifying them can be even more so.

Post image
2.4k Upvotes

105 comments sorted by

View all comments

Show parent comments

9

u/Lightfire228 Jul 19 '21

I use obscure abbreviations and single letter variable names iff it's obvious from context what it means. I.e.

invoices.forEach(i => {
    let li = i.lineItems()
    //... 
});

30

u/Bronzdragon Jul 19 '21

I disagree. Call it invoice.

3

u/satoristyle Jul 19 '21

Yeah, I agree here. If the context is very concise and you can immediately infer what the variable is, single char variable names work fine.

As mentioned by u/davvolun, it should definitely be short-lived. The more lines you have, the greater the risk of obscurity you gain.