/home/mbrennek

A mostly-fresh start

Ending Irrational HULK SMASH

Laura Savino gave a wonderful talk at CocoaConf in Seattle about about getting physically angry at bad code and how that’s not a good thing. That struck me particularly hard because I too get irrationally angry when I see bad code. If I’m lucky a long walk around the track at work is enough to calm down, but more often than not it seems like my whole day is shot and I go home grumpy.

I spent a lot of time last week reflecting on why I get so angry. Half the time it’s not code that I’m ever going to see again or have to maintain. Why am I upset? I didn’t get upset at the terrible code my fellow students wrote in the CS397 capstone class in college when I was grading. What changed in the last 10 years?

For me I think my intense irrational anger came when I rotated into my last group at my previous job. Up to that point everyone I had worked with before was either good at what they do, or at least still trying to learn and improve. What changed in my last group is that I discovered a new type of programmer. Ones with don’t-give-a-fuck-itis. They typically had 20-30 years of experience with the company, and were really just trying to hold onto a paycheck until the next round of layoffs would hopefully give them a chance at early retirement. I saw the absolute crap that DGAFites produced, and it was maddening.

Because I knew their grade level and the company’s pay scales, I generally knew about what they were supposed to be making. I was furious that these people were getting paid 2x-3x more than me to make mistakes a student would point out as obvious. Or claim a new technology they were investigating isn’t panning out while I watch one sit and read slashdot all day.

I stayed in that group for nearly six years. Over time my specific rage toward those people and the system that enabled their behavior translated to anger at bad code in general, regardless of the source. This is a problem. I’m supposed to be a senior engineer now at a company that hires mostly recent grads. When you’re new, making mistakes IS learning. It’s my job to mentor them. Show them not only what is wrong when they screw up, but why it’s a mistake in a supportive way. It’s my job to make sure they don’t end up the 30 year-old burn out with anger management issues. Step one is empathising with the newbies. I need to remember what it’s like to try something new and fail miserably. AFAIK no one at my current employer is just hanging on until pension time, and even if they were the pay gap between myself and them is much smaller. Anger at bad code is completely irrational and improper, and I musn’t see its author as a bad person who should feel bad for sucking, but just another human trying to grow and do better. As Daniel Steinberg said in his opening keynote, I need to try and Be Nice.

2014 CocoaConf Seattle Recap

I just spent this weekend at CocoaConf in Seattle, and it was great. From Daniel Steinberg’s Swift Kickstart, to Gus Mueller and Chris Adamson discussing Core Image, to Paul Goracke’s CoreData tips, there was a lot of technical content I can apply directly to either my day job or my side projects. It was also neat to finally meet some people I had previously only known through their twitter avatars. But I think the real personal value I got out of CocoaConf this week were a pair of keynote-style talks from the Khan Academy’s iOS developers.

First was Andy Matuschak’s Value and State: Functional and Imperative. I have been aware of a growning functional programming community for a while, but as with any new movement the die-hard extremists killed any enthusiasm I may have had into looking into. Plus, my cave-man brain actually LIKES C and C++, and one day I may finish the half-written post about why higher-level languages are hard for me. But Andy did an excellent job of breaking down what object and value types are useful for, and why separating action from logic is an important goal. He didn’t try to convince the room that we should write everything in a functional style (you can’t write useful software that way). Instead he advocated splitting objects into a thick value layer, and a thin imperative shell to handle responding to inputs from the system and tracking the change in versions of the immutable value layer.

The night before I had an idea for a new iOS side-project, and I had planned on starting in Objective-C, and sprinkling in Swift whereever it made sense. That is not how I’m going to learn and grow. Instead, I’m starting in Swift, and I’m only going to break into Objective-C when I can’t get something done in the current version of Swift. I with the standard library being almost entirely value types (structs), it will help me design my own software to act in a more functional way, without jumping whole-hog onto the crazy train.

As an asside, Brent Simmons had spoken the night before about (not) shipping Vesper for the Mac yet, but gave an impassioned arguement on why we should be writing Mac software. So this new side project is going to be written in Siwft, on iOS and Mac.

Finally what hit me the most was Laura Savino talking about being ANGRY at bad code, and how unhealthy and damaging that is to our relationships with other people. I have much more to write about my personal struggles with code hate, so I plan on breaking that out into a separate post instead of squeezing it in here.

Beth, Sam, and I are heading out tomorrow for a little vacation this week. I had planned on bringing 2 laptops and getting started on both my new project and some work-work I didn’t finish before CococaConf. Instead I’m going to leave them both at home, delete Tweetbot and Facebook, and spend a little time in reality. If you really need to get ahold of me this week just call instead.

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.