Re: Re[2]: (Another) (small) Eu 2.5 feature request.
- Posted by Jim Hendricks <jim at bizcomputinginc.com> Sep 24, 2004
- 494 views
Patrick Barnes wrote: > My point is, despite the fact that Euphoria *can* hold this > unstructured data very easily... > > As I have found many times, most of my programming errors are caused > by unexpected non-homegenity (I've made a mistake in subscripting, or > data operations). > > Most programming tasks and most programmers need to use data that is > largely homogenous... something that an improved typing mechanism > would greatly help, especially for diagnosing errors. Some of Euphoria's speed is based on the limited type checking, and this is not a new phenomenon. Forth for example does no type checking, it's completely up to the programmer to ensure that what is on the stack is what you what and to remember which item is which, the same holds true for memory access. I would not want to lose this performance kick because you want the safety net to keep you from accessing the wrong data. This is where accessor functions come to the rescue. If you are afraid you may mistype the sequence index for say customer balance, you wrap the access to customer balance in a function. ie.
function getCustBal() return somesequence[5] end function
And if you are afraid you will put info in that does not meet your criteria ( like a customer balance can't be negative ) you use a setter
function setCustBal( atom CustBal ) if CustBal < 0 then return FALSE else somesequence[5] = CustBal return TRUE end if end function
You could go even further by putting the sequence into it's own file with only the accessor functions global. This would eliminate the temptation to access the sequence directly and force you to go through your accessor functions. Jim