Tag Archives: Code

Regarding Style

RibbitAs I’ve gotten older my coding style has evolved. I’m a fairly verbose coder which can drive some people absolutely crazy but it works for me. It makes code more readable.

Case in point. Something I get questioned about all the time is why do I write false if conditions like this.

if (nil == thing) {
    // Create a new thing
}

Instead of doing…

if (!thing) {
    // Create a new thing
}

Well, that’s easy. My eyes can pick it up instantly. One other thing about that syntax. It’s a hangover from over 20 years of writing C and C++ code. The compiler will bark if you try to a value to zero. In that way it served as a way to make sure you didn’t accidentally make a mistake that could take a while to find. Let the compiler help you where it can.

I really like it more for readability. Opinions vary.

Just Ship It

Will write C/C++ for foodMike Jurewitz: “I have watched too many developers over the years focus on the wrong things in their products. Some endlessly add feature upon feature and take so long to ship that their users have long since moved on. Others endlessly rework a feature in pursuit of some nebulous technical excellence that isn’t necessary and whose pursuit certainly doesn’t pay the bills. And others find themselves constantly moving the target they’re trying to hit, redefining the features, UI, or problem-space of their product in a continual reaction to the world around them. These are easy traps to fall into. After all, we’re all human and most of us are making it up as we go.”

Good advice. Maybe people don’t teach this anymore? You can’t have a 2.0 without ever having a 1.0, right. Iterate, iterate, iterate, but ship between those iterations. Some people have to find the perfect solution for everything, or they waste their time rewriting code that works because they don’t like the style, or believe their way is better. There are, of course, good reasons for rewriting code, but the reasons I just mentioned aren’t among them.

I’m guilty of doing this stuff myself, when I was younger. What I’d end up with is code the way I liked it, but offered the same functionality. No net gain. I’ve learned not to do this. I now move forward and tweak things as needed for the next release. Yes, it must be solid and usable, but it doesn’t have to be perfect in every way.

I’m not the greatest developer in the world. I’m slow and my code has never been the prettiest in the world, but it’s in use by well over 10 million people worldwide, and that’s a pretty darned good feeling.

So, my advice to you is, find a nice minimum set of functionality, make it usable, make it solid, and ship it. That will let you move forward. It will afford you the opportunity to create a 2.0.

Design then Code

Design then Code
Design then Code: “Building iOS Apps From Scratch is an introduction to Objective-C and Cocoa for first-time coders. It explains Obj-C’s unique syntax, the Cocoa frameworks, creating and using objects, Model-View-Controller, and how to build an app’s interface. This is suggested reading before tackling project tutorials.”

This is Mike Rundle’s latest project to help the iOS Design and Development community avoid creating Frankenstein applications. Mike’s a rare breed, he’s a great designer and he gets Cocoa and Objective-C, which makes me a bit green with envy.

If you’re a beginner, and can’t wait to build your first iOS App, you could do a lot worse than purchasing the Design Rookie and Cocoa Rookie packages together. Heck, if you’re not sure, give the free tutorial a spin before purchasing. That should give you some idea of the quality to expect.

Well done Mike!

Using P8, the ping.fm Objective-C engine

I just wanted to test a code highlighter plugin for WordPress, so I’ll use my open source ping.fm Objective-C engine as an example. Yeah, I know, shameless self promotion.

Here’s how to use P8 in your app…

[codesyntax lang=”objc”]

// Yes, you owe a Release later for P8 and
// TestDelegate. This example doesn't do it.
TestDelegate* del = [[TestDelegate alloc] init];
P8Engine* P8 = [[P8Engine alloc] initWithOptions:kP8APIKey appKey:kP8AppKey delegate:del];
if (nil != P8)
{
	// Post something.
	[P8 userPostStatus:@"Testing 1,2,3... Please ignore, http://f67.us/iam"];

	// Create a short URL
	[P8 urlCreate:@"http://rob.crabapples.net/"];

	// Resolve a short URL
	[P8 urlResolve:@"http://ping.fm/xeECl"];
}

[/codesyntax]

Ok, I don’t really like that.