3 ms·
If I'm iterating over a hash, it seems natural to use "k" and "v" or "key" and "value". Do other people use different names for these?
by bshimmin 10y ago
If I'm iterating over a hash, it seems natural to use "k" and "v" or "key" and "value". Do other people use different names for these?
- dragonwriter 10y agoYeah, there's lots of places where "value" is a well-accepted, clear, domain-specific language for a specific component of a construct, and thus using "value" is an excellent variable name. (Similarly with data: lots of times, I've seen specs where a composite structure had a part called "data". Whether or not that is good naming in the spec, if I'm implementing the spec, using "data" for the element in the program corresponding to that part of the composite in the spec is clearly the exactly right thing to do.)
- bobwaycott 10y agoI typically keep it consistent, using either k,v or key,val (I like the symmetry of var letter length in a weird OCD kind of way).