Posts

Showing posts from May, 2013

Gulp!

Image
It is not easy to write diplomatically about sex and bowel functions, but Mary Roach does it.   She is a fearless science writer who manages to take taboo subjects and turn them into good books packed with information written in a style that is easily accessible without being condescending. In Stiff: The Curious Life of Human Cadavers (Norton, 2004) , she tells us just what happens to our earthly shell once we shuttle off this mortal coil.   Bonk:   The Curious Coupling of Science and Sex (Norton, 2009) takes us inside the human bedroom and into the sheets for some blushing details about how we make love.   She is also the author of Packing For Mars:   The Curious Science of Life in the Void (Norton, 2010), an exploration of human beings in space and all that it entails.   If you are sensing a pattern here, focus on the word “curious.”   Mary Roach is nothing but curious, and she takes us on a journey in each of her books with insight and humor, although at times she reaches a bit

JavaScript quirk 8: array-like objects

[This post is part of a series on JavaScript quirks.] Some objects in JavaScript look like arrays, but aren’t. They are called array-like . This blog post looks at what exactly that means and how to best work with those objects. Array-like objects An array-like object has: indexed access to elements and the property length that tells us how many elements the object has. does not have: array methods such as push , forEach and indexOf . Two examples of array-like objects is the result of the DOM method document.getElementsByClassName() (many DOM methods return array-like objects) and the special variable arguments [1] . You can determine the number of arguments via arguments.length And you can access a single argument, e.g. read the first argument: arguments[0] Array methods, however, have to be borrowed. You can do that, because most of those methods are generic . Generic methods A generic method does not require this to be an array, it only requires this to have length an

The beginning of infinity in JavaScript

Infinity begins relatively early in JavaScript: > Math.pow(2, 1024) Infinity > Math.pow(2, 1023) 8.98846567431158e+307 What is going on here? All numbers in JavaScript are floating point numbers and (roughly) encoded internally [1] as 1. f × 2 p This is the most common way of representing floating point numbers. The left-hand side of the multiplication comprises the digits, the right-hand side moves the dot to the correct position (to the left if it is negative, to the right if it is positive). The mantissa is a binary 1, followed by a binary dot, followed by a 52 bit fraction f . The 11 bit exponent p has to be in the range −1023 < p < 1024 Thus, the exponent of Math.pow(2, 1024) is out of range and Infinity is an error result. Consult [1] if you want to know more about how numbers are encoded in JavaScript. Reference How numbers are encoded in JavaScript

Plans for supporting Web Components in AngularJS and Ember.js

Web Components [1] are an upcoming standard for custom HTML5 user interface elements. Those UI elements will eventually become interchangeable between frameworks. Now the people behind AngularJS and Ember.js have described their plans for supporting Web Components. Below, you’ll see mentions of Google’s new framework, Polymer [1] . It is built directly on top of Web Components. One of Polymer’s goals is to help refine and fully figure out that standard. AngularJS In an entry on Google Groups, AngularJS co-creator Miško Hevery writes: We're in early stages of designing Angular 2.0, but some of our goals are: Angular will use the underlying web platform features available to it (e.g. Node.bind, template integration, Custom Elements, etc...) Web Components (Polymer, Ember, or any other framework/library) will work seamlessly within Angular apps and directives. Components written in Angular will export to Web Components (to be used by Polymer, Ember, or any other framework/library).

JavaScript quirk 7: inadvertent sharing of variables via closures

