Skip to content

Instantly share code, notes, and snippets.

@IMSoP

IMSoP/braces.cc Secret

Last active May 26, 2017 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IMSoP/90bc1e9e2c56d8314413d7347e76532a to your computer and use it in GitHub Desktop.
Save IMSoP/90bc1e9e2c56d8314413d7347e76532a to your computer and use it in GitHub Desktop.
// Braces would look like this (give or take a few new lines :P):
if (angle <= 30 || angle >= 330) {
return Car::EDirection::RIGHT;
} else if (angle <= 60) {
return Car::EDirection::UP_RIGHT;
} else if (angle <= 120) {
return Car::EDirection::UP;
} else if (angle <= 150) {
return Car::EDirection::UP_LEFT;
} else if (angle <= 210) {
return Car::EDirection::LEFT;
} else if (angle <= 240) {
return Car::EDirection::DOWN_LEFT;
} else if (angle <= 300) {
return Car::EDirection::DOWN;
} else if (angle <= 330) {
return Car::EDirection::DOWN_RIGHT;
}
// Not this, which would indeed by horrible, but completely unnecessary:
if (angle <= 30 || angle >= 330) {
return Car::EDirection::RIGHT;
} else {
if (angle <= 60) {
return Car::EDirection::UP_RIGHT;
} else {
if (angle <= 120) {
return Car::EDirection::UP;
} else {
if (angle <= 150) {
return Car::EDirection::UP_LEFT;
} else {
if (angle <= 210) {
return Car::EDirection::LEFT;
} else {
if (angle <= 240) {
return Car::EDirection::DOWN_LEFT;
} else {
if (angle <= 300) {
return Car::EDirection::DOWN;
} else {
if (angle <= 330) {
return Car::EDirection::DOWN_RIGHT;
}
}
}
}
}
}
}
}
// If you didn't use else, you'd have exactly the same braces and nesting as my first example
// (but might have different new lines, depending on your agreed style)
if (angle <= 30 || angle >= 330) {
return Car::EDirection::RIGHT;
}
if (angle <= 60) {
return Car::EDirection::UP_RIGHT;
}
if (angle <= 120) {
return Car::EDirection::UP;
}
if (angle <= 150) {
return Car::EDirection::UP_LEFT;
}
if (angle <= 210) {
return Car::EDirection::LEFT;
}
if (angle <= 240) {
return Car::EDirection::DOWN_LEFT;
}
if (angle <= 300) {
return Car::EDirection::DOWN;
}
if (angle <= 330) {
return Car::EDirection::DOWN_RIGHT;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment