buildo / nozzle

MIT License
0 stars 1 forks source link

Config case class should be an object #9

Closed calippo closed 8 years ago

calippo commented 8 years ago

Configs are currently written as:

private[this] case class LocalConfig(beAwesome: Boolean)

private[this] val localConfig = config.get { conf =>
  LocalConfig(conf.getBoolean("beAwesome"))
}

why is LocalConfig a case class? I think it should be a singleton. I don't see situations when we're going to reuse that class (reusing that case class is probably a mistake). I think we should use object instead of case class for config as best practice.

private[this] object localConfig { 
  val beAwsome: Boolean = config.get { conf => conf.getBoolean("beAwsome") } 
}

the only problem I see is that it gets kind of cumbersome for more variables

private[this] object localConfig { 
  val (beAwsome: Boolean, beCumbersome: Boolean) = config.get { conf =>
    (conf.getBoolean("beAwsome") ,
    conf.getBoolean("beCumbersome")
  } 
}

vs

private[this] case class LocalConfig(beAwesome: Boolean, beCumbersome: Boolean)

private[this] val localConfig = config.get { conf =>
  LocalConfig(
    conf.getBoolean("beAwesome"),
    conf.getBoolean("beCumbersome")
  )
}
calippo commented 8 years ago

Discussed orally with andrea: case class is there to explicity show the used parameters.

calippo commented 8 years ago

Work has been done about this in branch 1.0-master. Closing it for the moment.