DEV Community

Discussion on: Clean Code Part 1: Meaningful Names

Collapse
jonrandy profile image
Jon Randy

Single letter variable names are very useful as loop counters, or in small utility functions where the functionality is obvious. They have their place and should not be discounted

Collapse
tanisha03 profile image
Tanisha Sabherwal Author

Yes, using single letter variables in loops is justifiable because its standardised but single or double letter names using in functions or variables which are spread across files should be avoided because of it cannot be searched easily. Even for utility functions, names should be clear enough to understand what the function does.

Collapse
jonrandy profile image
Jon Randy • Edited on

Sorry, but I disagree. This function gains nothing by 'meaningfully' naming the parameter:

const isItemRed = i => i.colour == 'red'
Enter fullscreen mode Exit fullscreen mode

I've been writing code for about 38 years - 27 of those professionally. Experience has taught me that the best code is succinct and clear. It really isn't necessary to give everything a meaningful name - especially when the context makes it perfectly obvious what things are, and what they do.

Overly verbose code is exhausting to read, and totally unnecessary

Thread Thread
tanisha03 profile image
Tanisha Sabherwal Author

Sorry, if I came across as unclear or rather misunderstood your point. But I totally agree to what you just mentioned. What I was referring to was the name of the function and not the parameters, in this case being isItemRed.