Welcome to my little CS trivia series. Every week I post a new trivia piece.
Today's question is...
The spaceship operator looks like
This logical operator checks a statement three fold:
if a < b, return -1 if a = b, return 0 if a > b, return 1 if a and b are not comparable return nil
Therefore, instead of writing a few else/if statements, you can keep it short by just using the spaceship operator.
In the Google Group devoted to Dart Committee Meeting, Perl expert Randal L. Schwartz mentioned that he had coined the name "spaceship operator":
In writing, you can just get away with saying "the <=> operator", but
when teaching, I got really tired of saying "the less-than, equal,
greater-than operator", so I noticed it reminded me of the spaceship in
an old HP BASIC "star trek" game, so I started using that, and it caught
on, even finding its way into an error message, and thus becoming