Thursday, August 28, 2008

Javascript is Awesome Now

This year I've been learning two languages: Javascript and Perl (I'll talk about Perl later). I have a few years of "experience" with javascript. I mean onclick="alert('Bork!!!! you broke it...')" counts right? I remember about 3 years ago when the AJAX buzz first came to my attention. We were using it on our project for the first time. I did a few simple XMLHttpRequest things and it was cool. But I gave the UI guy on our team a bunch of grief for the "ridiculous" amount of javascript he was writing:

WTF are you thinking, making a whole domain model in javascript? And using javascript to write html snippets or pretending to do OO programming? We do all that stuff on the server side.... Don't you know javascript sucks?


Well it did until recently. I've started working on a few things that require some serious javascript. Now I want to apologize to my former teammate, you knew what it was all about long before I did. I should have listened back then because javascript is dead sexy now! jQuery is amazing and I really like Greasmonkey as well. I'm finally starting to understand how javascript the language itself works and how that relates to running it in the browser environment. It's really opened my eyes to the power of functional programming as well. Passing around functions is great! I find that it spills over and I get frustrated writing java sometimes now. I'll be coding along thinking: ok now all i have to do is pass in this function here... DOH!


Most recently the whole namespaces pattern really helped me structure my code in a way that made sense. For the longest time I was trying to figure out a clean way to lay out all the different callbacks so that they weren't all nested 12 deep and tangled up. Now I'm starting to get good reuse and I can easily separate related code out into separate files.

This same hurdle keeps coming up. Every time I try to learn a new programming language one of the things I worry about the most is where do I put the files? How do I make packages/namespaces/modules? Where do 3rd party plugins/libraries/frameworks go? I need to understand that structure--I guess my mind just works that way. In .NET I have my VS projects and namespaces all there keeping my code in order. Same with java, packages are built into the language and components have well defined structure (WAR, EAR, JAR files). It doesn't feel like I know the language until I can create a "Project" from scratch and know where to put the files and how to structure the code in those files.

So I can finally say I've crossed that milestone with javascript. Now I can build something useful with it. To me that is awesome.

2 comments:

Justin Wilson said...

Javascript does rock.. I did my first AOP stuff in it the other day.. I feel the same way though.. I'll be coding something up quick and think 'hey I can do this' and then I realize I've taken for granted some of Javascript's strengths..

BlackTigerX said...

Justin, that is not true, you did AOP a while ago in our project, remember?