Posts

Showing posts from October, 2014

Statically typed JavaScript via Microsoft TypeScript, Facebook Flow and Google AtScript

Update 2014-11-18: Facebook Flow has been released as open source. Its website is flowtype.org . The site mentions plans for Flow’s future . This blog post looks at three initiatives for adding static typing to JavaScript: Microsoft’s TypeScript, Facebook’s Flow and Google’s AtScript. Typing Let’s first clarify some terminology related to typing (excerpted from “ Speaking JavaScript ”). Static versus dynamic In the context of language semantics and type systems, static usually means “at compile time” or “without running a program,” while dynamic means “at runtime.” Static typing versus dynamic typing In a statically typed language, variables, parameters, and members of objects (JavaScript calls them properties) have types that the compiler knows at compile time. The compiler can use that information to perform type checks and to optimize the compiled code. Even in statically typed languages, a variable also has a dynamic type, the type of the variable’s value at a given point at run...

Days of Fire

Image
During the outbreaks of Bubonic Plague , better known as the Black Death, many devout Christians believed that the prophecy inherent in the book of Revelation was about to be realized.   The disease came after drought and famine, and as the bodies began to pile up, people desperately tried to find a rhyme or reason as to why some were infected and some avoided getting sick.   Ships arrived in port with every sailor sick and dying, and in at least a few cases, the vessels ran aground because everyone on board was already dead.   At night, people reported strange fires and mists that seemed to carry pestilence and immediate death.   All day in the sweltering heat of summer, the pope kept huge fires burning in the papal apartments at Avignon, believing that aromatic wood would ward off infection.   Those days of fire did nothing to keep Death at bay. The plague took three forms:   a lymph infection causing buboes, apple-sized swellings that became purple or b...

ECMAScript 6 promises (2/2): the API

Image
This blog post is outdated. Please read chapter “ Promises for asynchronous programming ” in “Exploring ES6”. This blog post is an introduction to asynchronous programming via promises in general and the ECMAScript 6 (ES6) promise API in particular. It is second in a series of two posts – part one explains foundations of asynchronous programming (which you may need to learn in order to fully understand this post). Given that the ECMAScript 6 promise API is easy to polyfill for ECMAScript 5, I’m mainly using function expressions and not ECMAScript 6 arrow functions , even though the latter are much less verbose. Promises Promises are a pattern that helps with one particular kind of asynchronous programming: functions (or methods) that return their results asynchronously. To implement such a function, you return a promise , an object that is a placeholder for the result. The caller of the function registers callbacks with the promise to be notified once the result has been computed. Th...