Structure is emergent, not primary. When we set out to build a structure, and then fill it in, it’s not just that we will build the wrong thing, it’s that we won’t notice we’ve built the wrong thing until too late, and won’t be able to easily fix it.
Using promises for clean asynchronous logic
Awareness of the Promises pattern has steadily increased since Deferreds were introduced into jQuery last year. I was impressed with this informative read by Jesse Hallett which starts with the basics then continues with a step-by-step example of using small asynchronous flows as components for building more complex ones. The example’s subject matter is easily recognized by any frontend developer who has struggled with logic to coordinate multiple interrelated AJAX requests in a fault-tolerant way. The result from leveraging deferreds and promises is much simpler and safer than before.
Moving on, Jesse presents a function called flatMap which is able to generalize sequential operations in the same way $.when generalizes parallel ones. As pointed out later, $.pipe provides much the same functionality as flatMap, but watching flatMap implemented as a step-by-step refactoring of the example code from the post provides increased understanding of why this pattern is useful and how it can be used. Article:
I see this type of approach as useful in place of most types of inheritance, especially for implementing a plugin system into a larger library, and plan to give it a try the next time I need something similar. Innovative work, Twitter guys. Presentation link:
My previous blog was a custom solution I wrote using Ruby on Rails. It was a good learning experience, but due to my busy schedule it contained only some old announcements that may have been interesting 2 to 3 years ago when they were written along with some long-outdated technical writing. To simplify, and maybe gain a little more time for sharing some thoughts here, I am starting over with this tumblelog.