Re: Variable declarations
- Posted by Derek Parnell <ddparnell at bigpond.com> Sep 19, 2004
- 398 views
Jim Hendricks wrote: > > Greg Haberek wrote: > > > > I think thats one of the few things we all did when we started, along > > with improperly initializing variables. > > > > we've all done these, i'm sure: > > > > }}} <eucode> > > -- wrong: > > integer myint = 5 > YUP! been there, done that. > > > > > -- right: > > integer myint myint = 5 > Yes, so long as you are not in a function or procedure and you have > other variables to declare as was specific question I raised at the > beginning of this thread. > > > -- wrong: > > integer myint > > myint += 5 --wrong > > > > -- right: > > integer myint > > myint = 0 > > myint += 5 > OK, I can see this even though it didn't trip me up yet. It does bring > rise to the question, "What is the value of a declared but not initialized > integer?" With sequences it's the empty sequence {} or "" but what is it > with atoms and integers? Actually its the same for integers, atoms, sequences and objects. When you declare any of these but don't explictly initialize them, they all have a special state of 'uninitialized'. Unfortunately, even though the Euphoria interpreter and debugger recognizes this state, there is no method of that your application can test for it. By that I mean you cannot do something like ... if not initialized(myVar) then myVar = 1 end if which is a pity because it makes a great "first-time-through" test and would be a neat way to test for 'optional' function arguments. To put it simply, the RDS philosophy is that all variables must be explictly initialized before they can be used in anyway. Ooops! Sorry - there I go bad mouthing Euphoria and RDS again. I apologize to all forum readers who are upset when people do that heinous crime. -- Derek Parnell Melbourne, Australia