3 ms·
> Regarding variable names strongly consider keeping the first variable name which comes to your head. It is simple, straightforward. Strongly disagree with th
by kypro 3y ago
> Regarding variable names strongly consider keeping the first variable name which comes to your head. It is simple, straightforward.
Strongly disagree with this. Variable naming is so important if you want to write code others can understand.
The first name I come up with tends to be overly verbose/specific or too general. Variables named "count" are a good example of a name that's too general requiring a developer new to the code to ask, what is being counted? While "userUniqueVisitCount" might be too verbose when given the context perhaps, "visitCount" would be fine.
Just little things like that can really help a developer understand what's going on quickly.
Code structure is super important too though... If you're making too many abstractions it generally forces your variables and methods to be abstract and meaningless too. Your names should hint at this when there is a problem. If you find you need to use extremely verbose names to explain what a variable or method is doing, you likely have something structurally wrong with your code.
- ilrwbwrkhv 3y agoI have gone back and forth on this many times in my career, but the word which comes to your head in the second or third attempt is usually the max depth you should search for. Chances are when you think of this again, the same word will come to your head making it easy to grep.
- mid-kid 3y agoJust "visits", unless you use that name for something else. I find code that relies excessively on catch-all terms to be very tacky.
- whstl 3y agoThese things depend heavily on context. "count" is better and less redundant than "visitCount" when it is a field or method of a "Visits" or "VisitList" class, for example, and nothing else is being counted. Or as a variable: "count" is also good enough in a small function with a few lines, that only concerns itself with a single type of item being counted. If there are multiple things being counted in the same context, by all means specify them. I get the good intention, but in the end those guidelines get in the way of good code more than they really help. The "no methods bigger than N lines" for example (popular with some linters) cause more damage than improvements.