Comment Comment by jlebar My favorite (not actually horrible) switch statement trick:Instead of string x; switch (y) { case 0: x = "foo"; break; case 1: x = "bar"; break; } try an IIFE! string x = [&] { case(y) { case 0: return "foo"; case 1: return "bar"; } }(); Once you get used to reading it, there are a bunch of advantages. Among them, you can't forget a "break", and you can't forget to assign into `x`. parent jlebar 6 years ago
Instead of
try an IIFE! Once you get used to reading it, there are a bunch of advantages. Among them, you can't forget a "break", and you can't forget to assign into `x`.