1. Data validation (was Re: Stupid Newbie-sounding question.)
- Posted by Derek Parnell <ddparnell at bigpond.com> Jun 02, 2004
- 553 views
Patrick Barnes wrote: > > >From: Derek Parnell <guest at RapidEuphoria.com> > >Subject: Re: Stupid Newbie-sounding question. > > > Okay Rob... What sort of structure do these sequences have to have? I > >don't > > > know! If we had the ability to use stronger typing, then function > > > myFunc(text_picture r1, string r2, flag_list r3) would make a lot more > > > sense. I could go and look at the type declaration, and figure out what > >to > > > pass to the function. > > > People don't use the types like this at the moment because it's so damn > > > computationally expensive for sequences. > > > >This is true. And there is the trade off - speed & flexibility against > >structure and complexity. Think of it in terms of a bicycle without > >training wheels and one with training wheels> > > >RDS has chosen speed. Meaning that the coder has more responsibility to > >provide quality assurance than the translator does. Yes this does mean > >more work for the coder and better discipline. > > Well, if you're writing a library that other people would use, I would say > that it's the library programmer's responsibility to check the data passed > to it. This is a good issue to discuss. I must deal with this problem with the Win32lib library. The question for me is, how *much* parameter validation should the library perform? On one extreme, it could be said that I should not do any parameter validation because it is the *user's* responsibility to provide parameter values as documented. If they do not heed the documentation, why is it considered to be my problem? This approach would speed up the execution of win32lib applications, and slow down the development of quality applications. On the other extreme, I should do everything in my power to protect the user from using incorrect parameter values. As a service to the coder (and end-user?) I should try to provide meaningful exception messages and/or codes when I detect unusable parameter values being passed. This approach would speed up the development of quality applications and slow down the execution of win32lib applications. And there are many shades in between these two extremes. Maybe I should provide two versions of the library - one with training wheels and one without? At this stage I don't have the answer. The current library does some checking but could do more. > I think that types could be implemented in a way that would run *faster* > than without. Without these types, libraries and functions need to check > that the data passed to it is valid. This results in redundant checks. > Having types supplemented with the "of" command speeds it up many-fold over > the old type system, because data will only be checked that has changed. And > because that if a variable is of a certain type, it is *known* already that > it is valid, so it won't need to be checked multiple times. What you are saying is true, but it comes at a cost to RDS. It introduces more potential bugs in the interpreter and translator. It also will cause Euphoria apps to run slower than if they had no type checking. BTW, how would the user defined type routine get to know which parts of the variable have been modified? Currently, the entire object is passed to the routine, but there is no indication which parts were changed. > > > Issue #2: > > > Run-time slicing and sequence errors are my main cause of problems. The > > > primary error I make is missing a set of braces around a concatenation > > > command.... > >Learn to love the append() function. > > I know, but '&' uses less keys... (my bad, I know). Yes, but '&' is NOT the same as 'append'. It is a different tool. > It's still a valid argument (slicing and seq errors). It's very easy to > misplace a subscript, or make some error if you are breaking up and > reassembling a sequence in one line. Yep. Any ideas how to make this less error prone? > > > > Unfortunately, I only find out when I try to reference it, which may be > >a > > > long way from this error. At least with differential checking, an error > > > would show up at that point of error, and I can fix it quicker. > > > >This is also an arguement for some type of 'assert' system that would help > >trap errors during development and could be automatically removed for the > >release version. > > Well, type checking could be turned off for release. The user won't know how > to fix a code error, no matter how helpful the error message. > > >Ummmm? Why not code so that it works? > > > > type myStruct (object s) > > if sequence(s) return 1 > > else return 0 > > end type > > Because it is non-intuitive. It is for me. It is saying that if 's' is a sequence then its okay otherwise its not okay. > Because there is no shortcut for 'and' in this form: > type myStruct ( object s ) > return sequence(s) and length(s) = 4 and integer(s[1]) > end type > Crashes if not a sequence. Yes, short-circuit evaluation on the 'return' statement would be nice. constant isGood = 1, isBad = 0 type myStruct ( object s ) if sequence(s) and length(s) = 4 and integer(s[1]) then return isGood else return isBad end if end type > > > Derek, if someone passes a badly-formed sequence into one of the Win32lib > functions, the error is stated to be inside that function, when in fact it > was the fault of the other programmer. The trace window or ex.err may show > the value of the sequence (or maybe only the first part), but it may not be > easy to elucidate that a) the error resulted from their own mistake. b) > Exactly what was wrong with that sequence they passed, anyway. That's what documentation is useful for
-- Derek Parnell Melbourne, Australia
2. Re: Data validation (was Re: Stupid Newbie-sounding question.)
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jun 02, 2004
- 533 views
On Tue, 01 Jun 2004 18:26:26 -0700, Derek Parnell <guest at RapidEuphoria.com> wrote: >BTW, how would the user defined type routine get to know which parts of >the variable have been modified? Currently, the entire object is passed >to the routine, but there is no indication which parts were changed. Good question. My first reaction was that if you have type thing(sequence of whatever) then only pass the modified slice. However we need to do something about eg: type ordered_list(sequence l) object item if length(l)=0 then return 1 end if item=l[1] for i=2 to length(l) do if compare(item,l[i])=1 then return 0 end if item=l[i] end for return 1 end type Maybe if we allow: type thing(sequence of whatever, integer from, integer to) the interpreter could throw different bits at a 3-parameter type definition, as opposed to throwing the entire object at a 1-parameter type definition? Pete