On Leaky Abstractions and Objective-J

In a recent post by John Resig, and in many of the comments, there seems to be the mistaken belief that Objective-J was designed to allow existing Objective-C programmers to write code that runs on the web. It’s been compared to GWT, where developers program almost exclusively in Java and are allowed to “circumvent” JavaScript. This however is not the case with Objective-J at all. For starters, Objective-J is simply a language addition to JavaScript, and exists separately from the actual Cappuccino framework (which I’ll discuss a little later). It does not directly have anything to do with the DOM or AJAX, etc. The purpose behind Objective-J was to facilitate the development of Cappuccino, and when we originally set out to do that we simply wanted to add a few key missing features to the existing JavaScript “standard”. In other words, Objective-J is our take on JavaScript 2.0.

Now, this is usually the point at which someone chimes in that JavaScript is perfect, and that I just don’t understand it (you know, despite the fact that I’ve been using it for upwards of 10 years and have worked on its implementation in a major shipping browser). However, I think most people in the community can agree that there are some pretty big holes remaining in JavaScript. JavaScript is being used in increasingly larger projects, and in these projects some of its weaknesses are beginning to show. This is precisely why we have things like the (now dead) ECMAScript 4 proposal, Harmony, and Adobe’s ActionScript. And the truth is, had JavaScript 2.0 come around and been widely implemented and supported, we would have built Cappuccino without Objective-J. But the problem is that JavaScript 2.0 didn’t come around. I started working on what would eventually become Objective-J and Cappuccino three years ago, and in that time there have been no significant improvements or changes to the JavaScript language. Yes, certain browsers have taken it upon themselves to add a few nice features here and there, but for people writing real applications that need to run on most browsers, its simply not practical to rely on them. For the most part, we’re writing the same JavaScript today (language-wise at least) that we were 5 years ago. And that doesn’t seem like its going to change anytime soon.

Everybody is writing “abstractions” around JavaScript

And I don’t just mean projects like Pyjamas and GWT. I mean EVERYBODY, including Prototype, Dojo, and jQuery.  Yes, you read correctly, all the major JavaScript frameworks are essentially doing the same thing we are to some degree or another — we’re really not that original. The sole difference between their approach and ours is that when they add new language features to JavaScript, they’re not taking the extra step of introducing new syntax. Don’t believe me? Take a quick look at an example right out of the Prototype tutorials:

// when subclassing, specify the class you want to inherit from var Pirate = Class.create(Person, { // redefine the speak method say: function($super, message) { return $super(message) + ', yarr!'; } });

What we’re seeing here is the introduction of classical inheritance to the JavaScript language. This has always traditionally been a language feature, but due to its absence in JavaScript, the folks at Prototype have chosen to make it a library feature. The important thing to realize here is that it requires as much work to learn about the Class function as it would to learn about a new class keyword. And the same is true of Dojo:

