An Afternoon With Cappuccino 5

Posted by Justin Reagor Sat, 28 Mar 2009 19:16:00 GMT

Ok, so I know all about the Cocoa inspired, Javascript framework, SproutCore (with it's tiny bit of Ruby for the "build process"). It definitely has the leverage of being based on current web technologies. As well as used by Apple for the "highly successful" MobileMe service (hehe). While making excellent use of the fat client pattern.

However, I just tried out Cappuccino, by way of Objective-J, and ran through some tutorials. The power of the GNUstep/Cocoa frameworks are definitely something to be seen within your web browser.

I am starting to think I prefer this more for utilizing desktop applications on the web. In a similar vein as Java applets or Flash web apps. Because that's what Cappuccino and SproutCore were built for, desktop-like web applications. Not traditional "web sites" or hyper text documentation.

Short Intro

Objective-J is the language written using Javascript. Where Cappuccino is the framework built with Obj-J. A rewrite of Cocoa and GNUstep for the DOM.

The wiki defines Objective-J as...

... a programming language developed as part of the Cappuccino web development framework. Its syntax is nearly identical to the Objective-C syntax and it shares with JavaScript the same relationship that Objective-C has with the C programing language: that of being a strict, but small, superset; adding traditional inheritance and Smalltalk/Objective-C style dynamic dispatch to JavaScript. Pure JavaScript, being a prototype-based language, already has a notion of object orientation and inheritance, but Objective-J adds the use of class-based programming to JavaScript.

Taking a small look at some of the code you will see its heavy Obj-C syntax...

@import <Foundation/CPObject.j>   

@implementation AppController : CPObject {   
  CPTextField label;   
  CPString contentString;   
};   

- (void)applicationDidFinishLaunching:(CPNotification)aNotification {   
  var contentString = @"Hello world!";   
  var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],   
  contentView = [theWindow contentView];   

  label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];   

  [label setStringValue:contentString];   
  [label setFont:[CPFont boldSystemFontOfSize:24.0]];   
  [label sizeToFit];
  [label setAutoresizingMask:CPViewMinXMargin |
                                                   CPViewMaxXMargin |
                                                   CPViewMinYMargin |
                                                   CPViewMaxYMargin ];
  [label setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([label frame])) / 2.0,
                                (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([label frame])) / 2.0)];

  [contentView addSubview:label];
}
@end;

The Pros

No one is suggesting you to ditch your life as a strict web standards developer and embrace the auto-generated presentation layers that Cappuccino provides. Instead, embrace the tool (TWSS). Use it when its the most appropriate.

Here are the positive bits I can identify at first glance...

  • Utilizes a proven platform and framework for desktop applications, Cocoa and GNUstep
  • Automagic cross browser support; from everything being abstracted away from you.
  • Obj-J can have Javascript intermingled, so you can write in a style with a cross between the two (hence the J).
  • NO PLUGINS; They wrote the damn lexer/parser entirely in Javascript. That's not JS ignorance, that's talent.
  • It seems pretty snappy and fast.
  • Used in production, considering 280slides.com is a killer web app.
  • Obj-J command-line interpreter
  • Theme support coming
  • Rake now employed for the "build"

The Cons

I've read through a ton of grips, mostly the introduction on Ajaxian. It seems that people at first believed this was an insult to Javascript. That there wasn't much of a purpose in bringing Obj-C to the web since HTML/CSS/JS work just as well. Of course the same people say the same thing about Java and Flash... but anyway, here are a few I'm watching out for.

  • Layers of abstraction are a plus, and a minus. :<
  • Seems you can only leverage current web tech (HTML/CSS/Canvas) through Cappuccino/Cocoa objects.
  • I haven't experienced their inheritance model yet, so I'm hoping thats not a hinderness (as in creating your own NSTableView or whatever).
  • The HTML source is completely obfuscated, and I imagine you can't make use of the DOM (restricted to Obj-J classes)
  • No command console [IRB]? Haven't found one yet.
  • Some error messages are vague.
  • Test/Behavior driven development? OJUnit does exist, haven't checked it out though.

EOF

The fact that the W3C and the industry are going to take decades to complete HTML5 and full CSS3 compliant browsers demonstrates the viability of this framework. No plugins, no compilation, just run the damn apps is POWERFUL. Also, given the success of Apple's platforms so far, Obj-C is proving itself on the desktop and on the iPhone. It's definitely not the horror that is VB.

Given those I think all-in-all it's a wonderful technology and I look forward to building a few apps with it!

Comments

Leave a response

  1. Avatar
    cheapRoc about 2 hours later:
    "objj is a command line Objective-J interpreter and interactive console", just noticed that ;)
  2. Avatar
    mike about 3 hours later:
    Please check out Human pheromones, pheromone cologne by Alpha Dream. Human pheromones help improve your sex life and dating success. Pheromones cause others to be more attracted to you, and help revamp your love life. Human pheromones are for men and women of all ages, and are provided in unscented sprays, or in cologne and perfume.
  3. Avatar
    Charles Jolley about 5 hours later:
    I think you missed that SproutCore is a JavaScript framework, not ruby. Ruby is just used for its build tools; only static JS, HTML, and CSS goes into production. Also, SproutCore is based on Cocoa as well, but it adapts the patterns to JavaScript so you don't have to pay extra overhead. That's why it is used for some of the most widely used desktop-like apps on the web.
  4. Avatar
    cheapRoc about 23 hours later:
    I was more referencing its use of Merb as a server backend, but maybe I'm wrong. Either case, I was making an assumption that others know that. We also usually have articles here about Ruby, so I was sloppily attempting to point out the Ruby support within SproutCore. Hey, don't get me wrong I love SproutCore as well. Maybe I need to praise it more with a cuttie filled article too. ;)
  5. Avatar
    cheapRoc about 23 hours later:
    Updated the article to reflect your remarks. Going to do a SproutCore article in the next week or so, to properly present a contrast. Thanks Mr. Jolley!
Comments