With the coming out of Leopard, I’m truly excited about the new programming features, it gives me lots of ideas about applications I’d like to build.
But each time I dig into the Cocoa Fundamentals, I’m just having a heart attack. Why desktop programming is still stuck in the 80s and so unproductive?
Here is a simple Cocoa command-line program. Given a series of arbitrary words as arguments, the program removes redundant occurrences, sorts the remaining list of words in alphabetical order, and prints the list to standard output.
$ filter a z c a l q m z
a
c
l
m
q
z
Simple isn't it? Here is the code in Objective-C using the Cocoa framework:
int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSArray *args = [[NSProcessInfo processInfo] arguments];
NSCountedSet *cset = [[NSCountedSet alloc]
initWithArray:args];
NSArray *sorted_args = [[cset allObjects]
sortedArrayUsingSelector:@selector(compare:)];
NSEnumerator *enm = [sorted_args objectEnumerator];
id word;
while (word = [enm nextObject]) {
printf("%s\n", [word UTF8String]);
}
[cset release];
[pool release];
return 0;
}
Erk! It just gives me spots, look at all the code you have to write to setup the objects. Funny enough, the documentation says:
The first thing you probably notice about this code is that it is short, perhaps much shorter than a typical ANSI C version of the same program.
Short? Here is what I call short:
ARGV.uniq.sort.each { |e| puts e }
Objective-C 2.0
Leopard comes with Objective-C 2.0 that features garbage collection and better iterators. But in the end, that won't make much difference -- it might remove a couple of lines in the above code. Despite its dynamic features and its huge libraries for Mac OS X, Objective-C is still a low-level programming environment.
In understand that in Mac OS X, power comes from the tools which removes part of the burden of writing code but it's not that ideal.
Ruby and Python Bridges
Leopard also comes with Ruby and Python Obj-C bridges so that you can -- in theory -- write Cocoa applications. I say in theory because any attempt so far has failed.
I guess the gap between Obj-C and high-level languages is just too big and makes inter communication complex.
No Flame Wars
I'm not starting another flame wars about programming languages, performances issues or compatibility. The above two examples are not just on the same abstraction level.
I just hope that in the future we'll see high-level programming environments wired into OSes so that we can write apps faster. In that regard, Microsoft has done a pretty good job by giving C# more and more expression power without breaking low-level compatibility.
CTO at 



