T
16

Why does nobody talk about the chaos of mixed-up variable names?

I was writing a simple calculator in JavaScript and spent ages wondering why the output was always wrong. Turns out I had named two variables 'sum' and 'total' but kept using them backwards, and a quick print statement saved my sanity.
3 comments

Log in to join the discussion

Log In
3 Comments
lily_sullivan82
I once stared at sum versus total for two hours...
1
charlie_stone72
Actually, in math terms they're pretty much the same thing. Grant's bill example is mixing in extra stuff like a tip, which isn't the math itself. Honestly, getting stuck on that for hours sounds totally relatable though.
6
grant779
grant7791mo ago
Well, lily_sullivan82, those two hours might have been useful. Sum usually refers to added numbers, but total is the final count after all factors. For example, on a bill, the sum of prices isn't the total if you include a tip. Get it wrong and your math is off. It's dull stuff, but so is most careful work.
1