Jesus's middle name is Hume! Caution: Some NSFW images within!

Page 3034 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

purbeast0

No Lifer
Sep 13, 2001
52,869
5,740
126
Why is it? If a function changes variables on a global basis, that aren't passed as arguments or return values, then clearly that will make it harder to follow what the program is doing. Makes sense to me, even if I guess it would be hard to stick to that rule in all situations.

Possibly I'm out-of-date and that 'functional programming' style fell out of favour (for practical reasons?) but in what way is it "totally" wrong?
It's totally wrong because you say functions shouldn't change values that aren't their return values. Functions can do whatever they are designed to do, which may be changing values that aren't their return values.

This looks like any old class you see in javascript. Where there is a local variable and then functions inside the class. And those functions can just change the values if it feels like it.
 

purbeast0

No Lifer
Sep 13, 2001
52,869
5,740
126
ideally functions shouldn't have side effects. if still_alive is going to get assigned to false, it should happen in the block that it was defined in, not in some other function.
It's only a side effect if that wasn't the intention. If the intention is to change it inside the functions, then it's not a side effect. Those functions could very well be implemented "in the block" (scope) that still_alive was defined in. They could be implemented right below the code in the billboard.

I know you know about coding but not sure your experience with javascript.

That syntax could be multiple languages but it could be javascript and looks perfectly valid.
 
Last edited:

kage69

Lifer
Jul 17, 2003
27,386
36,668
136
f8JH94I.jpg