[Tutor] running a script from IDLE

Erik Price erikprice@mac.com
Sat, 9 Mar 2002 12:21:17 -0500


On Friday, March 8, 2002, at 01:02  PM, alan.gauld@bt.com wrote:

>
>> So instead of global variables, it's good form for functions
>> to simply use arguments and act upon those?
>
> Absolutely. In fact this is one of the cornerstones of whats
> known as "Functional Programming" - along with having functions
> that always return a value.
>
>> Isn't using a globalized varible just a way to save time/space
>> by not having to declare it as an argument?
>
> Its oftehn used out of laziness yes but has several disadvantages.
> First, its very hard to know which function made the changes
> which caused a fault (a phenomenon known as a 'side effect'
> - when a function changes a value outside of itself).
>
> Second, its very hard to debug functions in isolation because
> they rely on the existence of the global vars
>
> Third, if you want to multi thread your functions its impossible
> coz every thread will call the function which, modifies the same
> variable.
>
> Avoiding globals usially leads to more maintainable, more
> reliable and more reusable code - isn't that wporth a little
> extra typing and a few bytes of RAM?


Now that I think about it, all of these are very good points!  You're 
right -- I think there's an expression for this kind of thing, but I 
can't remember what it is.  Something about a builder measuring an inch 
for every foot or something.  The point is that if you do the work ahead 
of time then you save yourself grief later on.

I'll take care not to act upon global variables unless I've really 
considered the ramifications of it.

BTW, I investigated a page on "functional programming" (posted a few 
days ago on this list, but I forget by who), and it seems to be a very 
strict method of programming.  I'm not saying that I wouldn't give it a 
try, but I think that it's something that I should come back to after 
I've had more experience just writing simple programs that don't conform 
to the functional programming dogma.

Erik