Re: Allowing error-prone code line to persist in app
Re: Allowing error-prone code line to persist in app
- Subject: Re: Allowing error-prone code line to persist in app
- From: Gregory Weston <email@hidden>
- Date: Tue, 18 Aug 2009 13:35:46 -0400
Chris Paveglio wrote:
This is a question of style.
My app has text fields to display a number, and with a command I
format it like a phone number. So for the second phone number,
sometime there is not a second phone (or fax). So my command to
format the 2nd phone number logs an error to the console when I run
it:
NSString *formattedFax = [NSString stringWithFormat:@"%@-%@-%@",
[originalFax substringWithRange:NSMakeRange(0,3)], etc...
*** -[NSCFString substringWithRange:]: Range or index out of bounds
But if there is not a second phone/fax number, I don't really care
if this line fails. I certainly *could* write a check like "if
(originalFax != @"") then... continue with function". But would that
take more time to process?
So SHOULD I write the check to make sure the data is valid or not?
Or just let the function fail because its faster and has no lasting
impact? Is it OK if this line quietly (to the user) fails?
It won't be quiet to the user if you're ignoring these kinds of
messages so often that their logs start chewing up disk space. Even
without consuming huge amounts of space it introduces noise into
what's supposed to be a useful signal, and you *will* get users
complaining to you about it. Those are probably the least of the
reasons why you shouldn't let conditions like the above persist.
In a case like this, you should actually be doing some more robust
checking than just for empty strings. And consider the possibility
that the user is not in the US, if that *is* a possibility. You might
not have 10 digits to work with. Less and you fail. More and you lose
data, at least as far as the user is concerned.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden