Skip to content


What I’ve Learned About Objective-C

I spent the start of 2013 working on my first iOS SDK. In no particular order, here’s some of what I’ve learned about Objective-C.

  • The hash of a collection is equal to the number of elements in that collection
  • Singletons (er, “shared singletons“) are an accepted pattern in Objective-C
  • Categories are cool. They’re kind of like Ruby’s mixins.
  • Class clusters defy expectations. You can’t cleanly override a method in a class cluster with a category.
  • The community seems to be suffering from Apple’s control. Too many mentions of “I can’t tell you because of NDA” on StackOverflow
  • Apple’s docs are pretty good… if you can find the right ones
  • There’s no easy way to build a “fat archive” and static framework unless you start with this project template, which I didn’t.
  • appledoc should be the de facto documentation engine now, but isn’t.
  • Unit testing networking code is much harder than it should be.
  • I miss Guava. Simple things like Objects.toStringHelper, Objects.hashCode, and EqualsTester.
  • I miss the builder pattern. Objective-C loves telescoping constructors initializers. Likewise, I miss Guice.
  • Many of my favorite libraries for unit testing have been ported to Objective-C.
  • The various abstractions for multithreaded programming are at war. GCD (the latest and greatest) vs NSOperationQueue (the most abstract) vs RunLoops. (Does this belong in this category? NSURLConnection can specify a runloop OR a queue, so I think so.)
  • Some (but not all) of CoreFoundation is open source. A lot of NS* classes are the same as their CF counterparts via “toll-free bridging
  • Variable argument lists don’t know the number of arguments without being told. Most people use a nil-terminated list. A format string (implicit count) or explicitly passing the count also works.
  • There is no NullPointerException; sending a message to nil is fine (no exception raised). This can really bite you in the ass.
  • There are best practices. Read them before you start your next (first?) iOS or Objective-C project. I found this after I figured them out in bits and pieces.

Since I was simultaneously writing an Android SDK, expect a similar post about what I learned about Android in the process.

Posted in Ramblin' Thoughts.


Open Source: Cassandra Super Columns to Composite Columns Migrator

If you’ve been following Cassandra’s development, you’ll know that its made huge progress in the last two years. My company first start using Cassandra v0.8.x, and the latest stable version is now v1.2.3.

One of the major changes was adding support for composite columns. In DataStax words, “composite comparators can be thought of simply as a comparator composed of several other types of comparators.” Since introduction of composite columns in v1.0, there’s been a trend to slowly fade out super columns in favor of composite columns. Cassandra itself is refactoring supercolumns to use composites under-the-hood in v2.0.

So when my company upgraded to v1.0, I wrote a little tool to migrate our data from using super columns to use composite columns instead. This was about a year ago, but I wanted to announce I’ve open sourced it on Github. Better late than never, right?

Grab the source and try it yourself **.

** Disclaimer: I waive all responsibility for your use of this code. Think twice before using it on a large production dataset.

Posted in News.


Case Study: Measuring Your Health

Ever step off the scale and wonder if a weight increase was due to gained fat or muscle?

A couple weeks ago, I was frustrated that my scale was showing the same weight, yet I could see my progress in the mirror and on the mat. That’s when I had a DEXA scan, and I’ve since learned how few people know about it.

If you’ve read any of my other case studies, you’ll know that I use numbers to make a lot of decisions in my life. I love DEXA because of the awesomely detailed and accurate information it can provide. A couple days ago, we learned why smart scales don’t cut it for measuring body fat; not coincidentally, data from a DEXA scan was used to make the point.

Now that I’ve built it up, I bet your wondering what kind of information you can get from DEXA.

  • whole body breakdown into lean pounds, fat pounds, and bone mineral content (BMC)
  • lean pounds, fat pounds, and BMC for each leg and each arm, your android (abdominal) and gynoid (hips/thighs) areas
  • lean mass symmetry, fat mass distribution, bone density, and more

Forewarning, your body-fat percentage will likely be higher than you expect. I was in shock on my first consultation. DEXA includes all the fatty tissues in your body, even those in your brain (around 3 pounds). If you weigh 150 pounds, that’s an instant 2% increase in body fat.

What’s this data look like? Well, I’m glad you asked.

Without further ado, here are my DEXA results as an example. Continued…

Posted in Case Studies.


Mixing old and new streams in Node.js

