Re: Changes in the ESL papers
- Posted by Derek Parnell <ddparnell at bigpond.com> Jul 22, 2005
- 568 views
Jason Gade wrote: > > D. Newhall wrote: > > > > Juergen Luethje wrote: > > > - Should the library have a global error handling function? > > > If so, it would probably be the best to implement it for the > > > first version. > > I was thinking about this too and I'd say that it's not necessary. > > Theoretically, the > > library shouldn't have to call any error routines since each function would > > return > > an error value instead. Error handling routines would probably be nice but > > different > > platforms, libraries, and applications would each handle them differently. > > > > > - What shall functions return in case of an error? > > Depends, but usually 0 or -1. If you look at match() and find() they return > > 0 on failure > > because those aren't valid return values but open() returns -1 for failure > > (since 0 > > means standard input I'm guessing). Also, stuff like get() and value() can > > return 0 > > as a valid result so they return a sequence starting with an error code > > declared as > > a constant. I think this is a case-by-case issue for the most part. > > As long as routines don't return a sequence or an atom based on *whether* > there is > an error. This is a behavior of Euphoria standard routines that I hate -- > users shouldn't > have to declare variables as object in order to differentiate between a valid > return > and an error. For what it's worth, I've tended to adopt the convention of *always* returning a sequence. The first element is either 0 (an error) or 1 (a success), and the second is the ancillary data. In the case of an error, it is something that helps users know what sort of error occurred, and in the case of success, it is the returned data from the function. This keeps code consistant and extensible. It also encourages (forces?) coders to take notice of error codes because it is no longer possible to do ... if func() = 0 then ... Instead you must do ... rc = func() if rc[1] = 0 then ... However, I guess most coders won't bother to adopt this discipline. It is similar to the RDS value() function's return. -- Derek Parnell Melbourne, Australia Skype name: derek.j.parnell