chris clarke
software development that works…or something
eXtreme JavaScript
August 5, 2007 on 11:32 pm | In eXtreme Programming, JavaScript |Over the past few months I’ve been working a lot with JavaScript. The language is very deceptive as it has C-style syntax, and is mostly written with little regard to good programming practice. However, it turns out to be quite a good object-oriented language which can lend itself to some very elegant code.
The language itself has a fair few problems for your average extreme programmer. For starters it’s a dynamic language so a lot of errors won’t turn up until you run it, and because of its tendency to not throw Exceptions (which do exist in JavaScript), things may just quietly go wrong. Code conventions don’t seem to have been established yet and there are an awful lot of different ways to do the same thing in JavaScript, for example declaring a class can be done like this:
function Monkey() {
// constructor
this.getBanana = function() {
// ...
};
this.eatBanana = function() {
// ...
};
}
…or it can be done like this:
function Monkey () {
// constructor
}
Monkey.prototype.getBanana = function() {
// ...
};
Monkey.prototype.eatBanana = function() {
// ...
};
or this…
Monkey = {};
Monkey.prototype = {
getBanana : function() {
// ...
},
eatBanana : function() {
// ...
}
};
… or you could even do it like this (although you’d have to be mad):
Monkey = function() {
// constructor
};
Monkey['eatBanana'] = new Function("alert('eating banana')");
Monkey['getBanana'] = new Function("alert('getting banana')");
If you are doing extreme programming it can be much harder to come up with agreed standards just because there are so many different ways of doing things. This also makes refactoring a much more subjective affair and can lead to churn if developers enter the vicious circle of refactoring other peoples code to their preferred style. Also, its very easy to do (and it seems fun for some people) clever and complicated things in JavaScript which means simplicity of the codebase often suffers.
Shared Coding Standards
This makes me think when dealing with JavaScript it is very important to have shared coding standards agreed by the whole team. For the benefit of rooting some values of simplicity in the team its probably a good idea to agree a set of things that just shouldn’t be done (i’m thinking about the needlessly complicated things here). Similarly, when CSS and DOM manipulation are involved - the team should agree standard ways of doing things.
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by Cheese.
RSS Entries Feed.
RSS Comments Feed
^Top^