A git quickie
After reading Fraser Speirs’ excellent write-up on his conversion over to git, I followed a few of the links to find a bash script to display your current git branch in the command prompt. Following yet another link from that post showed how to convert the bash script to zsh.
Here is my contribution to move that from the prompt to the right side of the screen.
1 2 3 4 5 | function parse_git_branch { git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/' } function precmd() { RPS1="%~$(parse_git_branch)" } export PS1='> ' |
Note that the last line just gives me a very short left hand prompt which I prefer.
A Case Against Dot Syntax
I was not born an Objective-C developer. I know that in some circles that is considered a mortal sin. Before learning Objective-C and Cocoa I had developed in a great number of languages dating back to the early 1980′s. I tell you this so that what you are about to read next is taken in the light that it was intended.
Take a look at the following lines of code:
- (void)doSomethingSpecial { myVar.itsAttribute = 10; myOtherVar.itsAttribute = 20; } |
Now tell me, what is myVar and myOtherVar. Is it an object or a struct? Can’t tell from that piece of code can you. That is half of my argument against dot syntax in Objective-C. It makes the meaning of your code unclear. Objective-C is known for its self documenting nature. Dot Syntax removes that.
The audacity of [some] Windows Developers
Thanks to our beloved iPhone (I do refrain from calling it “My Precious”), we have seen a sudden influx of Windows Developers. Now, when most of us came over to OS X and Objective-C from whatever platform we hailed from we did not assume that everything would be the same. Most of us are reasonable people and realize that OS X is different for a reason. Unfortunately, it appears that we are unusual people. Perhaps this would explain why we came over to this platform before it became “popular”.
With this recent influx of developers, most of whom we have welcomed with open arms, there are some who expect everything to be the same as the platform they came from and without bothering to learn or experiment have proclaimed our development tools to be “prehistoric”. This truly amazes me.
First, welcome to OS X and iPhone development. This is not the same language, platform and API you have been dealing with. Accept that or go home. We are not going to change it to suit you. We like it just the way it is.
We do things differently over here. Accept that or go home.
You have an interest in either OS X or the iPhone. To do a proper application for either one (barring a few edges cases), you need to learn Objective-C and Cocoa. Accept that … well you get the idea.
Objective-C has been around for a long time and it is a well thought out language. It is a runtime focused language and therefore things work differently than you are used to in your more structured environments.
Most of the time when these so called developers complain about Objective-C I simply roll my eyes and walk the other way. It is the sane thing to do. Never wrestle with a pig — you get dirty and the pig likes it. However, one particular “genius” has decided to out himself on his own blog. Of course I speak of none other than Jesse Ezell.
It is clear from this blog post that he has no interest in learning why OS X, Cocoa and Objective-C are different from his beloved Visual Studio but instead cries that it is too hard. I mean, seriously, complaining about NSObject vs Object? Perhaps he did not bother to learn that there is more than one root object in Objective-C? And then go to on and complain about MVC like its the devil’s music? Hopefully he is not the best that .net has to offer us!
But even with all of that, I read his post, chucked and moved on. It was not until he responded to the comments on that post that I decided to respond. It seems, from his perspective, that if a developer cares enough about their development environment to respond to his rant (and try to educate him!) that we are all “rabit elitists” out to get him!
First the word is rabid, not rabit. If you were using OS X you could have seen that it was misspelled and used the dictionary to figure out what the word meant. If you can’t even bother to run a spellchecker why bother writing at all?
Second, we care about our platform. We care about the code that we produce and how our applications look and are presented to the user. I know that is probably an extremely foreign concept where he comes from. But we care!
When developers come over here with preconceptions they do everyone a disservice. If they cannot even be bothered to pick up a book and read about the language to understand its fundamentals and its tools then why bother complaining about it. They are a waste of space. Move over and let someone who is willing to learn step up to the plate.
As for this developer’s ego and contempt for the developers on this platform — shame on him. His arrogance speaks towards his ignorance. He probably has written more lines of code in the past few years than I have. I have found that applications on Windows tends to take ten times as many lines of code as the same application would written on Objective-C and Cocoa. That does not make this developer better — if anything it makes him worse.
My suggestion is this: Pick up a book and read. You can even just read blogs like this one and avoid having to pay any money to learn. If a developer can’t be bothered then go home, we have no interest in you and certainly have no need for you.
Where has cimgf gone?
As you can probably imagine, we have been heads down coding for the past month. Can I tell you what I am working on? Nope and if you are in the community you can guess why.
However, here is a hint.
What does a deadline look like?
And my desk to go along with that link:
Coding Practice: Cleaning up the default Core Data project
In this entry I am going to do something a little different. Instead of showing some wicked code, I am going to reformat one of Apple’s default templates.
Apple writes some amazing code. Unfortunately a lot of their templates demonstrate simply terrible coding practices. What is worse, people take these templates and assume that they are the proper practice for coding in Objective-C and propagate that poor code into their own projects.
The first example I am going to tackle is the AppDelegate class that is auto generated in the Core Data template. This is not the Core Data Document template but the standard application template.
Cocoa Tutorial: Expanding NSError Usage
As a follow-up to the previous blog post: Cocoa Tutorial: Using NSError to Great Effect; in this post I am going to demonstrate a few things that can be done with NSError objects that have been received. Specifically, how to add options to an NSError and how to (hopefully) recover from one. (more…)
WWDC 2008 T-Shirts!
May 20, 2008
The T-Shirts for delivery at WWDC have been ordered. If there is enough interest I will setup a way to purchase CIMGF T-shirts (non-WWDC) directly from the site. Please contact me at marcus at cimgf dot com if this is of interest to you.
Last year I wore t-shirts for Zarra Studios and got quite a few compliments. These days I am becoming more known for this blog than anything else. Therefore, I am doing different t-shirts this year to celebrate this blog. As a reader of this blog you have an opportunity to purchase one of these shirts. They will only be run for WWDC so they are limited edition! :)
While the design is not complete yet, here is the first public draft of the T-Shirts:


