Categories
Uncategorized

Three Months of CoffeeScript

coffeescript

Guest Post by Kamil Tusznio!

Kamil’s a developer at Shopify and has been working in our developer room just off the main “bullpen” that I like to refer to as “The Batcave”. That’s where the team working on the Batman.js framework have been working their magic. Kamil asked if he could post an article on the blog about his experiences with CoffeeScript and I was only too happy to oblige.

CoffeeScript

Since joining the Shopify team in early August, I have been working on Batman.js, a single-page app micro-framework written purely in CoffeeScript. I won’t go into too much detail about what CoffeeScript is, because I want to focus on what it allows me to do.

Batman.js has received some flack for its use of CoffeeScript, and more than one tweet has asked why we didn’t call the framework Batman.coffee. I feel the criticism is misguided, because CoffeeScript allows you to more quickly write correct code, while still adhering to the many best practices for writing JavaScript.

An Example

A simple example is iteration over an object. The JavaScript would go something like this:

Meanwhile, the CoffeeScript looks like this:

Notice the absence of var, hasOwnProperty, and needing to assign value. And best of all, no semi-colons! Some argue that this adds a layer of indirection to the code, which it does, but I’m writing less code, resulting in fewer opportunities to make mistakes. To me, that is a big win.

Debugging

Another criticism levelled against CoffeeScript is that debugging becomes harder. You’re writing .coffee files that compile down to .js files. Most of the time, you won’t bother to look at the .js files. You’ll just ship them out, and you won’t see them until a bug report comes in, at which point you’ll be stumped by the compiled JavaScript running in the browser, because you’ve never looked at it.

Wait, what? What happened to testing your code? CoffeeScript is no excuse for not testing, and to test, you run the .js files in your browser, which just about forces you to examine the compiled JavaScript.

(Note that it’s possible to embed text/coffeescript scripts in modern browsers, but this is not advisable for production environments since the browser is then responsible for compilation, which slows down your page. So ship the .js.)

And how unreadable is that compiled JavaScript? Let’s take a look. Here’s the compiled version of the CoffeeScript example from above:

Admittedly, this is a simple example. But, after having worked with some pretty complex CoffeeScript, I can honestly say that once you become familiar (which doesn’t take long), there aren’t any real surprises. Notice also the added optimizations you get for free: local variables are collected under one var statement, and hasOwnProperty is called via the prototype.

For more complex examples of CoffeeScript, look no further than the Batman source.

Workflow

I’m always worried when I come across tools that add a level of indirection to my workflow, but CoffeeScript has not been bad in this respect. The only added step to getting code shipped out is running the coffee command to watch for changes in my .coffee files:

We keep both the .coffee and .js files under git, so nothing gets lost. And since you still have .js files kicking around, any setup you have to minify your JavaScript shouldn’t need to change.

TL;DR

After three months of writing CoffeeScript, I can hands-down say that it’s a huge productivity booster. It helps you write more elegant and succinct code that is less susceptible to JavaScript gotchas.

Further Reading

This article also appears in the Shopify Technology Blog.

Categories
Uncategorized

Malcom Gladwell’s Take: Steve Jobs, Tweaker

Photo of Malcolm Gladwell speaking at PopTech 2008. Photo by Kris Krug.Not tweaker as in “amphetamine addict” or “hyperactive person” (like the South Park character Tweek Tweak), but as in “someone who takes something and makes it better.” That’s how Malcom Gladwell sees Steve Jobs in his right-on-the-money essay The Tweaker, which appears in the current issue of the New Yorker. In it, he states that Job’s gift wasn’t for invention, but editorial – or, in other words, tweaking.

“The visionary starts with a clean sheet of paper, and re-imagines the world,” writes Gladwell. “The tweaker inherits things as they are, and has to push and pull them toward some more nearly perfect solution.”

Here’s the key line, which immediately follows: “That is not a lesser task.”

The Tweaker, which could be described as an Apple-esque reduction of the Steve Jobs biogrpahy by Walter Isaacson, is exactly the sort of essay we’ve come to expect from Gladwell. At its heart is an interesting tale, but it’s his trademark touches that make it, from the way he can put together a narrative to the details that make a tale resonate in your mind to the little detours he takes into parallel stories, often culled from history, as a means of underlining his thesis.

