3 January 2014
iOS 7 only is the only sane thing to do

I’m porting an app that was originally targeting iOS 3 to an iOS 7 support only. Almost three years later, so much have changed.

When I started programming it, iOS 4 was pretty new and not everyone upgraded to it. You know, there wasn’t over-the-air upgrades and you had to use iTunes for upgrades. No wonder only geeks were upgrading.

We decided to support iOS 3. Here are some stuff that weren’t available back then:

Blocks. Can you imagine programming without using blocks? I can’t, but that’s what we did back then.

GCD. There was no Grand Central Dispatch. Doing background work wasn’t easy as it is today.

ARC. No automatic reference counting meant worrying a lot about leaks, crashes and retain cycles. With ARC, you mainly have to consider retain-cycles and choosing between weak and strong references.

UIAppearance. There was no way to customize the basic UIKit controls. If you wanted a UISwitch with a different color, you had to build a complete custom switch control by yourself. It’s not just UIAppearance, it’s more that Apple understood that apps needs a unique look.

The list goes on and on. These are the things that I added to the app as time went by. When iOS 5 came around, we dropped iOS 3 support, introduced blocks, GCD and ARC into the app. When iOS 6 came out, iOS 4 support was abandoned and we could more easily customize the look and feel of the app.

Our current app is supporting iOS 6 and iOS 7 at the same time. This is horrible. We can’t leverage what iOS 7 has to offer and a lot of the UI is compromise. Going iOS 7 only is the only sane thing to do.

As we’re going for an iOS 7 only release here are some things I’m glad for:

Pull To Refresh. When we added pull to refresh to our app there weren’t many apps using this technique and it added a premium feel to our app. Our custom built pull to refresh control is no longer needed as Apple added UIRefreshControl a long time ago.

UIViewController Containment APIs. It’s so easy to keep sanity with UIViewControllers and the containment APIs allow creating a smart and scalable view hierarchy.

Custom Tab Bar. To customize it, we had to build our own UITabViewController subclass. Who needs it now. Deleted.

Custom Navigation bar. We wanted a background image for it, this wasn’t possible back then. Also gone.

HTML Strings. I remember that for adding an underline to some part of a UILabel, you had to split it into 3 parts. Not anymore, Attributes strings are so easy to create these days, you can even use HTML to create them.

@2x only. The era of retina only devices is here. Goodbye half of the images.

Flat out. A lot of retina images are also on their way out since most of the design gone flat. Almost no need for images

viewDidUnload. It’s not being called anymore by the OS. Wow, a lot of code is going to the trash!

AutoLayout. Not sure what I think of this yet. One thing I do know is if you’d like to achieve a html/css like rendering of UIViews then this is the way to go. Instead of calculating UILabel heights, let iOS do it for you.

UIDynamics. We’re surely not going to use this too much, but when physics are needed, we’ll surely use it.

Receding keyboard like the messages app. This was one feature we really wanted and implementing this was painful as hell. I can’t believe it’s now just a boolean value away.

There are so many options to make the app much better with iOS 7: Better handling of push notifications, background fetches, custom transitions, multipeer connectivity and so much more. iOS 7 also keeps us focused on the content and not the chrome, this is the ultimate key strength of iOS 7.

The iOS 3 app pushed what’s possible to the edge and beyond, I’m hoping to do the same for iOS 7.

27 December 2013
Detecting if a Backbone Model needs to be saved

I’ve answered a question on stackoverflow and I thought it might be useful for anyone using Backbone.

The question is how to detect if a Backbone Model has changes that requires it to be saved to the server. This is usually good for enabling/disabling the save button on forms.

The idea is that the model listens to its own changes and marks itself as changed. When it does sync with the server (read or write) it sets this flag to not-changed.

Here’s the code:

13 December 2013
Being professional on side projects

At Work

At my day job, I’m doing my best to be professional.

I never commit crappy code into the repository.

I unit test a large chunk of my code.

I make sure features can scale.

I have scripts for all repetitive work.

I monitor every web service for errors.

I think about backward and forward compatibility.

I take special care to write code that is easy to understand for other people and future-me.

At Home

As a part-time-indie-developer working on a side project, it’s easy to forget about all of this. Who’s got the time to think about being professional when you just want to hack a simple product over the weekend?

I do.


A big part of my knowledge and experience is based on stuff I learn on my free time. I then take this knowledge and apply it at my day job. If I have crappy work habits at home, they’ll soon propagate to my workplace as well.

So I’ve started to collect some new habits towards awesome-ness:

