On Sep 1, 2012, at 7:51 PM, openbios-request@openbios.org wrote:
Message: 2 Date: Fri, 31 Aug 2012 13:40:58 -0500 From: Tarl Neustaedter tarl-b2@tarl.net To: The OpenBIOS Mailinglist openbios@openbios.org Subject: Re: [OpenBIOS] Fwd: [PATCH] Adds local variable support to OpenBIOS. Message-ID: 5041053A.90303@tarl.net Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
On 2012-Aug-31 09:50 , Programmingkid wrote:
Are you saying my-variable is better than myVariable?
Yes.
I have changed all my code from camelCase to hyphens.
How do global variables get you in trouble in recursion? Do you have an example?
Not off-hand, we learn to avoid doing that. To construct one - let's take a method doing recursion properly, and break it:
\ Correct way, using stack manipulation : fibonacci ( fib -- return ) recursive dup 2 >= if ( fib ) dup 1- fibonnaci ( fib fib-1 ) swap 2 - fibonnaci ( fib-1 fib-2 ) + ( fib ) then ( fib ) ;
\ Incorrect way - using variable "fib", which will get overwritten during recursion 0 value fib; : fibonnaci ( fib -- return ) recursive to fib \ to avoid stack manipulation fib 2 < if fib exit then fib 1- fibonnaci ( fib-1) fib 2 - fibonnaci ( fib-1 fib-2 )
( fib )
;
There is nothing to worry about. All the global variables in my code are only used at compile- time - not during runtime.