Re: [newb] Allowing error-prone code line to persist in app
Re: [newb] Allowing error-prone code line to persist in app
- Subject: Re: [newb] Allowing error-prone code line to persist in app
- From: Alastair Houghton <email@hidden>
- Date: Tue, 18 Aug 2009 17:25:12 +0100
On 18 Aug 2009, at 17:11, Chris Paveglio wrote:
*** -[NSCFString substringWithRange:]: Range or index out of bounds
[snip]
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?
No, because:
1. It *isn't* failing quietly (it's logging a message to the system
console), and there's nothing worse than trying to debug something
only to discover that some app you're running is unnecessarily chatty
on the system console and is getting in the way of you seeing some
messages you've added deliberately for a particular run.
2. It's raising an assertion, which uses exception handling, which is
slow(ish) and error prone (since you can easily leak resources,
especially if exceptions are thrown through a non-ObjC-exception-aware
function).
Also, PLEASE remember that there are people who don't live in the
United States!
Not everyone formats telephone numbers the way you've done it above.
It's a real source of annoyance for end users outside the U.S. when we
discover that we can't enter our postal codes because you think they
should all be numeric and without spaces, or that we can't enter our
phone numbers because they don't fit your idea of what a phone number
looks like. Or that we can't type the name of a county because it
isn't a two character state code for a U.S. state (even Apple gets
that wrong in one or two places...)
Telephone numbers are a particular source of irritation, actually,
because different countries format them *radically* differently. It's
quite common to fine parens, dashes, full-stops, commas, spaces, hash
characters and all kinds of others, and the grouping may vary from
region to region within a country never mind between countries. What
you should do is leave the number the way it was originally entered by
the user; if you need the digits for some reason, then extract them
*where you need them* and leave the original string alone.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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