Cocoa

Brent Simmons on hybrid applications

I grow more jealous of Cocoa: Brent Simmons has posted slides from a presentation regarding my old flame, the hybrid app. Mostly bullet points, but with enough code samples to give a non-Cocoa programmer some envy.

It’s funny, if I was writing an app on a PC I’d make it hybrid because I could have more control over the UI at the desktop layer, delegating the web to data tasks, but if I was on a Mac I’d go hybrid because I could do more with the UI if it was a web page, due to my lack of understanding of the many many square brackets in Objective-C.

In either case, the goal behind a hybrid application (for me) would be to solve a problem that benefits from centralized data.

Technorati Tags: ,

Cocoa

Comments (0)

Permalink

Thrust Labs rule #1: use meaningful variable names

I should have committed this lesson to memory years ago after some kind of time wasting mix-up between a test script called “test” and the UNIX test command (which, in hindsight, may have been more of a path issue, but the other lesson was to not work on assignments at 4 am the night before they’re due), but here we go again:

Never ever ever use throwaway variable names.

Case in point: inspired by my earlier thoughts on desktop application development, I decided to try Cocoa programming. I’m just at the poking-around stage right now (I miss MSDN’s level of documentation already, even when it’s wrong), but I lost an hour or two on this gem:

- (void) loadPicture:(NSString *) filename
{

img = [[NSImage alloc] initWithContentsOfFile: filename];
if(img)
{
[pic setImageScaling: NSScaleProportionally];
[pic setImage: img];
[pic setNeedsDisplay:YES];

}
else
{

NSLog(@”img failed”);

}

}

“pic” was an NSImageView control, and there weren’t any errors, but the damned thing wouldn’t ever change its picture. Further debugging showed that messages weren’t going to it at all:

if([pic isEditable]) NSLog(@”YES”);
[pic setEditable: NO];
if([pic isEditable]) NSLog(@”YES”);

That yielded two consecutive YES entries in the log.

In the end, renaming “pic” to something more meaningful solved the problem. I’ve yet to find a Cocoa or Objective-C reserved words list, but I suspect pic is on it. Of course, meaningful names will avoid a good chunk of the need for such a list anyway.

Technorati Tags:

Cocoa
Programming

Comments (2)

Permalink