dojo.declare("Employee", Person, { constructor: function(name, age, currentResidence, position) { // remember, Person constructor is called automatically this.password=""; this.position=position; }, login: function() { if (this.password) alert('you have successfully logged in'); else alert('please ask the administrator for your password'); } });

Once again, dojo.declare might as well be a new keyword since its shoehorning classical inheritance right into JavaScript. The jQuery UI widgets do something very similar to this with the “widget” factory method:

$.widget("ui.sortable", $.extend({}, $.ui.mouse, { _init: function() { var o = this.options; this.containerCache = {}; this.element.addClass("ui-sortable"); //...

At the end of the day, it doesn’t really matter if you’re a JavaScript expert, all these libraries have quite the learning curve and if its your first time with any of them, you’re going to have be referring to documentation a lot. And that’s not a bad thing. My point is simply that in JavaScript, more so than anywhere else, libraries need to first define what is essentially a new mini-language before they can begin to do anything useful.  This is a bit unfortunate, because it ends up tying language additions to library features, despite there being no necessary connection between the two. This makes it particularly hard to use the different libraries together in an efficient way. Sure, you can use all three in the same project, but there are some clear walls between them since each one decides to do classes a little bit differently. Not to mention the fact that you now have pretty redundant code your site. This is what happens when a language is clearly missing features. Individual frameworks in the .NET, Objective-C, Java, and so forth world don’t suffer from core incompatibility in the way they choose to do something as fundamental as defining class hierarchies. This is part of the reason we built Objective-J as its own standalone entity.  If all you want is some of the cool language features that Objective-J adds (without any of the design patterns in Cappuccino) then you can just use Objective-J, there is no “all or nothing” contract.

OK, so how is Objective-J different?

As we’ve now seen, there is a general tendency to add language features to JavaScript. Now, in my personal opinion, I prefer language features as fundamental as these to be part of the syntax, not part of a library. Let’s look at what Objective-J inheritance looks like:

@import "Animal.j" @implementation Snake : Animal { Number miceEaten; } - (String)speak { return "hisss!"; } @end

To me this code reads a little more naturally, and at the very least it’s no harder to pick up than the numerous library functions required in the other libraries. This approach also has the added benefit of making it absolutely trivial to write new syntax modules so that my text editor of choice can actually know what is going on in my code. You’ll also notice that creating a new syntax gives us great flexibility and allows us to add a few nifty features that wouldn’t otherwise be possible, such as optional static typing and code importing. But again, this isn’t as “out there” as some people would have you believe. It has even more benefits as we’ll soon find out, but before we do, let me answer the question that I’m sure many of you are asking right now:

Why Objective-C style syntax?

Again, we didn’t start off saying “lets port Objective-C”!  In fact, our first versions of Objective-J looked very similar to Java or C++:

class Snake extends Animal { Instance.speak = function() { return "hisss!"; } }

However, this approach had some serious issues. To better understand them, we have to take a look at what the principal design goals of Objective-J actually were:

  1. First off, it had to be a strict superset of JavaScript – meaning all existing JavaScript had to work. Believe it or not, we do like JavaScript, and we didn’t want to break it or create a trade-off of features.  Not to mention we wanted the existing plethora of libraries to still work.
  2. Secondly of course, we wanted to add a number of “key” features.  Some things as crucial as being able to import code and built in support for classical inheritance.  We also wanted some features inspired by languages like Ruby, such as method_missing.
  3. And lastly, we wanted to keep the ease of use of JavaScript, which meant not adding an extra “compilation” step, but instead allowing developers to still pound out some code and hit refresh and see it run.

The problem with adding language features in a way that would be more “familiar” to most developers, like the Java approach above, is that it would break backwards compatibility with existing JavaScript. This is because a lot of the keywords we wanted to use are actually reserved words in JavaScript, despite not being currently used. There is good reason for this though, because at some point they may actually mean something, and we wanted to make sure Objective-J kept working when JavaScript (finally) got a real update. Of course, we could have just chosen different keywords, like “Class” instead of “class” for instance. This however also breaks backwards compatibility because someone may have used the Class identifier in their code already.

The other problem with this approach is that it made it next to impossible to add harder features like optional static typing or dynamic dispatch of methods (thus allowing for method_missing) without having a full blown compiler. There’s no way to “intercept” a method call in JavaScript.  So once again, we were stuck.

Luckily for us however, a group of people ran into these same issues about 25 years ago when trying to improve the C language. These were the folks at Stepstone who developed Objective-C. Just like in our case, Objective-C had to be a strict superset of C (unlike C++ which does NOT always play nice with C). Also lucky for us is that JavaScript syntax is very close to C syntax, so their language additions translated very naturally to JavaScript. And perhaps now it is obvious why our keywords start with the “@” symbol, because in this manner there is no possibility of ever clashing with future JavaScript keywords or predefined user variables and functions. In other words, we can now add to the language as much as we want without the fear of breaking compatibility with existing JavaScript.

Similarly, the new method passing syntax allows us to have firmer control of how messages are sent:

object.jsMethod(); [object objjMessage];

This is the famous bracket syntax. What you may not realize is that this makes it perfectly clear when you are using Objective-J style message dispath, allowing us to “hook in” and add things like method_missing, etc. There are a whole bunch of other cool things that this enables which are outside the scope of this post, but I encourage you to check out the other tutorials on our site to learn about them. All this, without breaking any existing libraries and without requiring the user to compile before every run. Pretty impressive for a langauge that is supposedly “completely different” from JavaScript.

The Part About Leaky Abstractions

On top of Objective-J, we’ve built the Cappuccino framework, which is designed to help developers write desktop class applications on the web. One of the many things Cappuccino does is “abstract away” the DOM, and I’ll get into why we do this in a moment.  But before I do, I think I should take a second to address this whole “leaky abstractions” business, because there seems to be a fair bit of confusion regarding this as well. If you haven’t already read it, or even if you have, I recommend you take a look at Joel Spolsky’s original article on the subject.

When people refer to this article, it is usually to criticize some “abstraction” because it will “inevitably” be leaky, and then oh boy you better watch out! But this was not Spolsky’s thesis. He didn’t end the article with “and thus avoid abstractions at all costs”. He was not somehow suggesting that we stop abstracting altogether. Quite the contrary, its clear that although these “leaks” are an unfortunate and unavoidable consequence, abstractions are still incredibly worthwhile: hence the conundrum. In every single example given in the article, it was never implied that the abstraction was somehow bad or invalid because of its leak: Just because certain SQL queries are slow doesn’t mean you should manually read in tab delimmeted files and scan them yourself. Just because TCP can fail if you unplug your computer doesn’t mean you should do IP transfers yourself.  It just turns out that, big surprise, nothing is perfect. Joel put it best himself:

Indeed, the abstractions we’ve created over the years do allow us to deal with new orders of complexity in software development that we didn’t have to deal with ten or fifteen years ago, like GUI programming and network programming.

And the truth of the matter is that the problem of leaks is overstated. I find it particularly hilarious when JavaScript programmers bring this up, since JavaScript, being a garbage collected dynamic interpreted language, is quite possibly one of the biggest abstractions of all. And yet, most of us can see that the benefits of JavaScript far outweigh the “leaks”. I think few JavaScript programmers have had to learn “the whole stack” once they’ve encountered one of JavaScript’s many leaks, whether it be performance issues (from being interpreted) or perhaps large memory consumption (from being improperly garbage collected in some browsers). No one has had to go and open up WebKit’s source code to figure out these problems. Most of the time you simply Google your concern and learn the workaround. Not that big a deal.

Leaks are just something we all have to learn to deal with in every facet of programming, because programming is abstraction. Abstraction is basically all programmers ever do, from pushing electrons across a wire, to turning C into assembly, to interpreting JavaScript in your browser, every step in computer science has been an exercise in abstraction. There is nothing inherently wrong with abstraction. I can understand if someone disagrees with a particular abstraction for well defined reasons, but simply waving your hands and referring me to the law of leaky abstractions is not a valid argument.

To suggest that we shouldn’t abstract because of Joel Spolsky’s Law that all abstractions are inherently leaky is to suggest that we shouldn’t debug because of Murphy’s Law that all code will remain inhrerently buggy.

Back to Cappuccino and the DOM

Cappuccino doesn’t just abstract away the DOM, it abstracts away HTML, CSS, VML, the JavaScript DOM API, etc. Why? Because as you can see there are just too many technologies with overlapping responsibilities. It’s never really clear whether you should create a button in HTML or in JavaScript code, and whether you should style it in a CSS files or apply styles manually in JavaScript, or whether you should just use Canvas to draw everything. Not to mention that on top of having to sort through all these technologies, you have the additional challenge of having to accomodate for every slightly different flavor that exists in every browser. Sometimes its relatively simple, but othertimes it can be quite complex, as is the case with Canvas and VML. The other problem is that these technologies were simply not originally designed to handle the tasks they are now performing.  HTML was designed for laying out documents, not creating applications.

We look at these technologies completely differently.  To us, HTML, CSS, Canvas, the DOM, etc all represent the “rendering engine” of the web, in the same way that graphics cards are the rendering engines for your computer. It’s too difficult to learn the intricacies of every graphics card on the market, so developers instead use technologies that hide these details like OpenGL. In the same way, Cappuccino defines a common way to “draw” for the web. Internally, it figures out whether its more efficient to make a div, or draw to a canvas, or use VML. This is a fantastic time saver today, because it allows Cappuccino to worry about things like performance and allows you to just get a button on the screen. But its going to be even better as time goes on. This is not only because the underlying code will get better, but because web applications today look like this:

But tomorrow, when enough browsers finally support SVG, they may look like this:

Or, for all we know, like this:

The important thing is that when this happens, and it will eventually happen, people who invested heavily in todays technologies will have to spend a great deal of effort updating, but we will just swap out the guts of Cappuccino and your code will inherit the benefits of SVG or whatever new technology is out there.

Conclusion

To me what we’ve done with Objective-J and Cappuccino seems inevitable. Even the most conservative major JavaScript libraries can’t get away without adding features to the language, and we’ve simply taken the next logical step with Objective-J. Similarly, Cappuccino is a tool that allows you to stop thinking about web pages and browser incompatibilities, and instead focus on the complex problems presented by the challenge of creating full-on applications on the web. As we’ve said countless times, Cappuccino isn’t for everything. All of this abstraction isn’t necessary if you’re simply trying to add dynamic elements to a site like bankofamerica or digg. Cappuccino is for building rich applications in the browser, a small minority in the web world today. We believe that this is where things are headed, and we designed Cappuccino specifically to get us there.

- Francisco

Tags: ,

  • Joel Norvell
    I think this is a brilliant article. For me, Cappuccino and Objective-J are an incredible and unexpected boon -- providing a way out of the client-bound, and a way forward onto the web -- a real future, but one that doesn't require the sacrifice of my past!
  • penny
    smalltalk like syntax is what won me in the first place....You have to program as you talk..this is what i call syntax...well, smalltalk.
  • Tim
    P.S. I also felt the need to respond to John Resig with a post of my own
    http://web.2point1.com/2009/01/03/a-response-to...
  • Tim
    That's an extensive article, great work.
    I totally agree that the likes of Prototype and jQuery are limited as they don't extend the syntax. Furthermore the sugared-syntax that with its clever use of whitespace is very unintuitive indeed, and stands in the way of developers new to JavaScript gaining any real understanding of it.

    It is at this point that I must plug my own project which is an abstraction in ActionScript. You write AS3 and the JASPA compiler generates regular JavaScript from it. http://www.jaspa.org.uk/
  • patrickdanger
    Great post, very reasonable interpretation of Spoelsky's wide-net analysis.

    I have read a lot of the reaction to Objective-J and Cappuccino with a critical eye, as I think what you've done is fantastic, and struck me as the next logical step following the glut of library development designed to abstract platform complexity.

    This is, in my opinion, the third tier missing in your diagram above right below the various collections of technologies that make the web run, as many browsers have idiosyncratic implementations of standards.
  • Steve I
    Great article , clears up alot!

    As a researcher I welcome and embrace all new ideas, and I find it disturbing all the negative comments you guys receive about your technologies. Some people seem to be taking this as though you somehow claim your solutions as the ultimate truth and force them upon us so that we may never program the web in javascript again.

    Anyway, I thank you for embracing openness and helping in your own way move the technological world forward, you have developed an interesting idea for your own purpose and been good enough to show it to the world... for the flamers out there, if you dont like it and have good reason, by all means say so, but then simply realise you dont have to use it and leave the poor guys in peace!
  • Great article. You have a small typo where you misspelled "design" :

    "To better understand them, we have to take a look at what the principal desing goals of Objective-J actually were"
  • Thanks. Also fixed.
  • Dale
    "outway"? - no way!

    "outweigh" - yes way!
  • Thanks. Fixed.
  • MichaelStroeck
    You know, LISP, Scheme, Smalltalk, etc. are not for everyone. I know really, really good and efficient software engineers who have tried repeatedly, but can't really wrap their heads around any of them.

    A simple reason for that is that, with all the C/Java/C++/Perl/... code to maintain and extend, they simply don't have the time to spend a year learning the other languages from the ground up... That sucks, but for that reason there will always be a place for excellent software engineering projects like Objective-J.
  • I'm not going to make any comments regarding the language abstraction issue, but one particular part of this article stood out for me:

    “It’s never really clear whether you should create a button in HTML or in JavaScript code, and whether you should style it in a CSS files or apply styles manually in JavaScript, or whether you should just use Canvas to draw everything.”

    If the reasons why you should create a button in HTML and not JavaScript are not obvious to you, then you should not be writing a web framework that deals with these things. If you cannot understand the benefits of defining your appearance through CSS rather than JavaScript, then you do not understand the reasons behind why these technologies exist. It's as simple as that, and it disturbs me that a framework could arise where the author doesn't understand the fundamental concept of separation of concerns in web technologies.

    I'd say I'm surprised, but I'm not; I've already seen the tag soup that Cappucino squirts out into the DOM, and the awful, awful way in which appearance is defined. I'd strongly advise you to do some more reading about why these things came to be, and try learning about how to build web applications in an extensible and layered fashion. Until then, my view is that Cappucino is not something that should be seriously considered for building web applications.
  • Ben, do you look at your C compiler's output and complain about the label soup that it squirts out into the assembly source, or the awful, awful way in which registers are allocated?

    Or are you just glad that you don't have to think about assembly code in the first place?
  • Bret, I would say that's a slightly unfair comparison. C compilers tend to be far more mature than projects like Cappuccino. Also, web developers are faced with a largely different set of problems than C programmers. For example, knowing how to progressively enhance an interface is crucial to developing an accessible website. C programmers may worry about locality of reference where a web developer doesn't.

    For what it's worth, I've encountered many cases where I have had to write inline assembly and/or read C compiler output.
  • This is a spurious analogy. The underlying assembly language is not written for a human being; it's written for a microprocessor and has an unambiguous interpretation. Markup is a semantic descriptor for information which isn't prescriptive about how it should be used, only what it means. The mistake being made by the authors of this framework is in assuming that the only meaning (and purpose) of markup is how it looks, which is just plain wrong.

    Markup can be interpreted in many different ways, and each is valid provided that the underlying meaning is still the same. A very simple example would be the strong tag. This is commonly used to embolden text, but its true purpose is to imply strong emphasis on a word or sentence. The visual representation is entirely lost to somebody having the page read out to them, and so instead the voice reading the page would use emphasis to represent it instead.

    These are fundamental concepts of web development.
  • I'd just like to remind you that Cappuccino is not intended to be used for websites, but rather single "page" rich web applications. If that were not the case then I would agree with you.

    I'd also like to point out that HTML is fundamentally a document markup language, not a rich application technology. Cappuccino accepts that fact, and rather than attempting to shoehorn an application into semantically meaningful HTML tags, it simply uses the DOM as a "rendering" layer. The DOM is a means to an end.

    Are you also upset that the user interfaces of your desktop apps, like MS Word, or the web browser itself, aren't made with semantically descriptive HTML? No, of course not.

    There is no advantage to having such a structure to the application itself since it is not content. If you're concerned about accessibility, that's exactly what WAI-ARIA is for (admittedly Cappuccino does not yet support it, but that's a separate issue)

    Take a look at Gmail, Meebo, or any other complex web application. They all do similar things.
  • What a messy, confused response.

    You imply that there is some black and white distinction between web pages and web applications, as if accessibility and cross-device compatibility only matters for some and not for others. There isn't.

    You say that because HTML is a document markup language (which it isn't, entirely; there's plenty within the HTML spec which has nothing to do with documents) that gives you carte blanche to ignore it and treat it as a ‘rendering layer’. This is wrong too.

    Desktop applications don't have to provide semantically descriptive underpinnings because (when properly implemented) the operating system they run on will do that for them; that's one reason why software developers are recommended to use API methods and standardised interfaces — because the operating system can then provide all its standard accessibility mechanisms to these applications. It's a spurious comparison to make in any rate; this is the web, not a desktop application.

    If you do not understand the benefits of having a structure to the underlying elements that your application is built from then I say again — go back and read and understand why these technologies exist. This is not simply about accessibility.

    Oh, and as far as Gmail goes; that's about as bad an example to cite as is possible (as is true with all the apps Google have built using the GWT) as they fall foul of exactly the same ignorance of a layered approach.
  • I certainly don't think it's black and white, but we try to emphasize that Cappuccino is a technology far on the "rich application" end of the spectrum.

    Anyway, I'm not going to continue this discussion if you're going to be rude. It's clear I'm not going

    By the way, Gmail is not built with GWT (almost none of their public apps are) but the point stands: all the major players writing complex client-side apps don't worry about whether or not the DOM structure has perfect semantic meaning.
  • It's not my intention to be rude, although I do think it's important that the things I've pointed out be said. For many years there was an active movement within the web development industry to embrace a standards-driven, accessible, best-practice approach; yet in recent years it seems that more and more of this mindset is being eroded by a desire to do ‘fancy’ things that ignore the basics.

    My ideology is simple, really: if you want to make a desktop application, don't build it as a web application. And if you want to build a web application, embrace best practice.

    As I said before, this isn't just about accessibility. Think about all the different types of device that might access your application in the future. I noticed that your framework implements its own scrollbars (lord knows why); this approach means that you can't scroll the view in MobileSafari (and slider controls don't work either). Could you have foreseen that? Perhaps. But then what? Build specific exceptions to make it work for MobileSafari? What about the next big mobile device that has a built-in browser? Just how well can you scale the practice of making exceptions?

    I didn't realise Gmail wasn't written using GWT, but my points still hold (just inspect the DOM to find what the Compose Mail ‘link’ really is, to see what I mean).
  • Just to clarify; I was referring to machine code rather than assembly as not being written for human beings, although I think that was probably what you were referring to as well.
  • tewha
    After reading this, I think you should rename the language. The name "Objective-C" implies a much closer resemblance to Objective-C at the cost of JavaScript. I don't think Objective-JavaScript would better, since it's too long, so maybe it's already as good as it gets. But the name has defined the battle.
  • Objective-JS?
  • SubGenius
    O.J.
  • Kyle
    This article really peaked my interest in Objective-J. It really shows that you want Objective-J and Cappuccino to be a real technology instead of a fad.
  • Lisp Zealot
    From a purely technical standpoint, Objective-J and Cappuccino are both very impressive. Porting part of Apple's Cocoa framework to the web, building a compiler for your own language in Javascript and then creating a web application of the complexity of 280Slides using them is a significant engineering achievement.

    That being said, I think that Objective-J ultimately is an example of what happens when people who don't know enough programming languages attempt to design their own. Francisco, in that talk you gave at FOWA you likened the current state of web applications to DVD/VCR combos--transitional technology that allows you to utilize something new and better without completely abandoning your existing investment in something old and obsolete. Well, perhaps you are unaware of it, but Objective-C is just such a technology. When Brad Cox made Objective-C, he was not simply attempting to "improve C." It was a stopgap measure forged in the harsh, technological reality of the 1980s, when microcomputers were simply not powerful enough for something as dynamic as Smalltalk and most software was written in either C or assembly. Objective-C allowed developers to leverage some of Smalltalk's magic without abandoning the massive amounts of C code they had accumulated over the years. But you must realize, Objective-C was never the destination, it was never the end goal--Smalltalk was. Objective-C was just a painless way of getting closer to it.

    Reinventing Objective-C in Javascript is like buying a mountain bike for yourself and then putting training wheels on it. If you had known Smalltalk (or perhaps even better, read the Self papers), you probably would have a designed a much more sensible language. Instead you took Javascript and made it less dynamic by bolting on type annotations and gained nothing, performance wise, for doing so. Understand, I am not criticizing you for creating your own language and framework to abstract away HTML, CSS, DOM, and Javscript drudgery. I think it's a great idea. I just don't think Objective-J is very good language.
  • Thanks to JavaScript, Objective-J is actually a bit more like Smalltalk than Objective-C is.

    Objective-J has anonymous functions / closures (though a more compact syntax would be nice). All "primitives," such as numbers, are actually objects which accept messages.

    Control structures and some operators could be implemented as messages, but since JavaScript already has most of what we need that's not necessary.

    Other than those things, and syntax of course, I think Objective-J is very similar to Smalltalk. But, I don't know Smalltalk, so I'd be interested in hearing about any other differences.
  • boucher
    Well, type annotations are completely optional, and you don't get "nothing", you get documentation built right into the code. And at what cost? It costs virtually nothing to label the expected types for your method or instance variables. In the future, you may also get a lot more, including potentially static and dynamic type checking, both of which are possible.

    In your recognition of what Objective-C was, I think you fail to recognize the similarities to today's browser environments. We have a huge legacy of JavaScript code, we have no available alternatives (not because of processing power so much as vendor decisions), and what we do have has severe limitations.

    On top of that, whatever Objective-C was designed for, it ended up being a great language that's still in use over 20 years later and is gaining rapidly in its popularity. Objective-J probably isn't the language for the web 20 years from now, but its the best choice for a language today, if for no other reason than its only competition is JavaScript, and it is simply an extension to JavaScript.
  • Lisp Zealot
    Thank you for your response.

    I guess what I'm trying to say is that you took a step backward when you could have taken one forward, and that's unfortunate. Smalltalk and (even more so) Self would have served much better as models to base your language on, and if any of you had knowledge of them I don't think you would have designed your language the way you did. You could have actually made Javascript's prototype system much less painful by simply adding some features from Self like copy and init. I'm not bashing Objective-C. It is a nice language, but there are languages much nicer than it.

    Anyway, what you gentlemen did in building 280 Slides is very impressive. Now that you've demonstrated that something like Cappuccino and Objective-J can built in the browser using Javascript and still perform well, I would not be surprised if others follow your lead and create their own DSLs in Javascript. Hopefully they will choose better sources of inspiration than Objective-C. Maybe Scheme in the browser? :)
  • boucher
    One of the reasons for the choice of Objective-C, which is mentioned in the post, is a technical one. The syntax of the language is designed to be implemented as a preprocessor on top of another (C style) language. It's also designed to be implemented primarily with the runtime component, rather than syntax. Choosing another syntax (and thus another language) would have been extremely problematic, because it would have meant more parsing, and perhaps even an actual compilation, both of which would be significantly slower than what we do with Objective-J.
  • John
    fantastic writeup, very long indeed. Im rereading it again later. I wonder if Apple would ever adopt Cappuccino?
  • Great post, Francisco.
  • Also, similarly to how we could swap out DOM for SVG one day, if we come up with a more efficient classical inheritance implementation that's semantically identical, we can easily swap that out as well. Or perhaps inline the method dispatching code.

    Which brings up another point... we already *have* done this several times since the inception of Objective-J. Once the syntax for Objective-J was nailed down we were able to work on Cappuccino without worrying whether or not Objective-J would be changed internally.
  • Brilliantly written. I'm glad you've (once again) made clear the purpose of Objective-J and Cappuccino. I'll be pointing people at this article in the future. Too many times when I've brought up Cappuccino, people have said, "It's like Sproutcore, in'it?" and I've wanted to slap them. Twice.

    Keep up the great work!
  • What are your thoughts on parenscript?
  • boucher
    None of us are lisp people, so we've really never looked at it.
  • Francisco, this is one of the most compelling arguments for Objective-J that I've seen so far. Well done.
  • anon
    Hm. A collection of different object systems atop a base language, none of which play nice... Flexible syntax... JavaScript really is Lisp, isn't it?
  • I've thought quite a lot about abstracting away the browser. My choice of programming language would be Scheme. Others would want Python, Ruby, Java, etc. All sorts of projects exist but they don't seem to be gaining much traction. Perhaps they will in the future but for now it seems folks are sticking with HTML/CSS/JavaScript. In order to abstract the browser successfully with other languages it would help if JavaScript exposed tail calls, continuation, macros etc. Then the source code written in many different languages could compile to efficient JavaScript. I've mentioned this on the es-harmony mailing list a few times but the committee doesn't seem to think making ECMAScript a stronger compilation target is a worthwhile goal of its own. If you think it is then please speak up on the list. I'm all for abstracting the browser but the browser needs to be a beter compilation target first. When it is I think projects like Objective-J and GWT will gain more traction. As it stands the browser is good enough and writing "native" code will be smaller and faster.

    Debugging compiled code seems to scare people away also. There is good reason to be scared but there would be several ways to deal with the problem. Building an Objective-J interpreter that runs in the browser, for example. Compiled code with automatically generated debugging output. An Objective-J browser which runs Objective-J code "natively". These would all be somewhat time consuming to build and may run slowly but would give good error messages to the developer. The compiled code could be used in production.
  • Debugging Objective-J code shouldn't be too terrible, since it's fairly straightforward preprocessing rather than full blow compilation.

    i.e.

    [object message:argument]

    becomes

    objj_msgSend(object, "message:", argument)
  • How does the performance compare to

    object.message(argument)

    I found that the following is about 130% slower than the above, and that was the best i could do (one extra function call and one property lookup.)

    object("message", argument)

    I imagine the following is about the same

    send(object, "message", argument)

    This sort of performance issue is a problem in the browser because browsers (the ones used by the general public, not the fastest nightlies available) are still reasonably slow. This problem is compounded by the fact that these sorts of frameworks that abstract JavaScript's regular property look up are for big projects. Presumably in a big project there is a higher likelihood that responding to a user action will be a more involved process with more method calls. If each method call is longer (e.g. some loop calculation) then the whole things slows down. I wouldn't want to explain this to the boss when things start getting noticeably slower. You can argue "premature optimization" against what I'm saying but is JavaScript really that ill-equipped? It is a reasonably high-level language. Anyway, I struggle with justifying the performance trade-offs because JavaScript is so capable.
  • boucher
    Peter, real world performance indicates that this is not an issue. objj_msgSend accounts for perhaps 0.5% of time spent in 280 Slides, which is negligible considering. I'd gladly pay that performance penalty for the feature we enable.
  • boucher, Those are very encouraging statistics (even though I don't know what "Slides" are.) Can you point me to a write up about the experiments and data collection techniques?
  • boucher
    280 Slides is a program written in Cappuccino (http://280slides.com). There's no write up, this is just profiling the app in various profilers like Firebug and WebKit during normal use.
  • Ahh. I was hoping you had written an application both ways (would be a relatively easy transformation for calls that can be made the regular JavaScript way) and seen the overall performance change.
  • He means 280 Slides, our application: http://280slides.com
  • Matteo
    This was a great article.

    I believe that people didn't realize yet the possibilities of Web Apps, or maybe they did but they are still "playing"/experimenting with them.

    Objective-J and Cappuccino are the way to go.

    Objective-J and Cappuccino are just years ahead. They set the foundations for a watershed event in the web apps' world.

    If everybody understood what Objective-J and Cappuccino really are, there would be a revolution tomorrow morning.

    Keep up the good work.
  • Francisco you explain very well your vision and it’s always a delight to read your articles.
    While learning (slowly) Capuccino and Objective-J, it remind me at every step the goodness of this investment. I had the same feelings while learning (slowly) NextStep and Objective-C a long time ago.

    This is not about the language but about the consistency of the framework.
    The whole create a beautiful unity where simplicity and elegance emerge (though it could use less words).

    I can’t wait for you using SVG!

    Thanks again for your work.
  • Oh good, software patents FTW. That'll really help. ;-}
  • Excellent.

    The thing that will give you some "runway" is that no one is thinking strategically enough about web apps, even if you tell them point blank, as you have here.

    It's just like 10 years ago when no one believed you could write serious applications in "scripting languages" (first Python/Perl, then later Ruby).
  • "The thing that will give you some "runway" is that no one is thinking strategically enough about web apps, even if you tell them point blank, as you have here."

    Don't know how you can suggest that no one is thinking strategically about this. Companies such as Adobe, Microsoft, and Google, to only name a few, have been thinking about this for years. Even companies such as our own, NOLOH (http://www.noloh.com) have been working on this problem for the past 5 years, and even have a patent pending that covers the general premise of this post.
  • Yes, and the way they're thinking strategically is to subvert the browser with evil proprietary solutions such as Flash and Silverlight, so they can continue their world domination schemes.

    Only Google is taking the open web as a given.

    Objective-J also takes the open web as a given and builds on that.
blog comments powered by Disqus

Download

Cappuccino and Objective-J are licensed under the LGPL. For more information, see our licensing page.

Copyright © 2009 - 280 North, Inc. Cappuccino and Objective-J are registered Trademarks of 280 North. Logo by Sofa. Hosting by Slicehost.