Categories
Product Design Tech Trends

When Dogfooding Fails

For over 20 years we’ve been eating our own dog food in the software industry and it’s not working. For the uninitiated dogfooding means to actually use the product you’re developing. It started out as a radical idea at Microsoft and spread as a way to get developers to experience their customer’s pain. On the surface it was a very good idea–especially for an aging corporate culture divorced from its users. When I interviewed with Microsoft in 1995 I was told that all their engineers we’re given low-end 386 PCs. These PCs ran Windows 95 so slowly that the MS developers were incentivized to improve Windows’ performance to ease their own suffering. I don’t know about you, but I find that Windows is still pretty slow even in 2011 running on a really fast multicore PC. Clearly all this dogfooding is not helping.

So I’d like to frame an argument against dogfooding and in favor of something else: Plagiarism.

My argument goes like this:

  1. Dogfooding doesn’t work, or at least it’s not sufficient, because it’s not a good predictor of software success. Some software that is dogfooded is very successful. Most software that is dogfooded fails. (Most software fails and most software is dogfooded therefore dogfooding fails.)
  2. Dogfooding is really bad because it give you a false sense of doing something to improve your product: “It’s OK, I know our software is terrible but we’re forcing our employees to dogfood it and out of shear frustration they will make things better! Everyone go back to sleep…”
  3. Dogfooding reinforces bad product design. Human beings are highly adaptable (and last time I looked software devs are still considered human). We get used to things, especially in a culture where company pride and team spirit are valued (e.g. groupthink). Over time poor performance becomes typical performance. It starts to feel natural. Thus slow loading Windows operating systems become the gold standard for thousands of loyal Microsoft employees and customers. Instead of fixing the software we are fixed by it.

I believe that the urge to Dogfood is an emergent strategy of mature tech companies that want to rejuvenate their software development process. Management starts talking about Dogfooding when they realize the spark of creativity has gone out and they want to reignite it.

One of the reasons Dogfooding fails is that you never eat your own dog food in the beginning: The dog food didn’t exist yet. You had to get your inspiration from outside the company. Microsoft Windows was not the first OS with a graphical mouse-driven shell. At some point the Windows devs must have looked at the Apple Lisa and Macintosh computers for inspiration. And the Apple devs looked at the Xerox Star. And the Xerox devs drew their inspiration from the physical world: The first GUI desktop was modeled on an actual physical desktop. No dog food there.

So rather than dogfooding we should talking about plagiarism. If you want to make a great software product eat another a great software product and make it taste better–don’t eat yucky dog food.

Microsoft should force their devs to use the fastest computers running the best operating systems with really cool applications. I think they must have bought some MacBook Airs, installed Ubuntu and Spotify because Windows 8 looks pretty awesome 🙂

Categories
Cocos2d-iPhone Programming

Dungeonators iPhone Game Released in the App Store!

Writing a real game, from scratch, in Objective-C, with original Art and sound effects, took a heck of a lot longer than I imagined. Even with the help of the Cocos2d-iPhone framework!

You can find it here: http://bit.ly/rkZvCJ

Here’s what the sprite atlas looks like (formatted by Zwoptex) …

And here are some stats:

Now you know all my secrets!

 

 

Categories
Cocos2d-iPhone

Invalid Code Signing Entitlements

Finally after 11 months I submitted my iPhone game, Dungeonators, to iTunes Connect for inclusion in the Apple App Store. I’m planning on giving it away so the “warcraft meets angry birds” funs is accessible to everyone! I hope it passes Apple’s review process 🙂

It took several attempts for me to get to “waiting for review status”. Here are the step I went through in hope that if you, in the near future, need to submit an app for the first time, you can succeed on your first attempt.

At this point set a cold beer within easy reach…

  1. Most of the info from Apple and the books on iPhone development is based on the old Xcode 3-based application submission process. Google Xcode 4 iTunes connect for the most recent tips. I’m not even going to include a link because the info goes stale fast. Just google it.
  2. Set your app’s pricing and metadata in iTunes connect. You’ll need a 512 x 512 icon too.
  3. Follow all the directions about distribution certificates and distribution provisioning profiles. Like a double-linked list your distro cert should point to your provisioning prof and vice versa.
  4. First create the distro cert via keychain access app on your map. Make sure there is key associated with your distro cert after you install it in your key chain.
  5. Second create your distro provisioning prof and install it in Xcode 4. Make sure your target’s code signing entitlements point to your distro provisioning profile for the release build.
  6. Clean and Archive your app with the Product menu in Xcode 4. The Archive scheme should be set to your release configuration.
  7. In the Organizer window validate and submit your app. You’ll need your iTunes Connect password.
  8. If you get the dreaded “invalid coding signing entitlements” don’t panic. It could mean a lot of different things. But if your iOS app is simple then it’s most likely  the iCloud entitlement. (Google it for more info.)
  9. Go to App IDs in the provisioning portal. Scroll to the bottom. Click configure on the row that represents your app’s ID. Uncheck Enable for iCloud. Click Done. Create a new distro provisioning prof and reinstall it into Xcode 4. Go to iTunes Connect and reject your binary. Go back to Xcode’s Organizer window and do Validate and Submit again.
  10. If you get an invalid binary. Drink a beer and try again! (do while beer != empty)
See, that was easy!
Categories
Argument

Why Engineers Should Win

If you accept my argument that engineers generally don’t win arguments because they tend to rely on reason instead of rhetoric (even if you don’t accept my example that spam is preferable to junk mail) then you’ll be glad to know I have  a prescription for engineers that will help them win arguments.

But before I get to that prescription I’d like to point out two important premises. First, winning arguments is desirable; Second, winning arguments via rhetoric isn’t really winning.

I have some friends in the hacker/engineering community who are simply disgusted and ready to drop out of mainstream society. In many ways they already have. They have their own culture, their own activities, and their own vernacular.

Q: Why did the hacker surrender his spoon but not his fork?

A: Because spooning is privilege but forking is a right.

If you get this joke you’re an engineer (of the hacker persuasion). Don’t ask me to explain it to you 🙂

“Why bother with the muggles if they’re just going to abuse us with their outmoded ideas about sexuality, gender, religion, intellectual property, and what constitutes an worthwhile activity?”

But there are several good reasons for dealing with the main stream, and helping it become more efficient, effective, and generally more happy. The muggles are our parents, brothers, sisters, and children and we owe them something. They are suffering needlessly. If you can help someone but stay your hand that’s just as bad as doing direct harm. These are all excellent but tired arguments. The best reason for engineers to engage society-at-large and start winning arguments is that we don’t have our own private planet. A couple of more Chernobyls, a few more degrees of global warming, a few more years of developing world famine, and it’s game over for all of us.

“Kk” you say, “I grok it. Let’s all go learn rhetoric and NLP and beat the muggles at their own game!”

Unfortunately that happens all the time. I know lots of people who started out as engineers and ended up as salesmen, managers*, and investors. Once you change your thinking patterns to base arguments on rhetorical techniques (winning on style, winning at any cost, winning as an end in itself) you lose the the ability to figure out the reasonable thing to do. Like Stockholm Syndrome once you take up the sword of your enemy you become your enemy.

If we really want to win arguments, we can’t win on mainstream terms, because then we lose. We have to win arguments on our own terms. See if you can guess how before I write  my next post…

* Mea culpa.

Categories
Argument

Why Engineers Never Win

Our world is full of bad decisions based on convoluted logic in service of irrational preferences. A great example is people who drive into NYC every morning to get to work. Why people sit in bumper-to-bumper traffic for hours polluting the air, wasting fossil fuel, and developing hypertension inducing road rage is beyond me. Another good example is junk mail. I just can’t phantom why the we tolerate a process where perfectly good trees are transformed into trash, and delivered to my mailbox in brightly colored envelops. Every day I simply throw this junk mail away. At least with spam no trees are sacrificed and I can automate filtering it out.

I like to think that if engineers ruled the world driving into NYC and junk mail would be optimized away like inefficient algorithms and duplicated code.

Apparently engineers don’t rule the world. They rule the internet and the desktop–all the virtual worlds–just not the real one.

So why is that? Why do lawyers and managers (like me) and lawmen get elected and listened too? Why do A students work for C students?

It’s a problem of tools. Engineers are taught logic. Lawyers, managers, and lawmen are taught rhetoric. Thus the engineer makes a well reasoned argument based on data and sound scientific principles and gets blown away by a non-engineer making an emotional appeal in the court of public opinion. If engineers used rhetoric to communicate their ideas instead of reason we would not have half as many problems. We would figure out where to store nuclear waste, how to feed more people, provide more health care, and jump start the economy. As a manager I don’t have the answers to these problem but I know several engineers who do.

If we let the engineers win life would not be perfect but it would actually get better via iterative processes, refactoring, and bug fixing. Instead our life degrades. This makes me sad and hopeful too because there is an obvious solution: Engineers of the world: Stop arguing so rationally.

My favorite Monty Python skit is the one about the Argument Clinic:

Python 1: Ah, is this the right room for an argument?

Python 2: I told you once

Python 1: No you haven’t.

Python 2: Yes I have.

Python 1: When?

Python 2: Just now.

This skit is brillant on so many levels. Every engineer should study it to help him or her learn rhetoric. Python 1 is obviously a typical rational engineer. He asks a perfectly good and honest question. Python 2 is obviously a manager. Python 2 answers Python 1’s question with a statement designed to inflame his passions and cloud his senses. By the end of the skit Python 1 has had his argument but feels cheated out of it at the same time. Like asking for technical debt to be addressed and leaving the meeting wondering how you got talked into creating more technical debt to remove the old technical debt.

Categories
Nerd Fun Programming

Fraction: Does not recognize selector forward::

If you’re crazy like me you love reading really good primers on programming. Not just to learn about a particular language but to enjoy well written technical prose. (Yeah, I said I was crazy). Yesterday, I started reading Stephen Kochan’s classic Programming in Objective-C (original edition), which was published in 2003. What I like about Kochan is how he presents the principles of object oriented programming and the syntax of Objective-C without jumping into writing a fancy application. Kochan takes his time to teach each component of the language and the paradigm instead of glossing over the details to quickly get to a utilitarian example.

If you want to understand how a great tutorial is written you can’t do much better than Kochan. Unfortunately a lot has changed in the Mac OS X world since 2003 and the code examples don’t compile. The code is fine. It’s the default compiler setting that have changed. A Google search on the compile error brought me to a a good discussion on the problem on Apple’s developer support forum. You have to dig but the fix is pretty trivial if you know gcc complier flags (which the target audience of a primer are unlikely to know).

My advice to students and armchair time travelers who want to follow the original book is to resist the urge to change the source code examples to inherit from NSObject. Instead use the -arch i386 flag as suggested by very helpful forum user Constantino. (Mysteriously Constantino’s forum name is spelled with a K.)

In other words instead of compiling with

gcc ClassName.m -o ProgramName -l objc

use

gcc -arch i386 -o ProgramName ClassName.m -lobjc

To compile and run the OOP first example of the book from the terminal you can copy and paste the following 2 lines:

gcc -arch i386 -o Fraction Fraction.m -lobjc
./Fraction

And for the full experience, don’t use Xcode or a fancy text editor. VI is fun, old school, and Apple’s Terminal a joy to work with.

Notes:

  • There is a third edition that probably addressed this issue. But what fun is that if you only have the original edition? I would love to set up an old Mac with a vintage version of the Mac OS X to really immerse  myself in the experience!
  • There is also also a Programming in Objective-C 2.0 3rd Edition which looks like a lot of fun to read and which might actually be more relevant if you have an urgent need to write a modern Mac application.
Categories
Music

My Life in Playlists: Delran High School 1976 to 1979

Too much has been written about High School, that American institution of adolescence, yearning, and despair. And so I’ll let the music tell most of the story. But to set the stage: I started 9th grade in the fall that followed the Bicentennial celebration of my nation’s birth; I ran with a prototype of the nerdy crowd; My girl friend was rumored to be the smartest-girl-in-school; My best friend was a body builder inspired by Pumping Iron; My other friends ran the Audio Video club as if it was the CIA; I was the worst guy on the Math Team and spent every moment I could in the Library reading Science Fiction; Worst of all I was the President of the High School Band, elected at first as a joke and re-elected because I was clearly the only soul who cared.

Point of Know Return, Kansas

But there was one thing that kept me from depression in the face of the jocks’ taunts and cheerleaders’ cold shoulders. That was Pop Music. Back then I called it Rock and it defined my social circle. While the psychological rifts between those who love Algebra and those who did not could never be crossed, every teen at Delran High School could rock out to Kansas, Thin Lizzy, ELO, Styx, and Heart.

As a freshman in High School I was only interested in big bombastic songs with lyrics that asked rhetorical questions. The fact that the word No in the title was spelled Know meant Kansas knew exactly how to get my attention. Was it a stupid pun or deep philosophical insight? I’m old enough now to know there is no difference between the two but at the time I was young enough to want to ask the question.

Telephone Line, ELO

The one High School party I remember well was at this rather popular girl’s house. None of my friends were there so I was bored and ignored. (I’m not even sure how I got invited.) To escape my anxiety I decided to man the record player and be the DJ. Nested in the middle of a stack of LPs was ELO’s A New World Record Album. Back then a big part of the experience was the artwork on the cover and ELO’s bright neon logo signaled icy crisp newness—So I plopped it on the turntable. I don’t down know what happened the rest of the night during the party but I still remember every song.

Jailbreak, Thin Lizzy

After school I hung out at a pizzeria in strip mall located at the halfway point between home and DHS (Delran High School). For the price of a coke and slice of sicilian it was my home away from home. I couldn’t afford to buy every album that interested me so the pizzeria was my focus group and cultural roundtable.

Thin Lizzy’s album Jailbreak was much discussed. The cover art looked as if Marvel Comics created it. Most of the songs seemed to be about a bunch of tough guys who called their girlfriend a “good looking female”. At the age of 15 I found this frank form of speech quite intoxicating.

Freebird, Lynyrd Skynyrd

At the time I was not a fan of Lynyrd Skynyrd and Southern Rock (I would drastically revise my opinions when I opened my ears and listened). But Freebird was the official theme song of the DHS prom in 1977. I was a sophomore and it was the only prom I attended. The smartest-girl-in-school was my date. I now realize my prom was a tame and chase affair compared to the Jersey Shore-inspired extravaganzas of the 21st century. I dined, danced, and stayed up to 3 am. Freebird did it job.

God Save the Queen, Sex Pistols

In my final year of High School (I only stayed for 3 out of 4) my musical taste was irreparably changed forever. In the middleclass bedroom community of Delran, I was securely well insulated from Punk, Europe, and Life with a capital L. (Remember, there was no Internet, that I knew of, back then—No MTV either.)

By this time the smartest-girl-in-school had graduated early and gone off to University. In my isolation the pulsing beacon of Punk rock was beginning to worm its way into my consciousness. Bombast was replaced with raw angry beats. I’m not sure where I first heard the Sex Pistols. I didn’t understand what it was but I immediately knew that I wanted to be part of it in some way, some how.

Psycho Killer, Talking Heads

This song , this album, this band was it. Unlike the Sex Pistols, which were beautiful, incomprehensible chaos, the Talking Heads were pure tension under a thin taunt layer of control. David Byrne sang songs about nothing and therefore, of course, everything.

What I liked best about the Heads was the clarity of purpose in their music: Not one note or beat was out of place. There was no fat, no frills, and no flourish. Their sonic tone of austerity only served to heighten the buried emotion of songs like Psycho Killer. It was the Heads who broke me like Tommy’s mirror. I forgot the High School band, put my sax permanently in its case, and bought a white-bodied replica of a fender Stratocaster. I believe this was the only important possession I brought to collage.

Delran High School 1976 to 1979

 

Categories
Cocos2d-iPhone Programming

Hey It’s Easier Than You Think (Xcode 4 and Subversion)

I love how the new Xcode 4 shows you code changes side-by-side with it’s version editor view. But I had a little problem. I’m a subversion fan. Yes, I know, totally not cool. I keep this flaw a secret and I don’t force my preference on my co-workers nor do I tweet about it. I’m sure with years of therapy and the love and support of my family I’ll get over it.

But in the meantime I’m working on an iPhone game and I have a free subversion repository from my ISP. I want to continue to use this fee repository even though Apple gently nudges you to GIT with Xcode 4.

I’m stubborn. I tried GIT and it’s not doing anything for me. My change control needs are small. The functionality that makes GIT great is way more than I need: I’m not working on a large team with a complex build system that has to commit changes with the finesse of a tightrope walker.

Today I went back to subversion and my free repository when I had to update my iPhone to the release candidate 3 of the Cocos2d framework (which is host on Github BTW). Back when Xcode 4 was release I just could get Subversion and Xcode to play nice. But being stubborn, I tried again and to my surprise succeeded.

I don’t think Apple changed much. I think I was just impatient and misinformed. There is a lot of silliness about how to set up Xcode 4 to work with a Subversion repository on the Internets. What worked for me is the functionality that Xcode gives you out-of-the-box (without using the terminal). It was point-and-click but just not automated.

If you’re interested here is how you get a hosted subversion repository to work with Xcode 4. Have fun and don’t sweat the snickers from your more version control evolved friends 🙂

  1. Create a new Subversion repository that you can access via your protocol of choice (mine is the open Internet and HTTP because that’s what Dreamhost provides). Leave this repository empty–we’ll use Xcode 4 to set up all the directories. Just remember your URL and password.
  2. Open Xcode 4 and go the Repository tab in the Organizer Window.  Click the tiny little plus sign in the lower left corner to add a connection to a Repository. Enter in the URL and password and wait for the little circle to turn green. Xcode 4 should automagically detect the type of repository. Be patient. This process takes a bit of time and there is absolutely no feedback: Apple forgot to spin the beach ball here.
  3. When you get the green circle click on the root directory icon on the left under the name of the repository and create 3 directories using the New Directory button on the bottom: trunk, branches, tags. Be patient again and wait for the directories to show up in the center pane of the Organizer window.
  4. Click on the name repository on the left and enter the names of our your 3 directories in the 3 fields provided. (See the genius of naming them trunk, branches, tags?) If your spelling is good you’ll get 3 more green circles.
  5. Click on the Trunk directory on the left and then click on the Import button on the bottom. Select the folder that contains the project you want to put under source code control. Now go away. Get a drink and watch an episode of South Park. You have to be patient because not only is there no beach ball, spinner, or progress bar, there is no green circle!
  6. When you come back you should see your imported directory listed on the main pane. If you click the arrow to the left of it you’ll find your Xcode 4 project file and a subdirectory of files. Remember to be patient. Your poor overworked laptop has to ask the Subversion server for all this info and it takes way longer than 200 milliseconds to get back to you.
  7. Make sure your original Xcode project is closed and hidden away for safe keeping. Click on the imported project in the main pane of the Organizer window and click on the Checkout button on the bottom. Select a location on your hard disk to store your working copy of the project that won’t conflict with the original project. It should be OK to overwrite the original but I’m just paranoid. (Years of experience will do that to you.)
  8. Get a cup of coffee and troll Reddit for some laughs. When you come back Xcode should ask you in a dialog box if you want to open the project that you just checked out. Say yes and run it just to be sure it’s all there. (Paranoia again, sorry.)
  9. Now make a change to your and look for the little M to the right of the file name in the Project Navigator pane to show up. Be patient. If it’s not showing go back the the Organizer Window, back to your Project folder (by selecting its name on the left), and click the Commit button. The little M should now and forever show up next to your modified files in the Project Navigator.

I’m still having a little problem committing from the context menu in the Project Navigator but I can commit just fine from the Organizer Window. Maybe that’s just how Subversion works with Xcode or more maybe I have to be even more patient. I’ll let you know!

Categories
Ubuntu

Don’t Cry For Me Ubuntu (Cry for Sata 6G)

Apparently Ubuntu is not for me 🙁

I have have this commodity PC that I snapped together to play Windows games. (Gaming is about all that Windows is good for these days.) So I though I would install Ubuntu and find some other fun things to do besides killing trolls and jumping through portals.

Every time I attempt to install Ubuntu the installer politely informs me that I do not have a hard disk attached to my PC. This is odd because I remember snapping it inside the case myself. (In fact I slid it in backwards the first time around and it got stuck and I had one of those classic /faceplam moments.)

I’ve tried both Ubuntu 10.10 and 11.4 to with no joy. I get stuck in the place inside the installer with the message:

(X) Has at least 4.4 GB available drive space

(The X above is a bad thing.)

I can run Ubuntu off the CD and Disk Utility doesn’t see the drive while GParted states tersely: No devices detected in the lower left corner of it’s status bar. The Unix command fdisk -l returns nothing.

Windows 7 has never had a problem detecting my hard disk. It’s pretty vanilla Western Digital Caviar Black with 1TB of space. It’s not some exotic brand or tech.

When I turn to Google for help I can see immediately this is not a common problem–not many search results. I found this post on the Ubuntu forums that describes a similar problem. Except that the poster has an HHD drive (which is part SSD and part normal drive). But the responses to his problem are not helpful and the thread just dies.

Western Digital’s support forum was not helpful. With the drive invisible tips for tuning it’s performance are just mean.

Currently I have 3, no 2, theories:

  1. I didn’t set a jumper properly or I somehow wired up the drive in a crazy way when I assembled the computer. That Windows 7 can work with my drive seems to disprove this theory but maybe I accidentally hit the Hide from Ubuntu DIP switch.
  2. My BIOS is not setup properly or my drive settings are screwed up. I don’t know much about BIOS but initial Google searches seem promising. I tried changing the SATA configuration settings from IDE to AHCI and from Enhanced to Compatible but without making a dent in the problem. Windows 7 boots no matter how I configure my SATA drive while Ubuntu continues to ignore the drive. This post on the ASUS Suport forum might yet bear fruit.
  3. Windows 7 has a clever hack that prevents Ubuntu’s installer from recognizing hard drives. (I’m just not this paranoid!)

I could just post on some forum but I’m kinda of bullheaded an want to figure it all out for myself. It’s hard for me to believe I have an actual new problem that the world has never seen before.

I will update this post as I progress. Comments welcome 🙂

UPDATE #1:

Theory 2 is disproved. I used ASUS Update to bring my motherboard’s bios up to date and the Ubuntu installer is still not cooperating!

UPDATE #2

Theory 1 is proven! Kinda. My WD Caviar Black drive supports SATA 3G and SATA 6G. So when I originally built my gaming machine I plugged the drive cable into the SATA 6G connector on my Asus P6x58D Premium motherboard. Windows 7 is ok with SATA 6G but I guess Ubuntu is not. SATA 6G is a new standard that is supposed be faster–but IRL isn’t much better than SATA 3G. (At least according to these guys.) When I wired up my drive to the SATA 3G connector Ubuntu recognized it!

So it’s not me that Ubuntu dislikes–it’s new fangled drive interfaces that don’t provide real value!

Categories
Cocos2d-iPhone Programming

Cocos2d Tip#3: Making Your iPhone Game Fast

My first iPhone game, that might actually make it to the App Store, is just about done. (Not done done but almost ready for testing and tweaking.)

With the idea that other people beside me might actually play my game I’ve started to do a very dangerous and high risk activity: Optimization!

The all the famous Computer Scientists and Software Architects agree: Optimizing your program is a necessary evil, like the death penalty or bug tracking systems, and to be avoided at all costs.

Well, that’s not quite true. It’s premature optimization that is the bad guy here. Don’t start out programming with performance or scalability in mind, least you optimize code that doesn’t need it and miss optimizing code that really needs it. (It’s the same for bug tracking systems–don’t put all your junk in Jira or Bugzilla–just the verifiable, repeatable bugs that you might actually fix one day.)

When I started my game I knew my ideas were going to evolve and I didn’t want to hard code myself into a corner. I consciously wrote code that I knew would be slow but flexible.

For example I used expensive string comparisons instead of testing for cheap numeric constants. During the initial development phases of my game the strings were self-documenting (I could read them like little notes to myself) and easy to change. Later, when my game solidified and the string comparison were easy to find using Xcode’s Find in Project command (which is now Xcode 4’s Find in Workspace command)…

// before optimization
if ([goodGuy.role isEqualToString(@"tank") {
   // aggro something
} else if ([goodGuy.role isEqualToString(@"healer") {
   // fix something
}
// after optimization
switch (goodGuy.role) {
   case CharacterRole_tank:
      // aggro something
      break;
   case CharacterRole_healer:
      // fix something
      break;
   default:
      // oops! This should not happen
      CCLOG(@"unknown character role in %@",NSStringFromSelector(_cmd));
      break;
}

Changing the type of Character’s role property from NSString* to CharacterRole (a typedef’ed int) sped up my game in update methods which were called with every frame change. It was a pain to add all the constants but at least I only had to do it once–even though my conception of a Character and a role changed quite a bit.

// Character.h
typedef enum {
    CharacterRole_tank = 0,
    CharacterRole_healer = 1,
    CharacterRole_melee = 2,
    CharacterRole_ranged = 3,
    CharacterRole_boss = 4,
    CharacterRole_add1 = 5,
    CharacterRole_add2 = 6,
} CharacterRole;

// Character.m
@interface Character : NSObject  {
   NSString* _name;
   CharacterRole _role;
   // ...
}
@property (readwrite, copy, nonatomic) NSString* name;
@property (readwrite, assign, nonatomic) CharacterRole role;

Another big optimization I did was to replace for-loops and with Cocos2d’s fast enumeration macros…

// before optimization
Character* goodGuy = nil;
for (int i = 0; i < self.goodGuys.count; i++) {
   goodGuy = [self.goodGuys objectAtIndex:i];
   // do something with good guy
}

// after optimization
Character* goodGuy = nil;
CCARRAY_FOREACH(self.goodGuys, goodGuy) {
   // do something with good guy
}

My list of good guys changes during the game so I stored them in a CCArray–Cocos2d’s version of a NSMutuableArray. CCARRAY_FOREACH is a Cocos2d macro supercharged for fast array access. I could have used the Objective-C version of a fast numerator but I like to use as much of Cocos2d as I can. That way when I port my game to Cocos2d-x (C++ cross-platform version) it will be less work 🙂

One of the biggest optimizations I did was to upgrade from Cocos2d 0.99.5-rc1 to 1.0.0-rc. You have to be smart about when you upgrade to a new version of a framework. I don’t agree with the idea of living on the bleeding edge–stability of the platform allows me to focus on my own bugs!

Upgrading from Xcode 3 to Xcode 4 also seemed to help, or at least not hurt, performance. The new version of Cocos2d seems to work better with Xcode 4. I’m still getting used to the shiny new Xcode–it acts weird and slow on my Mac Mini.

To make framework and Xcode upgrades easy I put very little code into my app delegate class. All I have to do is to comment out…

//[[CCDirector sharedDirector] runWithScene: [HelloWorldLayer scene]];

and replace it with…

[[CCDirector sharedDirector] runWithScene: [HomeScreen scene]];

There are lots more optimization I can do if my performance isn’t where I want it to be: Unroll my loops and get rid of Character lists altogether. But I’ll lose a lot of abstraction and flexibility so I’m not going to optimize anything more unless my beta testers complain!