3 ms·
I think in a huge number of cases it is possible to objectively say that a change made the code better. I see those very often when consulting at companies. Ju
by tuwtuwtuwtuw 6y ago
I think in a huge number of cases it is possible to objectively say that a change made the code better. I see those very often when consulting at companies.
Just to give you an example (which I ran across last week), if you have some code handling a cart in an e-commerce site and you need to keep track of the number of items in this cart would you prefer the variable name "totalAmount" or "quantity". There's also a variable named "totalAmountIncludingTax" which holds the monetary amount to pay for the items in the cart.
- mattgreenrocks 6y agoThe accumulation of many small wins in things like naming is often much more helpful than full-on overhauls. But you have to be willing to do the small, seemingly inconsequential things to build up to those.
- amw-zero 6y agoHow do you know that one name is better than the other? I see renames all the time where I preferred the original version.
- tuwtuwtuwtuw 6y agoIf you have a variable representing the length of an array containing user accounts, would you prefer the name "length" or "price"?
- amw-zero 6y agoThis isn’t a relevant argument. The fact that you constructed an absurd scenario and there’s a clear winner in it does not imply that there is always a clear winner. In fact, my experience is that in the majority of times there is not a clear winner, and terms get completely overloaded or used imprecisely. So, again, your absurd scenario proves to be quite a weak argument when you consider the scope of the whole problem.
- tuwtuwtuwtuw 6y agoThen I don't think I see the type of meaningless variable renames you are talking about. I do see variable names about as bad as in my example though, and I see them being fixed. They typically arise from some copy/paste where someone wanted similar logic but forgot to rename a variable. I don't see people renaming from say numberOfItems to noOfItems or similar, if that's the type of renames you're referring to. Can you give an example of a rename you are seeing?