Hacker News new | ask | show | jobs
by convivialdingo 579 days ago
I guarantee that piece of code has a comment like

  /* This should never happen */
  if (waypoints.matchcount > 2) {
3 comments

Possibly even just

    waypoint = waypointsMatches[0]
Without even mentioning that waypointsMatches might have multiple elements.

This is why I always consider [0] to be a code smell. It doesn't have a name afaik, but it should.

Silently ignoring conditions where there are multiple or zero elements?
Race condition?
From the text it sounds like it looked up if a code was in the flight plan and at which position it was in the plan. It never looked up two codes or assumed there code only be one, just comparing how the plan was filed.

I'm sure there'd be a better way to handle this, but it sounds to me like the system failed in a graceful way and acted as specified.

Don't you mean > 1 ?