In his essay, Gladwell explains Jobs’ genius by way of the industrial revolution and why it took place in Britain and not in nearby and equally-rich France and Germany: Britain had the tweakers – people who took the inventions that defined the age of industry and refactored them, either making them work or work better. They came up with what economists Ralf Meisenzahl and Joel Mokyr (whose article on the industrial revolution and tweakers Gladwell cites) call the “micro inventions necessary to make macro inventions highly productive and remunerative.”

MagSafe power adapter and jack

The MagSafe power connector: a great example of the lengths
to which Apple goes in their tweaking.

Gladwell puts forth the idea that Jobs is a tweaker in the same spirit as those Brits who refined the machinery of the industrial age and kicked it into high gear. Douglas Englebart may have given us the mouse and GUI, Altair the home computer, Audio Highway the MP3 player and IBM the smartphone, but it was Apple under Jobs that tweaked each of these devices to such heights that they became the gold standards.

It’s hard not to write about Steve Jobs’ creations without making some reference to his rival, Bill Gates. While the more hardcore Mac fans and even Jobs himself dismiss Gates as an copycat, Gladwell has a different take. He suggests that they’re two sides of the same coin. Both are tweakers, but one “resisted the romance of perfectionism”. Jobs saw Gates’ current role as philanthropist – something that isn’t all that popular in many corners of the relentlessly libertarian, cyberselfish world of Silicon Valley and apparently eschewed by Jobs  –  as something not requiring imagination, but Gladwell counters with this observation:

It’s true that Gates is now more interested in trying to eradicate malaria than in overseeing the next iteration of Word. But this is not evidence of a lack of imagination. Philanthropy on the scale that Gates practices it represents imagination at its grandest. In contrast, Jobs’s vision, brilliant and perfect as it was, was narrow.

Can a tweaker be an innovator? Dylan Love, in the title of his article in Business Insider says “no”, but I disagree. The Latin root of the word innovate is innovare, meaning “to renew of change”, and the dictionary definition of the word means both “to introduce something new” and to “make changes in anything established”. By tweaking established inventions and in turn redefining – or perhaps I should say tweaking – whole areas of technology, Jobs was most certainly an innovator.

This article also appears in the Shopify Technology Blog.

Categories
Uncategorized

It’s My Birthday!

"Interstate 44" sign

My 44th, to be precise. Party tonight, blog post on Accordion Guy tomorrow.

Categories
Uncategorized

It’s Time to Declare John McCarthy Day – How About Sunday, November 13th?

"Programming: You're Doing It Completely Wrong": Motivational poster with a photo of John McCarthy

Sunday, October 16th was declared Steve Jobs Day by California governor Jerry Brown, and that’s great. With Apple, NeXT and Pixar, he and the goodies he helped bring to us changed the way we work, live and play for the better. Jobs died on October 5th, and the world is a poorer place without him.

Sunday, October 30th was declared Dennis Ritchie Day by geek publisher and conference organizer supreme Tim O’Reilly, and that too is great. Perhaps laypeople won’t understand his contributions in the same way they understand Jobs’, the technologies and tools we use today are descendants, either direct or indirect, of his work on the C programming language and the Unix operating system. Ritchie died a week after Jobs, and the world is also a poorer place in his absence.

I think it’s high time to declare John McCarthy Day. “Uncle John” passed away on October 23rd, and as with Jobs and Ritchie, the world is once again a poorer place with him no longer around.

Uncle John’s Accomplishments

Illustration of ancient mathematicians from the cover of "Structure and Interpretation of Computer Programs"

McCarthy is the creator of the Lisp programming language. Even if you’ve never used Lisp (or, if you’re like me, took it in a course and swore off it for life), if you’re a programmer, the odds are good that you’ve benefited from an idea borrowed from it. That supposedly-newfangled functional programming you’ve been dabbling in lately? Lisp’s had that since Elvis was skinny. If-then-else? Uncle John invented that sucker for Lisp. Do you perform cool stuff on collections using IEnumerable’s methods in .NET, Ruby’s Enumerable mixin or Python’s list comprehensions? Lisp got there first; after all, its name comes from “list processing”.

"Khaaaan!": Painting of Ghengis Khan

