Overclock.net - An Overclocking Community - View Single Post - Why is this correct? Looks to me like it shouldn't work.

View Single Post
post #8 of (permalink) Old 10-24-2017, 11:53 AM
herkalurk
Retired Staff
 
herkalurk's Avatar
 
Join Date: May 2010
Location: Portland, OR
Posts: 2,039
Rep: 69 (Unique: 58)
Order of operations means you do less lines of code.
Code:
meal = 44.5
tax = 6.75/100
mealtax = meal*tax
mealtotal=meal+mealtax

The above is the same result, more lines of code. Order of operations for math is a constant. It is the same regardless of language so they use it to make the code simpler. Without it code becomes longer and more drawn out, which isn't needed. I know it doesn't seem useful in 7 lines of code, but imagine 7000. If this were code on a website like this one with hundreds of hits per minute, reducing the amount of code to run, or amount of JS to transfer to the client by every byte helps.



herkalurk is offline