Friday, January 20th, 2006

KavaScript: JavaScript meets Ruby

Category: JavaScript

Do you wish JavaScript was a touch closer to a language like Ruby?

Now your dreams have been answered… kinda.

A new language called KavaScript is in town:

KavaScript breathes new life into JavaScript by extending it with syntax and features inspired by expressive, dynamic languages like Ruby and Perl. KavaScript is a dialect of JavaScript designed to make your coding experience more productive and rewarding.

Features

  • Variable and code interpolation within strings
  • List and array literals (like Perl’s qw operator)
  • Terse block/closure syntax borrowed from Ruby
  • Usable and legible functional programming primitives
  • User-defined macros
  • A better class syntax and framework which supports multiple inheritance
  • Ruby-style instance variables
  • File include and insert directives

Macros

`define IsObject(x) {(typeof(#x)=='object')}
`define IsArray(x) {(`IsObject(#x)&&(#x).constructor==Array)}
if `IsArray(foo) { ... }

`define Debug(code) {#code}
`Debug( myLog('Something stupid happened!') );

How do you use it?

Precompilation baybee:


% kavascript myfile.ks > myfile.js

Posted by Dion Almaer at 2:54 am
7 Comments

+++--
3.5 rating from 21 votes

7 Comments »

Comments feed TrackBack URI

oh gosh… exactly what we needed: good luck debugging the compiled code in your browser !!

Comment by Didier — January 20, 2006

Well, if you keep your macro definitions to one line (easy enough with JavaScript, since it’s semicolon delimited like C), and don’t mess with the file insert/include features, the translated output will preserve your newlines so that the line numbers match, so I that shouldn’t be too much of an issue :)

Comment by Gary — January 20, 2006

Are any developers actually using things like this? I mean, hell – why would anyone want another layer of crap over JavaScript – like Didier insinuated, JS is hard enough to debug on it’s own without someone elses (potentially buggy) code running on top of it.

Comment by Jake Tracey — January 20, 2006

Oh dear lord…I want JS to get better, but not in incompatible, hard-to-debug ways. Were this a set of patches for possible inclusion in Spidermoneky or Rhino, it might be news. As it, it’s just a mistake in the same vein as ActionScript 2.

Regards

Comment by Alex Russell — January 20, 2006

Alex, if anything, your suggestion of patching Rhino or Spidermonkey would result in more incompatibility. Practicable JavaScript development will always remain frozen at the lowest common denominator, namely Internet Explorer. There’s simply no point in producing features that will result in syntax errors on 80% of end-user machines.
 
While it’s fine to extend native objects with emulable native-code methods (such as mozilla’s forEach, map, and filter), since backwards compatibility can trivially be maintained, it would be brutally stupid to extend the actual syntax of the language on just a minority of platforms.
 
I find your debugging criticism especially hard to swallow, coming as it does, from the lead developer of a framework that loads modules via string-eval. Don’t you think that’s a slight case of pot and kettle?
 
In any case, the assertion that KavaScript will be significantly harder to debug than regular JavaScript is bollocks. Even if you use macros, they amount to little more than speed-bumps during development, which are easily be mitigated by overall improvements in abstractability, comprehensibility, and performance. I don’t know about you, but there’s a limit to how many times I can stare at the exact same loop to copy the arguments[] quasi-array into a real array without wanting to tear my hair out. And personally, I’d rather not have the overhead of function dispatch to isArray/isObject/isWhatever type-checking functions when those checks can and should be performed inline, without sacrificing either performance or readability.
 
Sure, maybe I’ve been sipping on my own kool-aid for too long, but really, it’s quite tasty. You should try some before knocking it, I promise it won’t kill you ;)

Comment by Gary — January 21, 2006

I can’t believe how quick people are to criticize what they haven’t tried. Personally I can’t say whether I’d find this useful, since I’m brand-new to Ruby, but the fact that someone has built something like this is über-cool, if nothing other than as a proof of concept. If you want to give feedback on someone’s long & hard work, please have courtesy and try it first, and please offer any criticism constructively.

Comment by Brandon Zylstra — January 25, 2006

[…] Over at Ajaxian, there is a discussion on Kavascript which is an attempt to make javascript a bit more like Ruby and Perl. […]

Pingback by moebius recursive » Blog Archive » Making Javascript More Like Ruby — April 14, 2006

Leave a comment

You must be logged in to post a comment.