The JavaScript "Sucks" Conversation
The other day I had a conversation (more of I think I am better than you rant) about how JavaScript needs to be a "real" language. The person in my mind had no clue what JavaScript's real potential was when you sat down and looked at it. I remained calm and chuckled to myself inside.
Well I listened to his 2 cents and sum his five minute rant into one sentence. "JavaScript's 'loose' variables are evil, JavaScript’s OO is not OO, and the standards are to slow to adapt with browsers.
Well my response back went something like this:
Defending Attack 1 - JavaScript's 'loose' variables are evil
JavaScript 'loose' variables may be a strange concept to learn to deal with as a seasoned programmer with a real language. I go into every Ajax talk with my JavaScript Quiz where I always ask people to tell me what is going to be happening in this code. Out of 50 people I am lucky if 2 people can give me all of the correct answers. By adopting a simple naming convention on your part and declaring variables correctly, you do not have to worry about this! You just need to realize the difference between global and local declarations and you will stay out of trouble. If your variable states it is a string keep it that way! Act like it is a strict language!
Defending Attack 2 - JavaScript’s OO is not OO
JavaScript's OO is not perfect, but it can sure do a lot if the developer's spends some time architecting a correct solution. By using prototypes and such we can eliminate a lot of memory leaks and allow us to reuse a lot of code that can be used by multiple functions. If you would read Appendix B in Ajax In Action you would already know this! (Person said they read the whole book! I know he didn't or he would not of asked this since Dave did a great job explaining OOP in Appendix B!)
Defending Attack 3 - Standards are to slow to adapt with browsers
Now you complain about how it is so hard to code with all of the quirks in the browser. Now you need to realize that updating a JavaScript version is not like updating the .NET framework or Java Framework. You know what your code base is. Now when a browser grabs a new version of JavaScript, it has to either support the old version or dump it. Now what if your boss says you need to support Browser 1X and you wrote all of your code form browser 2X. 1X supports version 1 and 2X supports Version2. You would have to dumb down all of your code to support version 1 and hope 2X supports it still. Hence, why JavaScript does not get updated so fast. Now what could be the best improvement for any browser would to be able to update the JavaScript version as a "package" or "upgrade", but you still would have to deal with different versions. With the server upgrade in version, you never have to worry about this, hence why they can update versions so quickly. If you complain about cross-browser coding, wait until a new version comes out! Then you will have Cross-browser-cross-JavaScript version coding!
Sum it up to the attacker
In the end you need to do one of a few things. You either need to step up and deal with all of this "evil" browser coding. You could hire someone that loves this stuff and have them do it. Probably the best solution for you is to spend some time and research a framework that fits your needs. Use a framework that does all of the hard work of cross browser coding for you. All you have to do is call it and act like it is magic when it works in all the browsers. You do not have to bang your head unless you boss says you have to support Netscape 4.x!
Sum up to you the reader
I think people still look at JavaScript as a kid scripting language, anyone can pick it up and learn it as they say. Well it is true, I sat down and learned it 8-9 years ago, published a book on JavaScript, one on Ajax, and I never went to school for programming! I am a .NET Developer coding in C# thanks to JavaScript and the browser wars. Where you a document.all or document.layers guy? If you coded back in the NN 4 / IE 3 days, you know what I am talking about.
Developers grab code samples from around the web and slap them together and wonder why nothing works correctly. Half the code out there has been sitting there for years. When it mentions document.layers/document.all and no mention of document.getElementById() in it, you should really question on using it.
JavaScript is a real language and I am not afraid to call it scripting either since that is what it is. I know when I do my talks; I see a light bulb turn on the developers when I lightly touch on OO scripting techniques. When I give them my quiz and I see them realizing how not declaring a variable correctly can cause problems! I give them a glimpse that there is more than basic functionality with JavaScript. Grab an up-to-date book or up-to-date online reference and relearn what JavaScript has to offer. Heck knowing JavaScript may give you an edge on finding your next job!
Eric Pascarello
Coauthor of Ajax In Action
Moderator of HTML/JavaScript at www.JavaRanch.com
Author of: JavaScript: Your Visual Blueprint for Dynamic Web Pages