3 ms·
`val` is never an appropriate name for a variable because it tells you nothing at all about what the variable contains.
by j_jochem 9y ago
`val` is never an appropriate name for a variable because it tells you nothing at all about what the variable contains.
- flamedoge 9y agonever is strong requirement. maybe it doesn't need to tell. Int::add(int val)
- rhizome 9y agoI tend to use `num` in those spots.
- tomc1985 9y agoExcept when iterating through a hash, where 'key' and 'val' are my go-to names for stuff
- h1d 9y agoJust use 'value'. Only you can be sure of shortened words even if it looks obvious. Not good in a team. I never understood people who shorten words to make the program look cryptic. Maybe it was someone who taught you how to program had it that way or somehow it makes you feel your program looks cooler if it looks more cryptic.
- eropple 9y agoAgreed - at that point, I don't know why you wouldn't just (consistently) use 'k' and 'v'. 'val' adds some weird cognitive load, to me.
- flamedoge 9y agoI dunno, I am horizontally challenged. I like condensed code style like minimizing words, 2 spaces for indent, etc.
- tomc1985 9y ago'value' is frequently a keyword or property on objects, and has specific meaning in a lot of contexts. For names, IMO 'k' and 'v' also work, but I find an abundance of single-letter variables hard to read. key and val it is.
- nobleach 9y ago`val` isn't the variable name, it's the declaration. I'd imagine `val multiplier = 2' to make perfect sense. `var` likewise doesn't connote any truly valuable information other than the label for the memory location that follows is mutable.