• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: [newb] Allowing error-prone code line to persist in app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [newb] Allowing error-prone code line to persist in app


  • Subject: Re: [newb] Allowing error-prone code line to persist in app
  • From: bryscomat <email@hidden>
  • Date: Tue, 18 Aug 2009 11:16:07 -0500

There would be NO performance impact to impose the check.
Always perform range-checking as it will most likely break under circumstances outside of your development environment. It's not just a matter of style.


On Aug 18, 2009, at 11:11 AM, 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?

Thanks, Chris

_______________________________________________

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


References: 
 >[newb] Allowing error-prone code line to persist in app (From: Chris Paveglio <email@hidden>)

  • Prev by Date: [newb] Allowing error-prone code line to persist in app
  • Next by Date: Re: [newb] Allowing error-prone code line to persist in app
  • Previous by thread: [newb] Allowing error-prone code line to persist in app
  • Next by thread: Re: [newb] Allowing error-prone code line to persist in app
  • Index(es):
    • Date
    • Thread