Posts

Showing posts from June, 2015

Tail call optimization in ECMAScript 6

Image
ECMAScript 6 offers tail call optimization , where you can make some function calls without growing the call stack. This blog post explains how that works and what benefits it brings. What is tail call optimization? To understand what tail call optimization (TCO) is, we will examine the following piece of code. I’ll first explain how it is executed without TCO and then with TCO. function id(x) { return x; // (A) } function f(a) { let b = a + 1; return id(b); // (B) } console.log(f(2)); // (C) Normal execution Let’s assume there is a JavaScript engine that manages function calls by storing local variables and return addresses on a stack. How would such an engine execute the code? Step 1. Initially, there are only the global variables id and f on the stack. The block of stack entries encodes the state (local variables, including parameters) of the current scope and is called a stack frame . Step 2. In line C, f() is called: First, the loca...

Grief and Freedom

Image
What a Friday for the history books.   In short order, the United States Supreme Court endorsed gay marriage in all fifty states, writing in the majority opinion: “No union is more profound than marriage, for it embodies the highest ideals of love, fidelity, devotion, sacrifice, and family. In forming a marital union, two people become something greater than once they were. As some of the petitioners in these cases demonstrate, marriage embodies a love that may endure even past death. It would misunderstand these men and women to say they disrespect the idea of marriage. Their plea is that they do respect it, respect it so deeply that they seek to find its fulfillment for themselves. Their hope is not to be condemned to live in loneliness, excluded from one of civilization’s oldest institutions. They ask for equal dignity in the eyes of the law. The Constitution grants them that right.” Even as this decision was being celebrated all over America, President Obama was giving the eu...

Bibliotech

Image
I guess it is my fault that I found John Palfrey’s book, Bibliotech:  Why Libraries Matter More Than Ever in the Age of Google (Basic Books, 2015) somewhat disappointing.   I was looking for the very thing Palfrey says his book is not:   a paean to the libraries of the past offering a nostalgic, wistful, sepia-toned wish for a time now long gone.   He does admit that there is much to celebrate and love “about the libraries of the past,” but he is administering here what he calls “a dose of tough love.”   How can these institutions survive and even thrive in the burgeoning information age?   That is the question Palfrey seeks to answer. From the start, Palfrey makes clear he is a “feral,” a “nonlibrarian who ends up working in a library.”   He believes the institutions are at risk “because we have forgotten how essential they are” in this age of Google and Wikipedia.   He calls libraries essential cogs in the wheels of democracy, and believes the...

WebAssembly: a binary format for the web

Image
Updates: [2015-07-02] New material in these sections: How do I create WebAssembly code? First experiences in practice Further reading [2015-06-24] I added an FAQ with three new questions: Does the web finally have a universal bytecode? Isn’t WebAssembly like Flash? Will WebAssembly make JavaScript faster? WebAssembly (short: wasm ) is a new binary format for the web, created by Google, Microsoft, Mozilla and others. It will be used for performance critical code and to compile languages other than JavaScript (especially C/C++) to the web platform. It can be seen as a next step for asm.js [3] . asm.js Most JavaScript engines have the following compilation pipeline: JavaScript source → bytecode → machine code The idea of asm.js is to code JavaScript in such a way that engines produce machine code that is as efficient as possible. That is, you kind of try to bypass the first compilation step. The results are impressive: if one compiles C++ to asm.js one can reach 70% of native speed in we...

Scott Stossel's Age of Anxiety

Image
We’ve all been there:   the tightening of the throat, the shallow breathing, the twinge of pain around the heart, the dry mouth, the inability to focus.   It is anxiety.   We live in anxious times.   But when haven’t we lived in anxious times, and before we get too far into our own neuroses, are there not times in history when things might have been more precarious, more dangerous, more downright scary?   I am thinking now of the height of the Second World War when victory was not imminent, or in the late 60s when one had a reasonably good chance of being drafted, handed a weapon, and told to go fight in the jungles of Vietnam.   What about the Dust Bowl, the Plague, the Great Flu, the Great Depression?   Surely every age is one where anxiety might be the right and proper response to the circumstances that threaten the very existence of us. Scott Stossel, in his book My Age of Anxiety:  Fear, Hope, Dread, and the Search for Peace of Mind (Vintag...