Streams in node are awesome. I’ve heard one of the core node contributors say, “if you’re not using streams, you’re doing it wrong”. Why are streams awesome? I’m glad you asked.

  • improve performance for large data sets—stream from source to response without buffering it all in memory
  • improve perceived responsiveness—start responding as soon as any data is available, rather than waiting for it all
  • clean service composition pattern—make a request to another service and stream its response back to the user, filtering or modifying it in some way in the process

However, streaming in node isn’t straightforward. This is more true with the introduction of Stream2, aka “new streams”, since module writers try to support both old and new streams.

I ran into this challenge the other day. After hours of debugging, I realized that mixing stream modes was the cause and I somehow stumbled onto a stupid simple solution. Continued…

Posted in Tutorials.


Smart Scales and Body Fat Measurements

Earlier today, I read a post by Daniel at Needless Pounds where he references a Full Body Sensor Monitor Scale. I commented about their lack of accuracy, but wanted to follow-up on my comment with data justifying my claim. This argument is based on data I’ve personally collected over the last few years. Continued…

Posted in Commentary.


Automating Cloud Applications Using Open Source

Ever wonder about the best patterns for the design, deployment, and monitoring of cloud applications? This presentation describes the current best practices used at BrightTag. Its from a talk given with two colleagues last year at CloudConnect.


Posted in Tutorials.


Fighting Salesforce Web-to-Lead Spam

I was recently tasked with fighting spam coming from contact forms on a website that uses Salesforce web-to-lead feature.

The contact form in question had previously posted to another PHP page which checked for a hidden field with a known value and, if the received value matches the known value, emailed the lead to the team. This is a very basic but effective spam deterrent, as bots tend to change the value of the field. But then the form was redone to post directly to Salesforce with all the data Salesforce needs to create a lead. While this resulted in a much simpler lead-creation process, it also resulted in a lot of spam as the “spam detection” facility was no longer used.

As I was rolling up my developer sleeves to write a simple PHP proxy to do spam detection and then post from PHP to Salesforce, I stumbled on this bit of documentation from Salesforce on their web-to-lead feature:

Salesforce runs field validation rules before creating records submitted via Web-to-Lead and only creates records that have valid values.

Inspired, I decided to try a pure-Salesforce spam deterrent hack. Continued…

Posted in Tutorials.


Urban Opportunities, or Why I Love Chicago

Everyone has heard folks say cities have more opportunities than suburbs or rural areas. Well, until I moved to Chicago 1.5 years ago, I didn’t really know what this meant. I always assumed it referred mostly to jobs, and maybe something about exposure to arts and culture.

But now that I’ve experienced these opportunities, I may never go back. My favorite analogy to describe the phenomenon takes us back to our high school days. In high school, we had a breadth of experiences Continued…

Posted in Ramblin' Thoughts.


Finding Generic Type Parameters with Guava

Over the last year, I’ve ran into a number of cases where refactoring led to a generic abstract base class that accepted its parameter type class in its constructor. Something like this-

public abstract class BaseClass<T> {
    private final Class<T> type;
    protected BaseClass(Class<T> type) {
        this.type = type;
    }
}
 
public class ConcreteClass extends BaseClass<String> {
    public ConcreteClass() {
        super(String.class);
    }
}

Note the duplication of the type in the generic parameter declaration and in the call to the superclass constructor. Sadly, this is the usual workaround pattern.

Until Guava, finding the parameter type of a generic wasn’t easy Continued…

Posted in Tutorials.


Automating Your Job Search

A friend of mine recently asked about my process when I was searching for a job. Although I briefly described my system, I’m afraid I really didn’t give the time to do it justice. This post is my penance.

When I was preparing to graduate in Fall 2011, I was undecided between building my own startup, joining the corporate world, and academia. Worse yet, I was undecided between four very different fields (education, architecture/engineering, computer science, and electrical engineering) and several focus areas in each (e.g., controls/robotics engineering, telecom/network engineering, software engineering, and sometimes computational cognitive science).  This breadth of interests means I had to cover a lot of ground to figure out my next step.

My first piece of advice: don’t make this mistake – narrow your search. But that’s probably obvious to most people. And if its not, just remember that your first job will not be your last, and in today’s society its common to switch between jobs and even fields numerous times during your life. I mean, I still have no idea what I want to do when I grow up :)

Now onward to the tactical stuff. My goal was to automate as much of the job search as possible. Continued…

Posted in Tutorials.




Log in here!