AMD - totally unrelated to processors

AMD


 I have used javascript a lot and still can not fathom the messy selectors and callbacks. Being a part of a team that probably has millions of javascript code scattered in every page (before the rise of the SPAs (single page applications)) it is a real pain, not to mention dealing with browser support (don't get me started on this). I try to minimize my involvement in having to deal with javascript issues.

But javascript tools are getting better thanks to  Chrome, FireBug and now WebStorm javascript is now becoming a language of choice for web development. Javascript filled the gap of a much more responsive web ui. It vanquished having to wait for a response from  a web server. This responsiveness is now being utilized in mobile development as well. There is a lot happening in the javascript world Node.js, D3 just to mention a few and a lot more will happen.

As javascript becomes a necessary tool in any software development, patterns and best practices emerges that addresses concerns that most of us software developer have, like reuse, maintenance and modularity just to mention a few. One of the interesting discussions that i have been following is AMD (Asynchronous Module Definition ). There have been points made Why AMD? and counter points made AMD is not the answer. It is a very interesting discussion. But rather just accept each point one way or the other and me being practical my question is this "Would AMD help me develop better software or even make me productive ?"

What is AMD ?

AMD is a javascript API that will help you define and load modules (basic computer program components) and it's dependencies asynchronously. So why load asynchronously ? because of performance. Loading asynchronously means that the javascript you are using/loading would not hold up the rendering of your page while the javascript loads. This means that a user will not see a frozen screen and browse some other web page.

What is the alternative without using AMD ?

Well you can load your modules one by one which means a frozen up screen Or load it asynchronously without using AMD (Here is a sample)

If I decided not to use AMD i will have to try to create a mechanism to load javascript asynchronously but if  i have a lot of javascript libraries it might be a pain having to code additional lines just to have them load.

After trying to convince myself that AMD is a right choice i took it our for a spin of course using the famous todoMVC  -- best site to help you decide with javascript MV (Why is the C missing ? -- will pick another time to discuss this) is right for you. Here is the result of that (https://github.com/petabyte/BackBoneToDo). This was an attempt to use and understand backbone and requirejs (AMD api) .. thanks to the todoMVC website.

So after getting my feet wet, here is what i think about AMD

1. AMD really helps in loading those javascript.
2. Modularity is really good in any language. I like how AMD forces me to organize my modules and group them as i see fit so that there is sense and structure in my javascript codes. Not like at the time when jQuery selectors rule them all.
4. As I broke down my code into modules, I see them multiplying and was concerned with their numbers. Would the number of my modules negate the fact that they will be loaded asynchronously ?
Well in the API that i used RequireJS -- there is an optimizer -- i think it minifies the javascript library so that it will be smaller (still have to try this)
3. Helps me debug easily and change my javascript code. It really helps in my everyday development.


Comments

Popular posts from this blog

OAuth 1.0a Request Signing and Verification - HMAC-SHA1 - HMAC-SHA256

Spark DataFrame - Array[ByteBuffer] - IllegalAurmentException

Gensim Doc2Vec on Spark - a quest to get the right Vector