Developing Custom VersionOne Apps 101 Series Guide

Last time, in The VersionOne MetaMorformizr App — Using the VersionOne REST Meta and Localization APIs to GET Serious, we explored the VersionOne Meta and Localization APIs to make our User Story editor much more maintainable and flexible.

Now, let’s caffeinate it.

If you’ve not yet used CoffeeScript, a language that compiles into JavaScript, you might like it. At least try it. I got introduced formally to it here at VersionOne, and have grown to love it.

MetaMorformizr-Morformizd

Here’s the JavaScript Gist of the MetaMorformizr App from last time:

[gist id=4685990 file=gistfile4.js]

The easy way to caffeinated code!

Head on over to http://www.js2coffee.org and try it out with some of your own code.

Blech, is this sh#t decaf?

Now, it may be the easiest way, but it didn’t convert the MetaMorformizr correctly. Here’s what it did:

If you try this JSFiddle, you’ll see it doesn’t really work out for ya, but you also don’t get any errors in the console.

[gist id=4685990 file=gistfile8.coffee]

Fixing it manually

I had to manually rearrange some of the code. I’m not sure why. Maybe my original JavaScript could be written better? I am not really sure.

Try it out in this live JSFiddle.

[gist id=4685990 file=gistfile7.coffee]

Why I like CoffeeScript

Here’s what comes to mind off the top of my head…

I prefer typing less, thinking more

I’m not of the opinion that “fingers on the keys” means “more productivity”. Nonsense. What you’re building a product that nobody wants, or that could get from open source, or  buy from less than you pay for it? Did your fingers on the keys really make you “productive”?

So, given I can type this for handling some trivial, but Christmas Tree Callback prone jQuery deferred objects in a list:

[gist id=4687639 file=gistfile1.coffee]

25 lines of code, 918 characters

instead of typing this:

[gist id=4687639 file=gistfile2.js]

34 lines of code, 1128 characters

Then, I am happier. And, I feel more productive in reality, not by an arbitrary “fingers on the keys” or “lines of code generated” kind of way.

Less cognitive strain

It’s related to above, but dealing with the endless chain of }) and }) and somewhere, finally a });, is simply not cool. Been there since 1996. Done that. Done with it. Thanks.

And, the same goes for having to type function(){} intead of ->. I prefer –>.

Powerful idioms

Here are a couple of functions I use in OpenEpi.jQueryMobile for loading modules and templates, in CoffeeScript, and JavaScript:

modules.coffee

[gist id=4687639 file=gistfile3.coffee]

modules.js

[gist id=4687639 file=gistfile5.js]

templates.coffee

[gist id=4687639 file=gistfile4.coffee]

templates.js

[gist id=4687639 file=gistfile6.js]

Splat!

The (args…) syntax indicates a “splat” in CoffeeScript. Check it out here.  The other major feature in those Gists is the support for list comprehensions.

I have never been anti-JavaScript, so don’t go there

CoffeeScript, to me, makes writing code more fun. I am by no means anti-JavaScript. Not even close.  When I was in college, I volunteered with Mozilla.org, and I used to sit in the IRC chat channel with those folks and they helped me figure out the underlying C engine for JavaScript, and I wrote bindings that let you create Gtk+ apps on the X-Windows desktop in Linux using JavaScript. I wrote the first GUI on top of ChatZilla, the IRC client that Rob Ginda created which later was bundled with Mozilla. I also wrote a module for SWIG, called SwigJS, that let you generate the C or C++ glue code to create a JavaScript layer on top of it, including the ability to “object-orientify” a C-style Object Oriented API, like Gtk+.

Anyway, I’m glad to see JavaScript finally getting it’s due, but I still prefer to use easier to type and understand approaches like CoffeeScript to generate the JavaScript that ultimately executes 😀

Series Conclusion

This concludes the Developing Custom VersionOne Apps 101 Series Guide, at least for tonight 🙂

Thank you for reading, and I’d love your feedback or collaboration!

Join the Discussion

    • Blackberry App Development

      Visual Studio release cycles coming more and more frequently, our previous model of having “starter projects” set-up with all the necessary references and configuration was becoming a burden. By utilizing NuGet, we can now create a new project, install the packages we need and be up and running in short order.Thanks for sharing all that great information..

    5 + 4 =