3 ms·
My $0.02: Unnamed variables just seem to add confusion and inconsistency. Inconsistency like this in Scala and Perl make it harder to learn and offer little val
by cosmotic 4y ago
My $0.02: Unnamed variables just seem to add confusion and inconsistency. Inconsistency like this in Scala and Perl make it harder to learn and offer little value.
- speed_spread 4y agoThey allow to give out warnings on unused variables. If the warning is unwarranted and you really want to discard the value, you use _. It helps prevent mistakes by giving a hint on the intent of the programmer.
- cosmotic 4y agoI find it exceptionally rare to want not to use a variable that way, it's usually something you want to make harder to ignore, not easier. In the case you really do want to ignore, there are annotations to prevent the warning.
- bobbylarrybobby 4y agoThe underscore is the annotation
- cosmotic 4y agoI understand that; the problem is that it makes it so easy to bypass the safety net the warning is intended to provide. For example, not logging an exception; You'd have to be really intentional to block the warning with an actual annotation, but using an underscore would be so easy you'd just fall into a pattern of always commenting those out. It's better to have a line of code screaming "I'm doing something that looks wrong here but really it's okay" instead of "_".