Comments
[...] Check it out! While looking through the blogosphere we stumbled on an interesting post today.Here’s a quick excerpt [...]
My Ghillie » Why Desktop Programming is such Unproductive?20 October 07 at 1:46 pm
It really isn’t as bad as you think. I agree with you that writing apps should be “easier”, but then again Objective C is basically C and C is basically hard
The thing with Cocoa (and especially with Core Data) is that it really isn’t that “hard” to make a beautifully looking and fully functional application. I would suggest to you to check out some Core Data tutorials on Apple’s site and others… I just started using Obj-c/Cocoa/Core Data a month ago and it took a couple of days for me to prototype my app’s interface and have full undo/redo as well as open/save functionality… without having to write more than a few (maybe 20-30) lines of code.
I agree that some things should be easier in Obj-C, especially for data analysis, parsing, etc… but I think the whole app design framework was made to be able to design the interface easily and have full control over the back-end code.
I guess if you are only talking about pure command line apps then I can understand your complaints… but then again, just use perl/ruby/python for that stuff.
David Caplan20 October 07 at 2:09 pm
It really isn’t as bad as you think. I agree with you that writing apps should be “easier”, but then again Objective C is basically C and C is basically hard
The thing with Cocoa (and especially with Core Data) is that it really isn’t that “hard” to make a beautifully looking and fully functional application. I would suggest to you to check out some Core Data tutorials on Apple’s site and others… I just started using Obj-c/Cocoa/Core Data a month ago and it took a couple of days for me to prototype my app’s interface and have full undo/redo as well as open/save functionality… without having to write more than a few (maybe 20-30) lines of code.
I agree that some things should be easier in Obj-C, especially for data analysis, parsing, etc… but I think the whole app design framework was made to be able to design the interface easily and have full control over the back-end code.
I guess if you are only talking about pure command line apps then I can understand your complaints… but then again, just use perl/ruby/python for that stuff.
David Caplan20 October 07 at 2:09 pm
even adobe is thinking about bringing photoshop to the web. when we will be there, there is no point to create desktop software.
heri20 October 07 at 8:20 pm
even adobe is thinking about bringing photoshop to the web. when we will be there, there is no point to create desktop software.
heri20 October 07 at 8:20 pm
@david Thanks for your comment. Despite my negative feedback, I also think that Cocoa is a great framework given its low-level nature.
I gave a try to CoreData two years ago and it was not that bad — the lack of programming abstraction is compensated by the tools.
The command-line program was just for the matter of example, I would not used Cocoa to do that kind of job.
Frederic Brunel21 October 07 at 12:22 am
@heri complete online software is an holy grail and I’m still a big fan of desktop software — especially for the Mac — the experience is totally different from the web.
Actually, I don’t think both compete, an hybrid combination would make a perfect sense, i.e. iTunes Store.
Frederic Brunel21 October 07 at 12:27 am
@david Thanks for your comment. Despite my negative feedback, I also think that Cocoa is a great framework given its low-level nature.
I gave a try to CoreData two years ago and it was not that bad — the lack of programming abstraction is compensated by the tools.
The command-line program was just for the matter of example, I would not used Cocoa to do that kind of job.
Fred Brunel21 October 07 at 12:22 am
@heri complete online software is an holy grail and I’m still a big fan of desktop software — especially for the Mac — the experience is totally different from the web.
Actually, I don’t think both compete, an hybrid combination would make a perfect sense, i.e. iTunes Store.
Fred Brunel21 October 07 at 12:27 am
Bit Torrent on MacOSX was written in Python using Obj-C binding. I think this was a great app (and still using it on my Intel box, even if it is a PPC binary). It is probably possible to write good software with Ruby too with a bridge.
I think this is a matter of habits.
casa24 October 07 at 5:49 pm
Have a look at http://www.apple.com/macosx/technology/unix.html, especially “Scripting Bridge” part.
MacOSX rules
casa24 October 07 at 6:16 pm
Hi Michel,
Interesting. If Apple truly support these bridges within their tools that’s a very good news.
Actually, the Java bridge failed and they didn’t support it anymore. I’ve been told it was because Java is “less dynamic” than Obj-C and that lead to troubles.
On the opposite, Python and Ruby are “more dynamic” than Obj-C, so they would be a better fit.
OS X rules, I agree
Frederic Brunel24 October 07 at 6:26 pm
Bit Torrent on MacOSX was written in Python using Obj-C binding. I think this was a great app (and still using it on my Intel box, even if it is a PPC binary). It is probably possible to write good software with Ruby too with a bridge.
I think this is a matter of habits.
casa24 October 07 at 5:49 pm
Have a look at http://www.apple.com/macosx/technology/unix.html, especially “Scripting Bridge” part.
MacOSX rules
casa24 October 07 at 6:16 pm
Hi Michel,
Interesting. If Apple truly support these bridges within their tools that’s a very good news.
Actually, the Java bridge failed and they didn’t support it anymore. I’ve been told it was because Java is “less dynamic” than Obj-C and that lead to troubles.
On the opposite, Python and Ruby are “more dynamic” than Obj-C, so they would be a better fit.
OS X rules, I agree
Fred Brunel24 October 07 at 6:26 pm
I found an interesting article on Ruby on Leopard at this address http://trac.macosforge.org/projects/ruby/wiki/WhatsNewInLeopard. And here is the adress of the blog of the guy that was responsible for Python and Ruby integration at Apple : http://chopine.be/lrz/diary/.
To sumarize : bridges are now shipped with the OS.
Enjoy!
casa28 October 07 at 4:24 pm
I found an interesting article on Ruby on Leopard at this address
http://trac.macosforge.org/projects/ruby/wiki/W....
And here is the adress of the blog of the guy that was responsible for Python and Ruby integration at Apple : http://chopine.be/lrz/diary/.</p>
To sumarize : bridges are now shipped with the OS.
Enjoy!
casa28 October 07 at 4:24 pm
Leave a comment