Saturday, August 16, 2014

coding can be punishing at times...with a stress on AngularJS

What I mention here must be extremely familiar for coders. I come from the world of 'C' language in the early nineties. There were very few tools to use. I had to code a linked list for every small thing. I happily did it. Did not complain. It may appear stupid now. But that was how the world was. You had to write every bit of your code.

The scene now in coding is a lot different. There is a lot more collaboration due to open source, stack overflow and of course Google. Every question is out there asked by some one and answered by a bunch. While this is all good time for coders, the number of frameworks and tools that are available are immense.

I tried my hand with Servlets, JSP, JQUERY, JS, AngularJS and so on and on. I have spent more than a year with AngularJS now. I have very mixed opinion about it not from what all it can solve but the information that is available out there for coders from the community in variety of ways. So many different voices and so many different ways of explaining the same thing. I am afraid what I write here can again spin off into discussions. Contrast this with K&R C language. One and only authoritative, precise and clear book to learn 'C' language. Of course, there were other books as well. But language which solved pretty much the syntax and semantics of programming constructs could very much be expressed in a small book. How to solve problems with that was elucidated in many other books taking real world examples. And that's it.

Now, with the web, every one has become an author. And there are these 1 million plus links thrown by Google for everything. So how on earth you figure out simple, clean answers for your questions? The answer is fairly simple. Just get lost. I mean get lost in the sea of information out there. The price you pay for democracy. Millions of voices, zillions of things. See already I digress from what I want to say.

AngularJS has code examples and demo examples everywhere. It seem to be doing wonderful if you are person who has done enough Javascript in life and can understand the design patterns of Javascript, IoC, scope hierarchy, dependency injections, Object oriented JS, pub-sub-notify etc. However, there is no single thing which explains you the fundamentals of the these things and then talk about how AngularJS has brought in these aspects. There is a sea of demos and specific examples. The angularJS book by O'Reilly is definitely not something that covers the fundamental aspects in a simpler way for all to understand. That is the only book I have seen. The syntax is very convoluted and unreadable many times. It only makes sense after you spend a year on it. That too you get confused with the constant mixture of square brackets, curly braces and the $ signs.  It is definitely not for the weak hearted.

With so many different variations available to solve some problem, it amplifies the pain when someone's aim is to solve a business problem burning in their head. The syntax can be frustrating and can cause significant delays in schedules if you are new and picking up. And no one who comes on the videos from the AngularJS team or others who have supported this seem to bother about making life simple with easy to read syntax.

Added to this is the constant chatter about testing. It is great that testing everything eases your life. Towards it AngularJS has a steady supply of tools from community like Yo, Grunt, Bower, Karma, Jasmine and so on. I have been of late trying to use some of these. And specifically I have found that like using the AngularJS framework, these tools are also have lack of simple documentation explaining why they are there, how they are related to one another.

For example, Yo is a scaffolding service to create a boiler plate layout of your angular files plus it interacts with Bower to download dependent libs and Grunt  to run tasks. This can be explained with some simple visual diagrams somewhere rather than reams of text or demo examples that dive into the configuration aspects immediately.

There is no doubt that they make your life simple once you are familiar with them. But as I said, it is not for even for the newbies. They can shy away seeing the number of things to try out and the time it takes initially.

I request the authors of these tools to put out simpler and more fundamental descriptions with simpler English , visuals and examples rather than just pieces of code with demos with absolutely no explanation of them expecting the reader to make out things on their own.

To give an idea of a better explanation I give this link on AngularJS scopes. This is more fundamental, clear with pictures and covers a number of scenarios. https://github.com/angular/angular.js/wiki/Understanding-Scopes

I am not against AngularJS if you feel I sound so. I salute the team for their efforts, the community for jumping to solve a problem free of cost and the numerous ways they have made life better in solving the HTML/CSS/JS entanglement. I use them, have benefited by using them. The only complaint I have is the initial complexity in understanding them (when I say understanding, I mean making sense of them in a fundamental way) to be able to code complex behaviours for a newbie is bewildering with too many jargons and the issue with internet scale collaboration.

There needs more improvement in the content of the documentation around these new tools which are coded by some of these smart people around who end up answering questions on stack overflow rather than putting out documentation on why they envisioned such a thing and how they have solved in a way everyone can understand.

To end this, I will give a example of what took me a day to fix. I was using Yo/Grunt to run Karma tests on a Angular directive. The mistake I did was in the karma.conf.js I kept the order of the files with Angular JS files after my own scripts. This ended up not $compiling my directive and as a result there is no HTML generated for me to test with JQUERY find etc. This is probably a simple , stupid error for the people who have authored these tools. Also, this may not be anything to do with the AngularJS or Karma. It is probably the way dependencies get loaded and resolved in the JS world. However, since I was new to all of these, I went hunting into everything from the syntax to config files to stack overflows to Google and trying out tirelessly, mind numbingly the different options I had until it struck me from the error that the HTML of the directive is not getting generated.

Man! Life should be better than this any day.


No comments:

Post a Comment