One example of how to avoid using `var` fields in Scala

As one note and example of how to avoid using var fields in Scala, I initially wrote this code:

var numDaysToProcess = 0

if (args.length != 0) {
    numDaysToProcess = args(0).toInt

After I looked at that code for a moment I realized that I could write it without a var like this instead:

val numDaysToProcess =
    if (args.length == 0) {
    } else {

That’s a simple example of one situation where you can easily avoid using a var field in Scala. I’ll share more examples as they come up.