Summary
Developing robust, stable, and high-quality software in JavaScript stands on the same principles as doing so with other programming languages. Applying development best practices, proven design patterns, and common sense makes a project successful.
That said, the dynamic nature of JavaScript makes it easier to get messy with than, for example, the Java language. The Java language is strongly typed; it pushes you to use namespaces (packages); and its Java runtime library was seemingly driven by the Gang of Four patterns and similar reference points. Also, Javadoc documentation is very good and usable. These factors are all extremely helpful for new developers, as long as they have less wheels to reinvent, and are pushed in the right direction from the start.
JavaScript is different. It is very flexible, sometimes too much so. You can do so many things with JavaScript, and in so many different ways. But after a while, who can maintain the code? If you've ever been a little too creative and/or inaccurate with JavaScript code, you probably know what I mean: maintenance can be tough even for the author of the code, after a while. JavaScript is far less forgiving than the Java language.
What can you do, then? One idea is to enforce known good practices using coding standards. You could even try to stick to the Java way of coding. Some decisions can really simplify things and help newcomers:
- Take advantage of Dojo's infrastructure for using packages.
- Define only one class per file and keep class and file names consistent.
- Validate arguments for correct types and not-null conditions explicitly at the beginning of public methods.
- Throw exceptions as you would in Java and view a stack trace with the Firebug plugin.
- Declare classes with
dojo.declare(), and use the Dojo infrastructure for inheritance.
From another perspective, avoiding JavaScript's powerful flexibility can prevent really beautiful and worthy designs from happening. You don't want that either. So, as typically happens, it is all about finding a perfect balance between the extremes.


