Posts

Showing posts from July, 2013

A meta style guide for JavaScript

JavaScript has many great style guides. Thus, there is no need to write yet another one. Instead, this blog post describes commonly accepted meta style rules and conventions that I like that are controversial. The idea is to help you make a more informed decision about what is right for you . Existing style guides The two style guides I like best are: Idiomatic.js: Principles of Writing Consistent, Idiomatic JavaScript Google JavaScript Style Guide Additionally, there are two style guides that go meta: Popular Conventions on GitHub : analyzes GitHub code to find out which coding conventions are most frequently used. JavaScript, the winning style : examines what the majority of several popular style guides is recommending. General tips Code should be consistent There are two important rules for writing consistent code. The first rule is that, if you start a new project, you should come up with a style, document it and follow it everywhere. The larger the team, the more i...

ECMAScript 6 modules: the future is now

Update 2014-09-07: Newer version of this blog post: “ ECMAScript 6 modules: the final syntax ”. Read it instead of this one. This blog post first explains how modules work in ECMAScript 6, the next version of JavaScript. It then describes tools that allow you to already use them now. 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 (CJS): The dominant incarnation of this standard is Node.js modules (Node.js modules have a few features that go beyond CJS). 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...

I Hate to Leave this Beautiful Place

Image
Howard Norman mixes nostalgia (without sentimentality), environmentalism (specifically ornithology), folktales (Native American and Inuit), personal essay (and personal tragedy), and a healthy dose of quirkiness native to the far north of North America.   The result is I Hate to Leave this Beautiful Place:   A Memoir (Houghton Mifflin Harcourt, 2013). Norman is a mainly a novelist, but he has also translated a number of Inuit and Native American folktales.   It is from one of these tales that he gets the title of the book.   His path to a life of letters is an unusual journey:   high school dropout; various odd jobs; college to get double degrees in English and zoology; and completion of a graduate program in linguistics and folklore.   This book consists of five expansive personal essays.   He ties his work together using a quote from Saigyo , a poet-monk of 12 th century Japan:   “A soul that is not confused is not a soul.”   It is his ...

In defense of JavaScript’s constructors

JavaScript’s constructors have never been particularly popular: Douglas Crockford doesn’t like them and recently, more anti-constructor material has been published (two examples: blog posts by Kyle Simpson and Eric Elliott ). In this blog post, I explain that not all of the constructors’ flaws are real. But even with those that are real, I still recommend to use them. I’ll tell you why and what the future holds for constructors. Recommendations For ECMAScript 5, I recommend to: always use constructors always use new when creating an instance The main advantages of doing so are: Your code better fits into the JavaScript mainstream and is more likely to be portable between frameworks. Speed advantages. In modern engines, using instances of constructors is very fast (e.g. via hidden classes ). Classes, the default inheritance construct in ECMAScript 6 (see below), will be based on constructors. There are a few arguments against using constructors and new...

Rebecca Solnit

Image
The personal essay is a popular genre of nonfiction these days, taking up prominent column inches in magazines and often assigned to high school and college students as a way to break them into writing or as a vehicle for admissions officers to separate those they want from those they don’t.   The thing is, the personal essay is difficult to write, and a high wire act that offers a number of possible pitfalls for the author.   The best writers travel the razor sharp edge between blatant narcissism and deeply felt resonance, managing to take their life stories and hold them up like mirrors in which we, the readers, see ourselves.   I am thinking now of the greats like Michel De Montaigne , Henry David Thoreau, E.B. White, Joan Didion , Annie Dillard, and Richard Rodriguez.   A new name to add to the list is Rebecca Solnit. Solnit is the author of twelve books, all of which are great, but two loosely connected collections make for a good entry point into her oeuvre. ...