[This post is part of a series on JavaScript quirks.] Closures are a powerful JavaScript feature: If a function leaves the place where it was created, it still has access to all variables that existed at that place. This blog post explains how closures work and why one has to be careful w.r.t. inadvertent sharing of variables. Closures Let’s start with an example of a closure: function incrementorFactory(start, step) { return function () { // (*) start += step; return start; } } This is how you use incrementorFactory : > var inc = incrementorFactory(20, 2); > inc() 22 > inc() 24 During all of its lifetime, the inner function (*) has access to the variables start and step of the outer function incrementorFactory . Thus, incrementorFactory returns not only the function, but somehow attaches the variables start and step . The data structure in which both variables are stored is called an environment . An en

Google’s Polymer and the future of web UI frameworks

Updates: [2013-07-16] Hello Polymer: Q&A with Google’s Polymer team [more information on Polymer] [2013-05-23] Plans for supporting Web Components in AngularJS and Ember.js At Google I/O 2013, Google presented a new web user interface (UI) framework called Polymer . The way it works is indicative of the future of all web UI frameworks. Polymer Polymer is composed of the following layers: Foundation (platform.js): Foundational building blocks. Most, if not all, of these APIs will eventually become native browser APIs. Core (polymer.js): Helpers complementing Foundation. Elements: UI and non-UI components built on Core. The Foundation layer (platform.js) The Foundation layer comprises the following technologies: DOM Mutation Oberservers and Object.observe() (probably ECMAScript 7): for observing changes to DOM elements and plain JavaScript objects. Pointer Events : handle mouse and touch in the same manner, on all platforms.

The Man Who Fell To Earth

Image
Album cover shoot for Alladin Sane , 1973. Photo by Brian Duffy . Copyright Duffy Archive* Mr. Bleck was my fifth grade language arts teacher.   He dressed in rumpled suits that often made him look a bit heavier than he actually was.   His wit was dry and caustic, and I did not understand his jokes at times.   What I did notice were his long, elegant fingers stained with nicotine, and once when I passed the faculty room on some errand for another teacher, I heard his cackling laughter as the door swung open.   I turned in the direction of the sound to catch a glimpse of the man, his head thrown back, and a cigarette between those fingers gracefully emitting a trail of smoke that collected in the small room.   Then the door closed. Because of his disheveled elegance, I sensed something off about him.   He could sneer and be catty at times in the classroom, and often when I sought praise and affirmation, he responded with a sarcastic aside that made the whole enterprise ring hollow.  

JavaScript quirk 6: the scope of variables

[This post is part of a series on JavaScript quirks.] In most programming languages, variables only exist within the block in which they have been declared. In JavaScript, they exist in the complete (innermost) surrounding function: function func(x) { console.log(tmp); // undefined if (x < 0) { var tmp = 100 - x; // (*) ... } } The cause of the above behavior is hoisting : Internally, the declaration at (*) is moved to the beginning of the function (the assignment stays where it is). That is, what a JavaScript engine actually executes looks like this: function func(x) { var tmp; console.log(tmp); // undefined if (x < 0) { tmp = 100 - x; ... } } But there is a trick to limit the scope of a variable to a block, it is called Immediately Invoked Function Expression (IIFE, pronounced “iffy”). Below, we use an IIFE to restrict the scope of tmp to the then-block of

Netflix’s technology and hiring practices

In the article “ Netflix, Reed Hastings Survive Missteps to Join Silicon Valley's Elite ”, Ashlee Vance profiles Netflix and its CEO Hastings for Businessweek. The article mentions a few interesting tidbits about the company’s technology and hiring practices: Netflix data comprises a third of the incoming data in North American homes. Their infrastructure is based on Amazon Web Services. In off-peak hours, Netflix’s systems are repurposed to analyze data. The results are used to pre-cache data and to determine the likelihood of success of a show that Netflix might finance. As an employer, Netflix pays well: Managers routinely survey salary trends in Silicon Valley and pay their employees 10 percent to 20 percent more than the going rate for a given skill. Fired employees also get ultragenerous severance packages; the idea is to remove guilt as an obstacle to management parting ways with subpar performers. And they prefer to ha

JavaScript history: undefined

Two tweets by Brendan Eich shed light on the history of JavaScript having both undefined and null [1] . The first version of JavaScript did not have exception handling, which is why JavaScript so often converts automatically [2] and/or fails silently ( tweet ). JavaScript copied Java’s approach of partitioning values into primitives and objects [3] . null is the value for “not an object”. The precedent from C (but not from Java) is to convert null to 0 (C has pointers, not references and lets you perform arithmetic with pointers). Remaining problem: In JavaScript, each variable can hold both primitives and objects. In Java, a variable’s static type limits it to either kind of value. We therefore need a value for “neither a primitive nor an object”. That value could be null , but at the time, Eich wanted something that wasn’t “reference-y” (associated with objects) and did not convert to 0 ( tweet ). Now you know why undefined and null are converted to different numbers: >

Beyond “always on”

Current technology encourages us to be continuously connected. This blog post predicts that that will change. Always on The direction that technology currently takes us could be described as “always on”. The goal is to give us more updates, more quickly. Three recent examples. First, Facebook Home . The website describes the “always on” vision quite well (emphasis is mine): With Home, everything on your phone gets friendlier. From the moment you turn it on, you see a steady stream of friends’ posts and photos. Upfront notifications and quick access to your essentials mean you’ll never miss a moment . And you can keep chatting with friends, even when you’re using other apps. Second, Google Glass , where there is always a screen in front of your eyes. Third, existing and rumored smart watches which are also about receiving notifications more directly. Beyond “always on” Notifications are a form of stimuli. And, for evolutionary-biological reasons, those are hard to resist for humans.

Show Some Love For The Teacher

Image
May 6 th through 10 th is Teacher Appreciation Week.   We have all heard the various opinions about the world’s other oldest profession:   teachers aren’t paid enough; teachers have it easy because they have summers off; teachers put in long hours after the school day ends; teachers don’t work hard enough to engage their students; teachers are the best and the brightest the nation has to offer; teachers are those who’ve failed at everything so they enter the classroom as a last resort. Yes, depending on who is yapping, the story shifts from praise to blame. You can’t measure learning like you measure flour to make a cake.   No standardized test can gauge the effect of a good teacher on a student.   We are talking here about the most crucial role in the building of a future:   the vocation of a teacher.   To be a good one, you must be smart, quick, savvy, determined, strong, and resilient. A good teacher knows how to communicate with students.   She also knows and loves her subject.