JavaScript Promises – Gotchas and Anti Patterns

tl;dr

  • Flatten the Promise chain whenever possible
  • Straighten multiple nested promises with q.all() and q.spread()
  • Don’t break the Promise chain. Make sure that the last promise is returned to the caller.
  • Don’t overuse deferreds. Use them to promisify callback functions. In case a function returns a promise, it’s just better to form a chain with that same promise.

The long version

Continue reading

Validations with Ember.js

These days, with the rise of the single page applications, there has been a steady rise in the number of complete websites that are built on a client side JavaScript framework.
At any given point of time, these sites have always had the need for validations that they need to run client side.

Recently, while working on a pet-project using Ember.js as the client side framework and jQuery for running my client side validations, I came across a rather interesting question.
How would you handle client side validations with a framework such as Ember.js?  Continue reading

Code Jugalbandi

In Indian classical music, we have Jugalbandi, where two musicians or vocalists engage in playful competition.

A typical jugalbandi between a Flutist and a Percussionist plays out like this:

The percussionist listens to the intricate compositions played by the flutist and recreates them symmetrically. Needless to say, this often results in an exhilarating musical experience for the audience.

On a similar metaphor, I am proposing the idea of Code Jugalbandi across multiple programming languages (not just two) and see how the same code is rendered using different languages. Continue reading