When to use the _ Underscore Argument? How do you judge names in a library? Naming things” is one binary option vs vanilla those traditionally “hard problems” in software engineering. The Scala programming language gives you more tools than most languages do to manage names: apart from picking alphanumeric names of arbitrary length, you can also name things using operators, or in many cases not names things at all using language features like apply or the _ placeholder parameter.
However, the fact that code ends up “too concise” is itself one of the most common complaints leveled against the Scala programming language. How can we pick the right balance of verbosity and conciseness, at the right times, to ensure future maintainers of our software do not end up hating us? This post is part of a series, following an earlier post Strategic Scala Style: Principle of Least Power. Like that post, this assumes you are already proficient in the Scala programming language: you are already familiar with most of its features, and how to use them. When can you use short names? When should you use short names?
Similar to the earlier post, this covers a wide-range of topics, and is focused on the “Vanilla Scala” use case. It’s unlikely that everyone will agree with every point, especially those using specialized libraries, but hopefully people will find it broadly agreeable and be able to use it as a framework to insert whatever team-specific guidelines or conventions they prefer. This isn’t as flippant as it at first seems: knowing something isn’t all-or-nothing, and how much you want to know depends on a great many different factors! Nevertheless, while subjective, this isn’t a hand-wavy topic at all.
There are concrete things that a programmer would already know, and concrete things they would want to know. Things that are especially dangerous, whether due to correctness, security, performance, etc. This is not comprehensive, but it should give a sense of the things that people do or do-not want to see. While not totally concrete, this list is already pretty actionable! Who you think the future programmers are going to be?