3 ms·
It's pretty common in languages with pattern matching to use underscore as a catch-all (ML family, Haskell, etc.). I'm not sure how the underscore is a code sme
by johncolanduoni 10y ago
It's pretty common in languages with pattern matching to use underscore as a catch-all (ML family, Haskell, etc.). I'm not sure how the underscore is a code smell; if you want wildcard patterns without throwing a bunch of unused variables into scope (which can definitely lead to non-obvious bugs), you have to use some symbol.
- redleggedfrog 10y agoMostly like if I submitted some code for review and peppered it with underscores because "I don't care about those variables" I'm pretty sure it'd come back to me with a remark about starting to care. At the point your writing code you don't care about, something might be wrong.
- johncolanduoni 10y agoDo you ever write an if statement where you don't check one of the fields of an object, or a method call where you ignore a return value? If so, how is this any different?
- bschwindHN 10y agoWhen working with an object, you don't always care about all of its properties. If it's packed in a certain way (tuple, Optional wrapper, etc.) that is easy to unpack with destructuring, then you might use an underscore to say "this is how it's structured, but I don't care about the particular value it has so please don't bind it to a variable." If you bound it to a variable and didn't use it, it'd be the same as declaring an unused variable.