Skip to content

Instantly share code, notes, and snippets.

@tmcw
Last active June 3, 2016 19:06
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/91ec9e7f44695747ecbf to your computer and use it in GitHub Desktop.
Save tmcw/91ec9e7f44695747ecbf to your computer and use it in GitHub Desktop.
On Code Style

You might be expecting a long rant on why code style matters and tabs are sinful in your JavaScript code. This isn't that, thankfully.

If you've been snooping around ★★REDACTED★★★, you may have noticed that, in contrast to our other projects, it uses 2 spaces for indentation instead of 4. This was a decision Eden, Lauren, and I made, given that we kind of just started out that way, and that two-tab indentation makes our somewhat absurd functional chains easier on the eyes and the widths.

This also allows us to say that we simply use the Airbnb code style rather than saying we use it with a carveout as we've written for mapbox.js and iD.

This isn't an announcement that we're switching to 2 spaces, but rather a statement of how we treat code style and deal with these differences:

Use one code style for your whole project, and be consistent

Try to be consistent so that reading your code is like reading a novel, not a weird postmodern art novel.

image

When switching around projects, follow the surrounding code style

Just like this fun stock image, don't ever wear shorts like that and especially not at weddings.

Things can help you with this:

Changing code styles for an existing project is usually more annoyance than it's worth

For this reason we don't pester people to convert all their tabs to spaces or vice versa or whatever on projects that work pretty darn well already.


tl;dr: the 'mapbox code style' won't come as an order from high or even be 'the mapbox code style', but it's important to choose one for your projects, follow the 'when in rome' rule, and make sure projects are internally consistent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment