Is an Objective-C Minifier Possible?
My coworker-friend-buddy, Sean, and I are putting the final touches on our iPhone framework, iBoost. One thing we have to think about now is how it will integrate with our (and your) applications. There are two basic strategies I’ve seen:
- Copy the source code into the project. This is never done with Java projects, but is always an easy choice for C-based systems because compiled code is platform dependent. This is a very common choice for small classes, too. I make a lot of my mini-modules available this way.
- Compile as a library and copy header files. This involves distributing as a compiled library with header files. Flurry does this, as well as AdMob. The obvious motivation is to keep the source a secret.
-
Obviously, if wee distributed iBoost as a library, it wouldn’t be to keep the code secret (since it’s open source), but it’s still a valid way to go.
I lean towards the former. Dumping the source into your project may seem messier, but if you keep it isolated in a directory instead of copying it to your Classes, it’s really no different than library distribution. Plus, as the SDK iterates, and different platforms become available, you don’t have to worry about updating your libraries all the time. I just recently had to do this with the Acapela Text-to-Speech library and it was doubly painful because they are located in France and I needed it immediately. :-)
Minification
But now I have a new thought. It seems messy to distribute source as a large group of files. I’d love to make it a two-file (*.h and *.m) distribution. Hell, one would be great if it’s doable. But how?
Well, if you’ve been involved with the JavaScript scene the last few years, the little trick we like to do when publishing websites is to run a “minify” on the JS code. This is a script (there are several out there, but the YUI version is used a lot) that takes your JavaScript code, cuts out as much whitespace as possible, and basically runs your code through a vacuum. The resulting code is often unreadable, but (hopefully) works exactly the same. The idea is that you not only save some bytes of bandwidth, but it makes it a little harder for people to snoop through your code which is obviously uncompilable.
So, it is possible in Objective-C? I can’t find any references to it. No one seems to have done it. My guess is it’s doable. Here’s my theory on how it could work:
- Append all of the header files together.
- Pull out #import’s referencing any of the files themselves.
- Add forward references (@class) for all classes at the top of the file. (No need to ull existing ones unless we want to keep the file size minimal, which is not necessary.
I’m going to attempt it this week with a Python solution. I’ll let you know the results. What do you think?
Design Isn’t Just About Graphics Rapture In Venice’s Development Process
Comments are currently closed.
One thought on “Is an Objective-C Minifier Possible?”
This might make adding the code to another project easier, but it would make any reading/modification of the code later on terribly difficult.