Re: Variable declarations
- Posted by Jim Hendricks <jim at bizcomputinginc.com> Sep 19, 2004
- 424 views
Derek Parnell wrote: > <SNIP> > > 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. I don't think that's so bad since it forces the programmer to think through setting up the environment. I agree it could be useful to be able to test for unitialized but declared variables but it would go against the simple design of Euphoria. Personally I despise dealing with Null in other languages, it's too ambiguous. Years ago I used to program in dBase/Foxbase/FoxPro and loved the lack of Null and the automatic defaulting, nums to 0, strings to "", logicals to false. Although the lack of explicit declaration could lead to sloppy code and unexpected errors. And as optional arguments go, I have a love/hate relationship with them. While I love the ability to drop some arguments that may not be necessary, I hate how optional arguments can lead to sloppy code. I try to allow for a "NA" state for arguments which may be optional and then test for that state in the function/procedure. This forces me to be specific in calling the function/procedure that if I don't want the argument I must explicitly set it to the "NA" state. > > 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. Since I'm new to Euphoria and this list I wouldn't know your history of "bad mouthing" so my opinion here may show a lack of sensitivity to the situation, but I don't see this as bad mouthing. You might change your choice of "RDS way" to "Euphoria way" to make it a statement of "this is how it is" rather than the more political statement of "this is how it is because this is how RDS wants it". Even though the more political statement is true, it goes without saying since Euphoria belongs to RDS. > > -- > Derek Parnell > Melbourne, Australia >