06

11/10

JavaScript – A Love/Hate Relationship

00:20 by rleahy. Filed under: Technology

So a buddy and I decided to work on an AJAX-based chat server/client, as an exercise in ASP.NET, .NET Sockets and Threading, and JavaScript, and it really brought to the forefront the reasons that I alternately love and hate JavaScript…

As it stands we’re both working on it separately—being that it’s an academic exercise—but eventually I think we’ll merge out efforts and work to our strengths (I’m really good at writing back-end code, but am terrible at HTML/CSS, which is good because it means I probably won’t have to write JavaScript again…).

Anyway, working with JavaScript is really one of those love/hate things for me, and I guess I felt compelled to blog about it. I went to blog about it about 12 hours ago—while I was actually writing it—but decided that my post would be too rage-filled…

…and that might be too overwhelming for a first blog post.

The great part (i.e. the “love” part) of JavaScript is when you’re finished. It does really, really cool shit, doesn’t even take that long to write, and there’s a lot of boilerplate code out there to work from.  AJAX is especially awesome, watching this HTML—which you have this expectation of being static—get “pushed” chat messages is nothing short of magical (not to sound like Steve Jobs…).

The bad part (i.e. the “hate” part) is actually writing the JavaScript.  I can’t think of a single language I hate more (not even Java, and I hate Java) than JavaScript.  The main problem I have with it is the fact that it’s so cross-platform, so cross-browser, that the debugging errors that are given are totally meaningless.  Take this line of code for example:

document.GetElementById("chat_div").Style.Display="none";

Seems fine, but it’s not, because JavaScript is case sensitive (which seems bizarre for a scripting language, but whatever) and uses the camelCase convention.  While in a sensible language—like C# —you’d get a helpful (or at least semi-helpful…) error message, in JavaScript you get “Object expected”, which leads you to believe that DOM couldn’t find the element with ID “chat_div”, which just isn’t the case at all.

Compound this with the fact that I already have high blood pressure…