On Wed, 28 Jan 2015, adamn...@gmail.com wrote:
> Hmm, I've never tried this before.
> 
> Suppose a function GetCurrent(DateRange as Date[]),  now intuitively 
> DateRange is an array of 2 dates. No-one would be silly enough to pass an 
> array with more than two elements would they?  My cynical nature says yes 
> they could/would.
> 
> I could ignore the array length and just use DateRange[0] and DateRange[1] as 
> the limits but that may produce confusing outcomes, or an error if DateRange 
> contains only one element.
> 

That's how I do it in the Graph class. A vertex is identified via a name
String and an edge is a String[2]. I expect the user to provide a String[]
with at least 2 elements of which indices 2, 3, ... are ignored. If they
don't follow these rules, they can go jump in the lake -- or wherever it
is where runtime errors dwell.

The thing is, as you implied, that there is (likely) no error recovery
strategy which is guaranteed to be natural for everyone. My personal
practice in these cases is to let the interpreter raise the appropriate
error. Less defined behaviour in a component's interface makes it easier
to be backwards-compatible :-)

(The otherwise very good suggestion of using a Struct/Class was not
 applicable to the graph case, IIRC.)

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to