Created
May 29, 2020 08:01
-
-
Save tonymorris/730e4984cff0ee20e5e74bcf39621929 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Which of f or g are more readable, and if possible, why? | |
def f(x: Seq[Int]): Int = | |
x.toList match { | |
case Nil => 99 | |
case lst => lst.sum | |
} | |
def g(x: Seq[Int]): Int = | |
x.toList match { | |
case Nil => 99 | |
case lst@(_::_) => lst.sum | |
} | |
I agree less noise the better, hence the answer is g
.
Yeah, I didn't take overlapping into account. It's subtly deceptive.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The less noise the better, so the answer is
f
.For what "readability" arguments are concerned, the real question is often how much is the reader familiar.