Look at the most programming languages, and you’ll see Lisp’s fingerprints all over them. The obvious ones are its direct descendants, such as Clojure and Scheme, but like the very prolific Genghis Khan – believed to be the ancestor of 1 in every 200 men today – its DNA is everywhere. Haskell and OCaml (and F#, which is OCaml spoken with a Redmond accent) are obvious candidates. There are Lisp-isms all over Python and Ruby. Scratch beneath JavaScript’s clunky hacked-together-in-ten-days syntax and you’ll see Lisp-like stuff in its innards. Even Java-the-language and C# are getting in on the act, with all sorts of Lisp-inspired functional programming stuff getting tacked onto them.

Old black and white photo of 1950s garbage collectors

Every time you don’t have to worry about freeing memory that you had to malloc, you owe a debt of gratitude to Uncle John. He invented garbage collection, and he did it ages ago – in the same year Fidel Castro took over Cuba. (We had computers back then?)

Time-sharing, and later software-as-a-service or platform-as-a-service? He was the first guy to put forth the concept in public.

Diagram showing how a space fountain works

And just for extra nerd points, Uncle John was one of the people who came up with the idea of the space fountain.

Let’s Give Him a Day: Sunday, November 13th

I don’t have the convening power of the Governor of California to make an official Steve Jobs Day. I don’t have the clout of Tim O’Reilly, who was able to declare an unofficial Dennis Ritchie Day. But I’d like to use whatever pull I have and your help to make Sunday, November 13th the unofficial day in which we mark the life and achievements of John McCarthy. We’ve all benefited from his work, and I think it’s only fair to pay him back with some tribute.

Please help by spreading the word! Let’s use the #JohnMcCarthyDay tag on Twitter and Google+.

This article also appears in the Shopify Technology Blog.

Categories
Uncategorized

Shopify Hackfest in Ottawa – Saturday, November 19th

hackfest 01

Hey, developers from Ottawa and parts nearby!

  • Are you interested in building innovative, novel apps on the Shopify ecommerce platform?
  • Have you got “the skillz to pay the billz”?
  • Are you available on Saturday, November 19th?

If the answer to that last question is “Maybe!”, we’d love to see you at Shopify’s Ottawa Hackfest taking place that day.

We’re celebrating our recent round of new funding. As my coworker David Underwood puts it:

Shopify is throwing an all day hack event the like of which has been seen several times before. That doesn’t make it any less fun though, I promise.

With a stunning endorsement like that, how can you possibly choose to miss this event?

hackfest 02

When and Where

  • The Date: Saturday, November 19th
  • The Time: 9:30 a.m. – 6:00 p.m.
  • The Place: Shopify’s Offices, 61A York Street, in the heart of ByWard Market


View Larger Map

So How Does This Work?

Everyone shows up in the morning ready to start coding at 10 a.m.. We provide you with food, drink, and assistance throughout the day as you build the best Shopify app you can. At 5 p.m., work stops and everyone with a working demo presents what they’ve done. We pick our favourite projects and award fabulous prizes for them. Then everyone retires to a nearby pub and parties into the night.

Who Will Be There?

Shopifolk (Shopify employees) will be on hand to provide assistance throughout the day. And of course, your teammates/competitors will be there too.

Why Are You Doing This?

Because we can! We have to spend that $15 million we raised somehow, you know. We’re also always on the lookout for new talent to join the Shopify team, so don’t be surprised if someone takes a shine to you.

What Will Be Provided?

  • Breakfast
  • Lunch
  • Video games (Street Fighter 4!)
  • Workspaces with power and wireless internet
  • Fabulous prizes (to be announced)!

What Should I bring?

  • Laptop
  • Power supply
  • Your enormous intellect
  • Beverage container (e.g. travel mug)

What Should I Build?

Anything you want! The only restrictions are that it has to use our API and has to work for a demo at the end of the day. If you don’t have an idea or a team to work with, we’ll match you up with people/projects when you arrive. You can also have a look at our app wishlist if you’re stumped and want a head-start.

Ok, I’m Convinced. Where Do I Sign Up?

Go here to register. Spaces are limited, so don’t dawdle. We’re looking forward to seeing you there!

Categories
Uncategorized

Pixel Union’s Beautiful Shopify Themes

pixel union - beautiful themes

pixel union“Pixel Union” is synonymous with “beautiful Tumblr themes”. Go take a look at their site and try out the demos of themes like Sticks and Stones with its hand-drawn charm, the retro-urban New Yorker theme or the simple but powerful grid of the Insider theme. Pixel Union themes turn Tumblrs into gorgeous sites that make you want to visit over and over again.

That same gorgeousness that goes into Pixel Union’s Tumblr themes can now go into your Shopify shop. Starting today, you can get your hands on Pixel Union’s new Shopify Themes and turn your shop into a place that customers will want to visit over and over again.

You’ll find the same magic that goes into Pixel Union’s Tumblr themes in their new Shopify themes: Carleton, Jitensha, Technophile and Vintage. They all come with a boatload of features:

  • The same beauty and craftsmanship that goes into Pixel Union’s Tumblr themes, for both your shop’s catalogs as well as its blogs
  • Lots of customizability to make the theme fit your shop: logo, fonts and colors
  • Ties to the big social media services so you can harness word-of-mouth for your shop
  • MailChimp integration so it’s simple to set up an email newsletter campaign to reach out to your customers
  • Pixel Union’s speedy, expert and personalized support

Here’s a closer look at Pixel Union’s Shopify themes…

Carleton Classic and Modern

The Carleton theme is reminiscent of those thick, high-end clothing catalogs and comes packaged with two similar but distinct “flavors”. First, there’s the traditional, clean Classic:

carleton classic theme

Carleton Classic: See its page in the Shopify Theme Store | View the demo

…and there’s the contemporary, bold Modern:

carleton modern theme

Carleton Modern: See its page in the Shopify Theme Store | View the demo

Jitensha

Jitensha takes its inspiration from Japanese culture: the word means “bicycle” in Japanese, and the theme takes its design cues from Japanese minimalism.

jitensha theme

Jitensha: See its page in the Shopify Theme Store | View the demo

Technophile Dark and Light

If your shop is about gadgets and gear, you should check out Technophile. It pays homage to Apple’s legendary interface design and comes packaged with two styles. There’s Dark

technophile dark theme

Technophile Dark: See its page in the Shopify Theme Store | View the demo

…and if you prefer the white iPhone, there’s the Light style:

technophile light theme

Technophile Light: See its page in the Shopify Theme Store | View the demo

Vintage Theme

If you have a shop that specializes in hand-made, artisanal products, you should check out Vintage Theme, with its letterpress-on-high-grade-paper look and boutique “feel”.

vintage theme

Vintage: See its page in the Shopify Theme store | View the demo

See Pixel Union’s Themes and More at the Theme Store!

theme store pixel union

Shopify gives you lots of options. If you’ve got the time and know-how, you can create a theme that’s your very own. You can also find the right “look and feel” your shop with a free or paid theme at the Theme Store, whether it’s one created by Pixel Union or any other of the wide range created by shopowners and designers.

We’re very happy to welcome Pixel Union to the Theme Store, and we think you’ll love their themes!

This article also appears in the Shopify Blog.

Categories
Uncategorized

The First “Grand Theft Auto V” Trailer

The first trailer for Grand Theft Auto V was released today at noon. You’re not going to find out much about the game from it, other than:

  • It takes place in what seems to be present-day “Los Santos”, the analogue for Los Angeles in the world of Grand Theft Auto. Los Santos is one of the three cities in the sprawling Grand Theft Auto: San Andreas.
  • The plot seems to involve a guy trying to start a new life in a new city, not unlike Grand Theft Auto IV’s Niko Bellic or Grand Theft Auto: Vice City’s Tommy Vercetti. I think it’s safe to assume that his plans get waylaid and through a series of bizarre circumstances and friends and associates with poor life-planning skills (no shortage of such types in the world of GTA), our hero lands himself in a whole world of trouble. It would also be safe to assume that he gets out of said trouble by causing a lot of mayhem.
  • The voice-over in the trailer sounds a helluva lot like Ray Liotta, who played Tommy in Grand Theft Auto: Vice City.

As with most of Rockstar’s trailers, this one’s all cinematics and mise en scene. There’s no indication of what the gameplay is like, whether you’re playing the story or in multiplayer mode. There’s also no indication of what platforms it’s coming out for (although it’s safe to assume that Playstation 3 and Xbox 360 will be supported, with a PC version to follow later) nor when the game will be released (I assume sometime in 2012).