Coding Tip: Have A Single Exit Point
Having one exit point (return) from a function is a good thing. Here is an example of a single exit point: int MyArray::indexOfElement(int elementToFind){ int foundIndex = ELEMENT_NOT_FOUND; for(int i...
View ArticleCoding Tip: Replace Complicated Conditions With Boolean Variables
Consider the following if statement: if(dragOperation != NSDragOperationCopy && NSPointInRect(currentMouseLocation, self.bounds)){ //do something } Even though you may have worked out what the...
View ArticleConst Correctness For NSString (And Pointers In General)
So you're implementing a new notification and you want the name to be a constant. Easy, right? const NSString* VTMyNewNotification; If that's how you do constants, you're not doing it quite right. Try...
View ArticleWhen A Café Is Not A Café – A Short Lesson In Unicode Featuring NSString
Let's start with two exotic strings (console output is in the code comments): NSString* apples = NSGetFrenchWord(); NSString* oranges = NSGetFrenchWord(); NSLog(@"apples == '%@'", apples); //apples ==...
View Article