4 ms·
The most common reason I would have variable shadowing in my code is that I'm dealing with optional values. e.g. (Scala) def greeting(name: Option[String]):
by philipkglass 6y ago
The most common reason I would have variable shadowing in my code is that I'm dealing with optional values.
e.g. (Scala)
def greeting(name: Option[String]): String =
name match {
case Some(name) => s"Hello $name"
case None => "Welcome, stranger"
}
I could call the input parameter something like optionalName or maybeName to avoid shadowing but I dislike repeating type information in the variable name.