Why did I want to stop using jQuery as much as I can and move on to AngularJS
2/16/2014, 1:01:02 PM
I didn’t like to use jQuery very much when I started building Peatix. What I didn’t like most was the fact that by merely writing $(’.class-yeah-its-just-a-marker’) you could jump here from there and everywhere. I am a crazy old man. I learned how to program by learning Structured Programming. Yes, that “avoid goto, everything you write you can write in a sequence, loop or conditional blocks”. Yeah I am old. What are you looking at?
To me jQuery selector is a GOTO in BASIC (and any other languages). It’s actually a feature that only advanced programmers can use it correctly for a few correct reasons. Yet similar to GOTO in BASIC, it is always those someones who are not real programmers who don’t have solid understanding of whatever programming paradigm who tend to use jQuery. And the code written by those someones breaks my beautifully structured, object oriented, whatever what'ed code.
Well, jQuery is not to be blamed. JQuery is great. JQuery saved us a lot. But it’s time for me to move on to more structured way of writing frontend code.
Enter AngularJS. Until last week I only took a few glances of its tutorial, and read a few articles about it. It sounded like you would be able to separate your HTML completely from someone else’s jQuery. It sounded nice.
I started writing my first AngularJS controller. The web site that I took had a simple search function and the backend API is quite nicely written by my colleague. I only had to move the code that was written with Underscore and jQuery to AngularJS.
It turned out it was actually mere three days job to fully migrate the page to be based on AngularJS. Part of the reason is that the page was already well separated into logic and view thanks to my colleague. I saw a few holes in here and there while I was working on that page, which I will explain in the following entry.
So far I like how I write AngularJS controller and a few helper modules, and tests. It doesn’t make me feel anxious like jQuery did when I wrote a jQuery selector that was too vulnerable to a change to HTML/CSS.