Programming Proverbs 8: Avoid side effects

Computer Science Teacher
Computer Science Teacher - Thoughts and Information from Alfred Thompson

Programming Proverbs 8: Avoid side effects

  • Comments 1

Side effects are actions that change things outside of a procedure, function or method. Generally this happens when a procedure modifies a global variable. I'm tempted to suggest that this proverb might just as well be "avoid unnecessary global variables."





    e.g. a function called CalculatePrice takes a list of products as an argument... you would expect it just calculates the total price of all the products, but it goes and decrements the inventory count for each product as well... bad form, old chap.

Page 1 of 1 (1 items)