Currently, the plan is to take them with me to WWDC and hand them out to those who have purchased one right after the keynote on Monday. If you are not going to WWDC but would still like to order a T-Shirt, that is also doable but naturally shipping costs will be involved.
The price per shirt will be $20.00 US. If you are interested in purchasing one or more, please contact me at marcus at cimgf dot com and I will work out the details. Right now I am processing orders manually but if they get too crazy then I may set up an actual shopping cart. Quantities are limited so act now! ;-)
Lastly, to follow Justin’s great idea. I am interested in trading T-shirts with other WWDC attendees. If you have a NEW shirt that you would like to trade for a CIMGF shirt, please contact me at marcus at cimgf dot com to plan a swap.
All Orders must be received and paid for by the 19th of May, 2008. Any orders received after that date can be shipped but cannot be delivered to WWDC.
Legal Junk
It is not my intention to make a profit on these t-shirts. I am offering them to readers at the approximate production cost. It is not my intent to mass produce these t-shirts with the goal of making a profit. If the production run comes close to or exceeds 500,000 t-shirts (wouldn’t that be amazing!) then the artwork on the back of the t-shirts may change due to restrictions in the license agreement.
Cocoa Tutorial: Wiring Undo Management Into Core Data
Undo support in Cocoa is fantastic but for those who have tried to mix it with Core Data know that it can be a bit frustrating. Generally, undo support can be ignored in most applications and it will “just work”. But when Core Data is added to the recipe then things get a bit confusing and more complicated.
Cocoa Tutorial: Don’t Be Lazy With NSDecimalNumber (Like Me)
NSDecimalNumber is Objective-C’s solution to numbers that need to be very precise. The documentation defines it as:
NSDecimalNumber, an immutable subclass of NSNumber, provides an object-oriented wrapper for doing base-10 arithmetic. An instance can represent any number that can be expressed as mantissa x 10^exponent where mantissa is a decimal integer up to 38 digits long, and exponent is an integer from –128 through 127.
NSDecimalNumber
If you are dealing with currency at all, then you should be using NSDecimalNumber. However, since it is immutable and definitely not a primitive then it is difficult to use right? Well — yes — a bit. But if you do not want to see your $9.50 item displayed as $9.49999994 or something then you are better off using NSDecimalNumber right from the beginning. Otherwise you are going to be converting to it later and that is a LOT more painful.
Cocoa Tutorial: Get The Most Out of Key Value Coding and Observing
Key Value Observing/Key Value Coding (KVO/KVC) is probably one of the most powerful and most under-utilized features of Objective-C. Here are a couple of examples of how to get the most out of it
When a call is made on an object through Key Value Coding such as [self valueForKey:@"someKey"], numerous attempts are made to resolve the call. First, the method someKey is looked for. If that is not found then the iVar someKey is looked for. If neither of those are found, then one last attempt is made before presenting an error. That last attempt is a call to the method -(id)valueForUndefinedKey:. If that method is not implemented then an NSUndefinedKeyException is raised.
valueForUndefinedKey: is designed so that when you request a value from an object using -(id)valueForKey: the object has a last chance to respond to that request before an error occurs. This has many benefits and I have included two examples of those benefits in this post–Core Data Parameters and Data Formatting.
Git and XCode: A git build number script
Git has been gaining in popularity with Cocoa developers as well as open source developers. As I work it into my development workflow, one item that was missing was the automatic injection of the build number into the application bundle.
There are a few scripts floating around that perform this trick for subversion, but git handles build numbers a bit differently and it appears that no one has bothered to publish one. As is known, subversion uses an incrementing integer for build numbers. This makes it very easy to determine which build number came first and makes it very useful for a non-public version number. Git, however, uses a hash for each build number which is not incrementing and therefore not very useful for determining version numbers. However, it is still very useful for pulling up a specific build when a crash report is received, etc.
Therefore, with the help of Matt Long’s perl-fu, I have updated Daniel Jalkut’s subversion perl script to work with git. Since the build numbers are not sequential, I would not recommend using them for Sparkle. Therefore, in my own build process for iWeb Buddy, I hand select the version number (for example 1.0.4) and then use the short hash from git as the CFBundleVersion number. Normally this number is displayed in parens after the primary build number but, at least in iWeb Buddy, I have removed it from the display entirely. Since it is no longer a sequential number it would only potentially confuse users and it displays in the crash reports anyway.
The updated script is as follows:
# Xcode auto-versioning script for Subversion by Axel Andersson # Updated for git by Marcus S. Zarra and Matt Long use strict; # Get the current git commit hash and use it to set the CFBundleVersion value my $REV = `/opt/local/bin/git show --abbrev-commit | grep "^commit"`; my $INFO = "$ENV{BUILT_PRODUCTS_DIR}/$ENV{WRAPPER_NAME}/Contents/Info.plist"; my $version = $REV; if( $version =~ /^commit\s+([^.]+)\.\.\.$/ ) { $version = $1; } else { $version = undef; } die "$0: No Git revision found" unless $version; open(FH, "$INFO") or die "$0: $INFO: $!"; my $info = join("", <FH>); close(FH); $info =~ s/([\t ]+<key>CFBundleVersion<\/key>\n[\t ]+<string>).*?(<\/string>)/$1$version$2/; open(FH, ">$INFO") or die "$0: $INFO: $!"; print FH $info; close(FH); |
Since git is distributed, there is no need to be online to produce a build. The script will grab the current abbrev-commit hash and will inject it into the current build’s Info.plist file.
Cocoa Tutorial: Using NSError to Great Effect
Error handling is rarely fun. I find myself often re-coding a method after I realize that I need to handle one error condition or another. Usually, error handling involves either try/catch or some return code strategy. Neither of those is pretty or easy to maintain. For Objective-C development, however, there is another option — NSError. (more…)
Cocoa Tutorial: awakeFromNib vs applicationDidFinishLaunching
When developing an application in Objective-C and using Cocoa, there is a lot of “magic” that happens in the background. As we get more comfortable with the language and the APIs, we begin to discover the source of that magic and understand not only WHY it works but HOW it works.
One of those areas is the initialization and callbacks from the nib files to my code. Normally, when I want a controller to do something after the NIB/XIB has loaded, I add the method -(void)awakeFromNib and know that I will receive a call when all of the connections into the NIB/XIB are complete. But on what object does this get called and how?
Git and .mac: A Match Made In Purgatory
Last year, I made the switch from subversion to Git. After 9+ months of using Git, I can comfortably say that it was a very good choice. While branching is easy in subversion, merging is just as bad as it was in cvs. Git is a significant improvement over that. In addition, since Git is a true distributed source control system, I can easily do branches and merges on my local machine without an internet connection and just “push” my changes to my off-site server when it is convenient.
I am also a user of .mac. I like the service and the iDisk is probably my favorite feature. Therefore, I wondered, like chocolate and peanut butter, could I put these two together and come up with something better than the individual parts? (more…)
MacBook Air: Thoughts and Issues
For those of you who only read this blog for coding suggestions and tutorials — please hit next on your feed reader :)
For those who are also interested in our development environments, hardware, etc. then please read on. (more…)