I use version control. I’ve never used it for personal project and I don’t know why. We introduced Git (and Git Flow) into my workplace recently and we love it! Now Git also powers all my side projects.

I open source code I’ve written. It’s always a good idea to have another set of eyes examine your code. Open sourcing code allows for it. Some of my projects are already up and being used by github’ers (Check out Sequencer, Backbone.setters.getters and my github profile).

I script repetitive tasks. As I’ve already mentioned in a recent blog post, my iPhone app configuration can be controlled remotely. I used to manually upload a JSON file to my servers. It was boring so I scripted this task. It now takes less than a second to deploy a new configuration.

All these habits does come with an overhead, but it should pay off in the long run.

28 November 2013
Abuse Twitter to get x5 more exposure per tweet

Twitter recently made a critical change to the Twitter feed.

Images attached to tweets are now displayed without the need to tap/click them. This chance is probably for advertising purposes as can be seen in the following timeline:

I don’t really like this change, because now Twitter is no longer about who writes better. It’s about who attaches the best image.

Is this the kind of Twitter world we want to live in?

I don’t like it, but I’ll abuse it if they let me

From now on everytime I tweet about a new blog post I’ll attach an image. It could show a code snippet, a part of the first paragraph or just the title of the blog post written with a nice font as an image.

Here’s the one for this post:

I’m going to test this using ads.twitter.com for statistics. You can use it too even if you don’t advertise. I don’t, I’m not even eligible… whatever.

I had a few tweets with photos in them and they are all 5X better (favorited/clicked/retweeted) than my average text-only tweets.

I guess Twitter will change it shortly when they notice the issue (everyone will start using images, especially business Twitter accounts). The change will probably only expand images from popular tweets (with many retweets and favorites).

Until then, let’s take advantage of it it together. I’m @ketacode on Twitter, let’s meet there.

24 November 2013
Javascript Hacks for Hipsters

Javascript is so much fun, except when it’s not.

There’s always the fear of runtime errors that keeps us thinking all the time while writing code. It makes us better coders - we have no other option than to visualize every line of code as if it’s running as we write it.

That’s why it’s so important to have tidy code. Small code. Pretty code. Code you just fall in love with. Otherwise, Javascript will scare you away.

I gathered some fun snippets I enjoy using instead of boring code that takes too much space. Some makes the code shorter, cleaner and more readable. Other are just plain hacks for debugging.

I learned all of this from open source code (until node.js all javascript code was open source, wasn’t it?), but I’ll write them here is if I invented them.

Hipster Hack #1 - Method calling

I really hate if/else blocks and this is quite a useful trick to call the right function based on a boolean value.

Hipster Hack #2 - String joins

It’s a known fact that strings like other strings. Sooner or later you’d like to concatenate two or more of them. I don’t really like +ing them together, so join() comes to the rescue.

Hipster Hack #3 - Default Operator ||

Javascript is all about not knowing what an object holds. Sometime you get it as a function argument, other times you might read it from the network or a configuration file. Either way, you can use the || operator to use the second argument if the first is falsy.

Hipster Hack #4 - Guard Operator &&

Similar to the Default Operator, this one is super useful. It eliminates almost all IF calls and makes for a nicer code.

Hipster Hack #5 - XXX Operator

This one is totally copyrighted and also SFW. Whenever I write some code, but then have to consult the web, or a different part of the code, I add an xxx line to the code. This makes the code break so I can get back to the specific place and fix it later. Much easier to search for it (xxx usually never appears) and you don’t have to think about a TODO comment.

Hipster Hack #6 - Timing

Ever wonder what’s faster: Looping with an i++ or looping with an i— ? Yeah, me neither. For those who does, you can use the console’s timing methods to test for slow loops or any other event-loop blocking code.

Hipster Hack #7 - Debugging

I learned this one from a Java developer. I have absolutely no idea how he knew about it and I didn’t, but I’ve been using it ever since. Just drop a debugger statement and the debugger will stop on that line.

Hipster Hack #8 - Old School Debugging

I’ve always been a “printf debugger” more than a line-by-line-in-a-debugger kind of developer. If you’re like me, you’ll want to “export” some private vars into the global scope in order to examine them from time to time. Don’t forget to remove these before committing/pushing-to-production.

Hipster Hack #9 - Ultra Light Templates

Are you still concatenating strings using the + operator? Here’s a better way to combine a sentence with your data. It’s called templating and here’s a mini framework in 2.5 lines of code.

Already knew them all?

Even the copyrighted XXX Operator invented by me?! You’re a true hipster hacker, let’s talk more on twitter.