Picture of admin

No thanks, Atlas, I'll take my JavaScript straight

  • Posted By admin on January 20, 2006

JavaScript is an easy language, full stop. It isn’t perfect, but if I had to teach a language to eager newbies, I’d prefer JavaScript over C# or Java. But apparently, some folks think JavaScript is too hard. With Atlas, you are encouraged to use helper libraries so that you can write code like this.

Type.registerNamespace("Demo");

Demo.Person = function(firstName, lastName, emailAddress) {
    var _firstName = firstName;
    var _lastName = lastName;
    var _emailAddress = emailAddress;

    this.getFirstName = function() {
        return _firstName;
    }

    ...

    this.dispose = function() {
        alert('bye ' + this.getName());
    }
}
Type.registerClass('Demo.Person', null, Web.IDisposable);
Without Atlas, I’d be forced to this:
Demo = new Object();
Demo.Person = function(options) {
  this.firstName = options.firstName;
  this.lastName = options.lastName;
  this.emailAddress = options.emailAddress;
}
The plain old JavaScript looks easier to me. I guess all those accessor methods and busywork code make the Atlasized version more “scalable” or “enterprise”. :-)

Humor aside, there is a serious question here. Does it help to make one language look like another, like the C#-izing of JavaScript shown above? If it does help, is it a short-run, “training wheels” kind of thing, or a long run plan? If you’re building Ajax apps, drop a comment and let us know what you think.

Ad: Fortunately, there’s more to Atlas than the misguided C# veneer. We’ll be talking about some of the better parts at the Pragmatic Studio in Reston, VA, Feb 9-11.

Comments
  1. Marcus AJanuary 20, 2006 @ 05:01 PM
    Why do you expose instance members through accessors in Ruby? Why don't you use public on your instance members in Java? Same reasons apply to Javascript despite being a scripting language running in a browser. I've developed three (large?) web applications (somewhere between 250-500kb of js each) the AJAX way, and all three before the AJAX term was coined. All three benefitted large from applying sound OO rules. Now, having said that, I wouldn't touch the thing you describe above. As javascript is very dynamic and nice, I would implement functions similar to those found in Ruby, like the standard accessor methods or the cooler ones found in traits (probably overkill though), to help me getting code almost as simple as your's but with the benefit of encapsulation.
  2. Stuart HallowayJanuary 21, 2006 @ 07:46 PM
    Marcus, I think we are mostly in agreement. There's a difference between (1) sound design and (2) repeating idioms from another programming language just so things look familiar. I believe you and I are both in favor of the former, and opposed to the latter.
  3. Delhi India New ProtestApril 29, 2006 @ 03:07 AM
    I thout to do it in my local version.
  4. Retaining Bulwark BlockApril 29, 2006 @ 03:50 PM
    Well at last catched the problem...
  5. Delhi TravelMay 02, 2006 @ 02:23 PM
    I think it would be usefull for other users also :(
  6. Baccarat Perfume BottleMay 04, 2006 @ 07:02 AM
    That's awesome!
  7. Cheap Dvd Rw MediaMay 08, 2006 @ 11:03 PM
    i am not sure as to why :(
  8. Test AffinitaMay 12, 2006 @ 05:40 PM
    Gonna have to give it a try.
  9. Viaggi Natale CapodannoMay 12, 2006 @ 11:30 PM
    I use Firefox in Ubuntu.
  10. Vancomycin Package InsertMay 12, 2006 @ 11:30 PM
    Well at last catched the problem :(
  11. Nevada Escritoire Of StateMay 18, 2006 @ 04:10 AM
    I use Firefox in Ubuntu :(