Skip to content

Instantly share code, notes, and snippets.

@icholy
Last active August 29, 2015 14:06
Show Gist options
  • Save icholy/362153a496848dbc8673 to your computer and use it in GitHub Desktop.
Save icholy/362153a496848dbc8673 to your computer and use it in GitHub Desktop.

I prefer this

var distance = metersToNauticalMiles(
  utils.getDistance(
    utils.toPoint(coordinates.get(0)),
    utils.toPoint(coordinates.get(1))
  )
);

Instead of this

var distance = metersToNauticalMiles(
    utils.getDistance(
        utils.toPoint(coordinates.get(0)),
        utils.toPoint(coordinates.get(1))));

I'll do this if I need to reuse the intermediate values

var point1   = utils.toPoint(coordinates.get(0)),
    point2   = utils.toPoint(coordinates.get(1)),
    meters   = utils.getDistance(point1, point2),
    distance = metersToNauticalMiles(meters);

This is ok

var point1 = utils.toPoint(coordinates.get(0));
var point2 = utils.toPoint(coordinates.get(1));
var meters = utils.getDistance(point1, point2);
var distance = metersToNauticalMiles(meters);

I don't like this at all

var distance = metersToNauticalMiles(utils.getDistance(utils.toPoint(coordinates.get(0)), utils.toPoint(coordinates.get(1))));

Even worse

var distance = metersToNauticalMiles(
    utils.getDistance.apply(utils,
        [0, 1].map(coordinates.get.bind(coordinates))
              .map(utils.toPoint.bind(utils))))

Are there other styles I'm missing?

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