First, sorry for my laziness — I have not posted good/useful posts for a long time. I did not do nothing, but the results were made public under my true name rather than here. Sorry.
This is another rant.
I use C and Perl and see them as the best combination, which has unfortunately prevented me from systematically learning other programming languages, although I wished to. I know some Java and Python, because so many are using them; I also know a bit D, Scheme and Tcl. Nevertheless, I have never written a serious program in them.
Now the situation has been changed a little. Out of curiosity, I wrote something in Javascript. Fooled by its name, I originally thought Javascript is just a scripting version of Java, but gradually, I found some nice features about javascript, which from my angle are listed below:
- Simplicity. The basic elements in Javascript are simple: we have all the C-like flow controls and then objects, with which we can do most of programming.
- Versatility. Although simple, javascript comes with a very powerful object system, which allows us to mimic procedural programming, object-oriented programming and even functional programming.
- Efficiency. While many other scripting languages achieve the same level of simplicity and versatility, few achieve the same speed of javascript (more exactly, the javascript interpreter/compiler). It seems to be the fastest scripting language in the Computer Language Benchmark Games. It is true that modern javascript engines compile Javascript to native code behind the scene, but personally, I do not feel a long delay like when I compile a C++ program.
- Usefulness and uniqueness. Javascript is the only programming language that provides dynamic web contents at the client side. Personally, I found writing a graphical interface with HTML+Javascript is much easier than using C++ and Java (although writing a professional GUI in html+javascript requires efforts).
- Back to succinctness. What I hate most about the modern programming is bloatware. I frequently feel that many programmers are writing unnecessarily complicated programs for simple tasks. In the world of javascript, in contrast, we care about the code size again because a large javascript program means more data transfer, slower responsiveness and a worse user experience.
(This post is unfinished. I need to point out the weakness of javascript. It is not perfect.)
Bad parts:
1. Assignment to an undeclared variable adds it globally. This tends to make typo’s create new variables.
2. Conversions. JS tries way too hard to convert values and make things assign and often unclear. Consider that
3 + “5” is 8, but “5” + 3 is “53” (not sure this is the right way round, but that really emphasizes my distrust of this.
3. Great object system. Awful syntax for it.
Those are my top 3 gripes, I’m sure there’s more.
To be fair, Eich et al. did a remarkable job for the time they were given. If Netscape hadn’t rushed him so much, a couple more weeks and it may have been one of the best.
Bad part:
1. Javascript informally requires you to format programs in a specific way, otherwise semicolon insertion will cause issues.
return
{
fu: ‘bar’,
bar: ‘fu’
};
Will actually return undefined because it sees “return” as a valid statement and puts a semicolon there, and just ignores the block, which is valid.
so:
return;
{
fu: ‘bar’,
bar: ‘fu’
};
You have to use: return { in this case.
2. The with statement. It really ends up making code hard to understand and follow.
Javascript has lots of mis features and issues. The book Javascript: The Good Parts mentions many of these and coding conventions to help keep you sane when developing in Javascript. (That’s just a general note to anyone using the language.)