Re: Crash or return forbidden value?

new topic     » goto parent     » topic index » view thread      » older message » newer message

Bernie Ryan wrote:
> 
> Jeremy Cowgar wrote:
> > 
> > CChris posed the question. I always have a tough time with this one. I can
> > give
> > a few examples:
> > 
> > 1. Open a file that does not exist. Well, the user may wish to try a
> > different
> > file. Error code.
> 
> Ask user if they want to create the file.

Correct, no crash, open() returns an error code and the app deals with it.

> > 
> > 2. Connect to a database server fails. Error code, as you may have given
> > incorrect
> > login credentials by user input and want to prompt the user for the
> > username/password
> > again.
> > 
> 
> Connecting to a database should start out asking the user to login,
> 
> therefore the user would know their login failed.
> 
> > 3. Requesting an out of bounds index for a given sequence. Crash. This tends
> > to be a programmers fault, not a users fault. The methods find_from,
> > rfind_from,
> > etc... do this.
> 
> The programmer should be doing any necessary bounds checking ?

I am always testing for 
if sequence()  
if length()
if length() > index
if index > 0 
etc etc. when in my opinion, Eu could be more tolerant and return logical
results:

s = "qwerty"
a = 12
return s[11] -- returns ""
return s[1..45] -- returns s
return s[-1] -- returns ""
if s then -- this works
if a = s then -- cannot possibly be true, but don't crash!

etc.

Kat

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu