/home/mbrennek

A mostly-fresh start

Developer Conferences

I just read an article on a tech news site that I generally respect which took shots at GDC for its code-heavy treatises, as compared to other industry events like E3 or PAX.

For those who haven’t been, GDC stands for Game Developers Conference. It’s explicit purpose for game and game-adjacent developers, programmers, designers, artists, to share notes, compare techniques, and get into the nitty-gritty details of game development.

If your complaint about GDC is that it’s taking a more intellectual route compared to E3 or PAX, it’s because its not for YOU, game journalist. The other events you mention exist explicitly for your purposes. Stop dumping on the one event designed for game developers to get together and talk shop.

At least developers can still buy tickets to GDC. I think this is at least in part because they have a separate ticket just for the show floor/keynote hangers on like this article’s author. WWDC has failed in this regard because they insist on bundling major product announcements with what is otherwise a perfectly civilized developer conference. I would wager that WWDC tickets would be accessible to more actual developers if Apple sold a separate keynote-only ticket, or even had the big product-announcements the week before so WWDC could also have the reputation for being a code-heavy treatises like GDC.

Demand for and Apple centric developers conference is so high that several independent conferences have sprung up over the last few years. NSConf, Úll, and Çingleton all look to be doing good work, although they are very indie focused. It’s hard to get approval and funding for these smaller non-mothership based conferences for corporate devs. These smaller conferences are also missing the extreme press scrutiny of the bigger official xDCs, but I think that’s a good thing.

Can I Buy a New Mac Pro Yet?

There has been some complaining on twitter about it being December and the the new Mac Pro still not being for sale. Since I still have the source to Is WWDC Sold Out Yet lying around, I put it to good use and created Can I Buy a New Mac Pro Yet? Update: The new Mac Pro is available, so the toy heroku instance has been deleted.

Cibanmpy is functionally the same as Iwsoy. It accepts an email address, and after confirmation adds it to a mailing list that will send one email when Apple adds a Buy button to the Mac Pro web page.

The whole app is running on free/dev tiers on Heroku, so hopefully Apple releases the new Mac Pro before too many people sign up and I have to pay mailgun to send the email.

UINavigationBar Color

In iOS 7, Apple changed the navigation bar to be semitransparent by default. In doing this, they pull down the saturation of the color you set as the barTintColor. This is a very bad thing. So bad that they fixed it with 7.0.3. That’s great moving forward, but they shipped 3 minor releases with the broken color behavior, and not all users upgrade minor point releases. What’s a developer to do?

UINavigationBar isn’t changing colors if you disable transluency, but in their infinate wisdom Apple didn’t make the transluency property available through UIAppearance, so you’d have to set it manually on every navigation bar in your app. Luckily we have one more trick up our sleave. It looks like the UINavigationBar is not changing image colors if you set an image as the background. But you don’t want to create a new image every time your designer changes their mind, so create a single pixel image in code! Put the following method into a category on UIImage:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
+ (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}

I allow my designers to specify a main theme color with a hex value, and have the following method in a Category on UIColor:

1
2
3
4
5
6
7
8
9
10
+ (UIColor *)colorFromHexString:(NSString *)hexString alpha:(float)alpha
{
    // Hex strings may optionally start with a #
    NSString *strippedString = [hexString stringByReplacingOccurrencesOfString:@"#" withString:@""];
    NSScanner *scanner = [NSScanner scannerWithString:strippedString];
    unsigned int rgbValue = 0;
    [scanner scanHexInt:&rgbValue];

    return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:alpha];
}

Putting in all together, you can now set the background color of your UINavigationBar application wide using UIAppearance! I have an –[AppDelegate initializeAppearance] method I call from application:didFinishLaunchingWithOptions: which contains the following:

1
2
3
4
5
6
7
8
9
10
11
12
- (void)initializeAppearance
{
    // .... snip other app appearance code ...

    // ...snip getting color and alpha values from config
    NSString *hexColor = @"#007646";
    float alpha = 1.0;

    UIColor *barColor = [UIColor colorFromHexString:hexColor alpha:alpha];
    UIImage *backgroundImage = [UIImage imageWithColor:barColor];
    [[UINavigationBar appearance] setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
}

Before:

Before Image

After:

After Image

I hope this helps anyone who has to support users on iOS 7.0 – 7.0.2.

UIAlertView Redux (Thank You Apple)

I last took the opportunity to bitch about UIAlertView when a threading error by my predecessor at work caused the screen to flicker. Along with all the problems mentioned in my last rant, it is also often abused by developers stuffing it with custom content, when the documentation clearly states it should be left alone.

Whether it was intentional or accidental collateral damage, iOS 7 breaks most existing UIAlertView customization methods. At WWDC, they announced a new -contentView property to allow these classes to do what they were doing before in a more supported manner. I was less than pleased. I wanted them to disappear, and Apple was promising to make them easier to use.

Lo and behold 3 months later and not only is -contentView not a property of UIAlertView on iOS 7 yet, but it looks like it will not be added at all. This makes me very happy. Not only does it mean other developers have to spent a few more minutes thinking about how this abused content should better fit into their UI, it gives me the political capital necessary to go back and undo some of the sins previously committed in this code base in the name of compatibility. Thank you, anonymous Apple decision maker!

Of course some people will never learn. There are already people in the developer forum that have found new ways to hook into the UIAlertView view hierarchy. I hope they get rejected in the review process and Apple continues to tweak the private class structure. Next step, burn it with fire!

My only concern is that @behrens suggests that people file a radar if they want to see the contentView property added in the future. What if I want it to stay gone? Do I file my own keep it out radar? Will enough people vote the same way with me?

Opaque Review Process

I understand the need to for an app review process. Apple doesn’t want to let broken or misbehaving apps in the store. I understand the time it takes to get to each review. It’s a popular store with thousands of updates a day. I know it takes time to have humans look at each and every one of those. Under those conditions I consider the current 4-5 days very reasonable.

What bothers me about the app store review process is the opaqueness. 5 years in, and there is still no indication of WHERE you are in line, i.e. how much longer you need to wait. When an app finally does go to In Review, there is no indication of what that process is or where your app is in the process.

90% of the time (for me anyway) reviews take less than 5 minutes. In the past I’ve gotten the Processing for App Store email before the In Review email, it goes so fast. But that other 10%, oh the 10%. That last 10% of the time reviews can take days. Why? Is there a policy question they’re checking with their supervisor about? Is the reviewer having problems logging in? Did they claim a whole bunch of apps for review off the presumably common review stack and then go home for the weekend? No idea. There is never contact from the reviewer. It’s just In Review. If it is a policy question, then why haven’t they ever contacted my to say “Hey, this is questionable”. I’d gladly change/remove whatever it is they have a problem with.

BTW: The web server logs show that no one has ever logged into the test account we provide for the reviewer(s) in the year I’ve been checking. Not once. How in depth can your review of the app get if you never get past the login screen? My last 3 day In Review time was on a 2-line x.x.1 release to fix a display bug the reviewer never looked at.

Promising Features to Others

Had another great idea come across my desk today that I would love to put into production and push out right away. Newbie Matt would have promised that feature in the next release, scheduled X.Y.Z day, possibly with a smiley face on the end of the mail.

Old grizzled Matt knows better. Old man Matt has had too many features postponed or killed by schedules, or management, or politics, or bugs to promise anything to anyone. Here are my 4 basic responses to great ideas now:

  1. That is a nice idea.

    That is it for ideas I have not actually written any code for. No estimates, no, “I want to do that”, no “I’ll try to make that happen”. Give any more than this and someone will end up disappointed when it does not happen.

  2. Let me think about that.

    You will this response if I have actually written the majority or what you are asking for, and have cleared it politically with QA, management, whomever feels they are entitled to make decisions about what I build.

  3. That should be in the next major release.

    You only get this far if I have already landed your feature in trunk/master (depending on your VCS), and our release process is such that we do not have a release branch cherry-picking features from master. Note the complete lack of a time frame on when that release might happen, and the two emphasized weasel words left in statement even at this late stage in the process. Should is there because features can always be removed due to political or technical integration reasons, and major because I need to leave an escape hatch to have a release without the feature (think small emergency bug fixes).

  4. Your feature has been available since version X.Y.Z release DD MMM YY

    That is right, the only way you get a specific time frame from grizzled old Matt is if your feature is already shipping, and preferably has had a few days to settle in and get tested by people who were not necessarily waiting for it, that way if they find bugs I have time to fix them before the person looking forward to said feature (you) get to use it.

It seems a little harsh, but I have been bitten too many times by schedules and politics to promise anything more.

Motivation for the Mundane

So where do you find the motivation to work on the boring stuff? I don’t mean documentation, unit tests, localization, etc. That stuff is fine, if it’s for a product you believe in. I mean having become more of a Product Person, how do you keep working on the projects that clearly are not the thing people will use because they want to, but because they have to?

I am responsible for 2 large products at work. App A is a consumer facing application available for public consumption in the app store. End users choose to download and run it not because they have to, but because it solves a problem for them better than loading a webpage on a PC, or using their bank’s Bill Pay solution. It has a never ending stream of feature requests and I’ve got my own giant backlog of technical improvements to bring it up to date. It is a Product with a capital P.

App B is a B2B enterprise behemoth. It is the kind of thing companies build to use internally, and occationally turn around and sell to others to defray the cost. No one will ever use this thing because they want to. It has a dozen programmers from a half dozen departments working on it because it needs to be everything to everyone. It is the very definition of dull business app. The only feedback it will ever receive is “It doesn’t work like giant system B’, therefore it sucks”.

My problem here is that management has ordered me to work on B full time to help get a prototype out the door, and I cannot force myself to work on it. Even though the objective part of my brain knows I need to work on it to fulfill certain contractual and political obligations, my impulsive side jumps at every single opportunity to work on App A, wether its “emergency” bugs, feature design, or even end user support. Toss in the mental preload time it takes for me to write good code, and I am way, way behind schedule. Even though App B should be all the fun part of software engineering, writing code, I just can’t do it.

So how do I get it done? I don’t know yet, but I’ve got probably got less than a week to figure it out or face some serious consequences.

Becoming a Product Person

Since I have transitioned from the realtime simulation world into mobile app development, I find myself becoming a product person. I suddenly have opinions about how software should look and how the UX should behave. I want to build things people choose to use because it is fulfills some need or want in their life not, because they have to use it to get their job done.

T-minus 1 Week?

I made my prediction on Twitter a few weeks ago, but I am going to make it slightly more formal here. My guess is WWDC2013 announcement & ticket sales are happening on April 24th, 2013.

Why? It is the day after the next earnings call. I predicted that about a month before it happened last year, and I think it will be same this year. The bean counter’s laywers are scared shitless of Sarbox, and prevent anything non-business news from happening anywhere except in the post earnings call free-for-all.

We’ll see. I’ve got no insight, I’m just some guy with a hunch. If I’m right, I look like a psychic, if I’m wrong I delete this post and no one ever cared.

Update: Nailed the announcement, did not see the delay in ticket sales coming.

Nodedub Walkthrough

A brief(?) introduction to the source for Is WWDC Sold Out Yet?

As I said in the release announcement, the site was a way for me to get some experience with a new toolset, so don't expect to see a lot of best practices or even correct practices when looking through the code. I had used nodejs on the job briefly before, but it was someone else's existing design, and I believe you don't really know a language/framework until you have built something in it from scratch yourself.

This is also not a How to get started with Heroku or How to get started with Node.js article. There are plenty of those on the web. I used several building it. This is just me trying to hit the highlights of what makes this site unique.

Before I start, I would like to thank @esigler for jumping on the domain registration and setting up a github repo and heroku instance as soon as we started joking about it on twitter. I definately would not have actually written this if he hadn't taken it seriously and created them right away.

dubstate.js

The app has 1 main piece of state. What is the current status of WWDC?

1
2
3
4
5
var DUBSTATES = {
  NO : {name: "NOPE", description: "Tickets are not on sale yet." },
  MAYBE : {name: "ALMOST", description: "Tickets have gone on sale. Go!"},
  YES : {name: "YEP", description: "You are too late, they sold out." }
};

apple.js

This file provides the meat of the application. Is WWDC actually sold out yet? It gets https://developer.apple.com/wwdc/, counts the number of instances of 2012 and 2013, and if 2013 is mentioned more, it assumes WWDC 2013 has been announced and triggers the state change from NO to MAYBE. This function is called every 5 minutes via a simple setTimeout() call.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var checkYear = function () {
  https.get('https://developer.apple.com/wwdc/', function(res) {
    var wwdcContent = "";
    res.setEncoding('utf8');
    res.on('data', function (d) {
      wwdcContent = wwdcContent.concat(d);
    });
    res.on('end', function() {
      var oldyear = wwdcContent.match(/2012/g);
      var newyear = wwdcContent.match(/2013/g);
      ...snip error checking...

      if ((dubstate.currentState == dubstate.DUBSTATES.NO) && (newyear > oldyear)) {
        dubstate.trigger("MAYBE");
      }
    });
  });
};

That trigger action at the end checks the database to see if it has already happened (restart, multiple nodes, etc) and if it hasn't, then it sends and email to everyone who has registered their email address.

Handling email

This part was tricky. Registrations trickle in slowly, but when the site changes, everyone expects to receive an email immediately. So to ensure we get as many emails out as we can and still keep it cheap/free to run, we:

  1. Confirm email addresses. Nothing too hard, just a simple encryption of the email address & a nonce bundled in a url for the user to click to make sure the recipient really wanted to be added. We send this confirmation through gmail since they happen slowly.
  2. Cull uncomfirmed addresses regularly. Lots of people will test with fake addresses for some reason, or bail when they find out it is a two step process. This keeps the record count low, and keeps us in the free rowcount for heroku.
  3. Once confirmed, add users to a mailgun mailing list. This allows us to send a single email when Apple's site is updated and ensures everyone gets it in a reasonable timeframe.

building the confirmation url

1
2
3
4
5
6
var confirmationString = email + ":" + nonce;
var cipher = crypto.createCipher('aes-256-cbc', credentials.aesKey);
var crypted = cipher.update(confirmationString, 'utf8', 'hex');
crypted += cipher.final('hex');
var url = "http://" + req.headers.host + "/confirm?confirmationString=" + crypted;
emailer.sendConfirmationEmail(email, url);

credentials.js

At one point in development I had most third party credentials (gmail, mailgun) hardcoded in the source, which is why the github repo has no history. It has since been changed to read these values from environment variables. Heroku and other cloud hosting services allow you to set these env vars easily based on environment (dev/test/production), and reading them in with javascript is extremely straightforward.

1
2
3
4
5
/* for encoding/decoding confirmation string */
exports.aesKey = process.env.CONFIRM_AES_KEY || "";
if (exports.aesKey == "") {
  console.log("Error: Missing AES key.  Won't be able to process confirmation emails.");
}

route/index

By default, the express framework uses the jade templating engine to reduce the amount of HTML you have to write. It takes a little getting used to, and I'll admit I barely learned enough to get a functional page displayed. This is one of many problems I have with ruby as well, I don't want or need a shorter HTML, I just want some defined way of inserting templated variables like with underscore.js or jquery.

the index javascript where variables are passed

1
2
3
4
5
exports.index = function(req, res) {
  res.render('index', { title: 'Is WWDC Sold Out Yet?',
                        value: dubstate.currentState.name,
                  description: dubstate.currentState.description });
};

the jade index template file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
extends layout

block content
  h1= value
  p= description

  if value == 'NOPE'
    p Register your email below to be notified when WWDC is announced.
    form(name="registration", action="/add", method="get")
      input(type="text", name="email", size="35", maxlength="320")
      br
      input(type="submit", value="Submit")

  if value == 'ALMOST'
    a(href="https://developer.apple.com/wwdc") WWDC at Apple

  br
  br
  a(href="/privacy") privacy policy

fin

That's it as far as the unique bits I think. There are some helper functions I wrote for accessing the database and emailing, but they are pretty self explanatory, and the app.js (int main() if you will) is mostly boilerplate stuff to get the server running and set up the routes/pages. If you want further clarification hit me up on email/twitter and I'll be glad to expand this post.