Posts

Showing posts from September, 2014

ECMAScript 6 promises (1/2): foundations

Image
This blog post is outdated. Please read chapter “ Asynchronous programming (background) ” in “Exploring ES6”. This blog post explains foundations of asynchronous programming in JavaScript. It is first in a series of two posts and prepares you for part two , which covers promises and the ECMAScript 6 promise API. The JavaScript call stack When a function f calls a function g , g needs to know where to return to (inside f ) after it is done. This information is usually managed with a stack, the call stack . Let’s look at an example. function h(z) { // Print stack trace console.log(new Error().stack); // (A) } function g(y) { h(y + 1); // (B) } function f(x) { g(x + 1); // (C) } f(3); // (D) return; // (E) Initially, when the program above is started, the call stack is empty. After the function call f(3) in line (D), the stack has one entry: Location in global scope After the function call g(x + 1) in line (C), the stack

ECMAScript 6 modules: the final syntax

Check out my book (free online): “ Exploring ES6 ”. Updated version of this blog post: chapter “ Modules ”. At the end of July 2014, TC39 [1] had another meeting , during which the last details of the ECMAScript 6 (ES6) module syntax were finalized. This blog post gives an overview of the complete ES6 module system. Module systems for current JavaScript JavaScript does not have built-in support for modules, but the community has created impressive work-arounds. The two most important (and unfortunately incompatible) standards are: CommonJS Modules: The dominant implementation of this standard is in Node.js (Node.js modules have a few features that go beyond CommonJS). Characteristics: Compact syntax Designed for synchronous loading Main use: server Asynchronous Module Definition (AMD): The most popular implementation of this standard is RequireJS . Characteristics: Slightly more complicated syntax, enabling AMD to work without eval() (or a compilation step). Designed for asynchron

How About Never--Is Never Good For You?

Image
It is probably not fair that I read and loved Roz Chast’s cartoon memoir of her last years with her parents before I read Bob Mankoff’s similar reflections on his life in How About Never—Is Never Good For You?: My Life in Cartoons (Henry Holt and Co., 2014).   Both are great cartoonists; Bob Mankoff is the cartoon editor at The New Yorker while Chast is one of many in the humorous illustration business at the magazine.   Both books consist of drawings and prose, making them unique in the way they tell a life story.   However, that is also where the two diverge dramatically.   Chast’s memoir was both sad and funny in equal measure and focused on a specific time in her life.   Mankoff goes for a mix of autobiography and an analysis of cartoon humor and specifically, humor at The New Yorker.   In this way, his book is less funny, although there are some classic cartoons reprinted here, many from other cartoonists that Mankoff has edited over the years as well as from Mankoff himself.  

Standardizing (a flavor of) Markdown

Update 2014-09-05: Jeff Atwood renames “Standard Markdown” to “Common Markdown” and apologizes to John Gruber. Details: “ Standard Markdown is now Common Markdown ”. On September 3, Jeff Atwood announced a new standardization effort for John Gruber’s Markdown : Standard Markdown . It is amazing how ubiquitous Markdown has become and it’s great that there is now a standard for it. Highlights: The working group comprises representatives from: GitHub, Reddit, Stack Exchange, the open source community. There is a proper specification that also describes a parsing strategy. This should help tremendously with writing a parser that can handle all content that complies with the standard. Given all the incompatible Markdown dialects in existence, that is currently a very difficult task. There are reference implementations in JavaScript and C and a validation test suite. You can try out the reference implementation online. Background: The whole effort more or less started with a blog post b

For The Time Being

Image
Annie Dillard ’s books have always had a deeper, more spiritual quality.   Many are just like Buddhists’ works—short, pithy, and intense, the kinds of books where one reads a few sentences and then must stop to contemplate and internalize the insights.   Her greatest are A Pilgrim At Tinker Creek (Harper Perennial Modern Classics, 2007), An American Childhood (Harper & Row, 2013), Teaching A Stone To Talk:  Expeditions and Encounters (Harper Perennial, 2013), The Writing Life (Harper Perennial, 2013), and the book under consideration here, For The Time Being (Vintage, 2000). In truth, this is my second trip through this book.   The first time, not only did I find the book moving and inspirational, but the author led me to other works that are now an integral part of my library.   She opens the book with a quote from Evan S. Connell :   “The legend of the Traveler appears in every civilization, perpetually assuming new forms, afflictions, powers, and symbols.   Through every ag