vesoft-inc / nebula-algorithm

Nebula-Algorithm is a Spark Application based on GraphX, which enables state of art Graph Algorithms to run on top of NebulaGraph and write back results to NebulaGraph.
71 stars 39 forks source link

Why do we need `var`? #87

Open jxnu-liguobin opened 1 year ago

jxnu-liguobin commented 1 year ago

I am confused with these codes.

What are the requirements for using var and it needs to be public? Every time I call method getLPAConfig, var changes, so this var is unreliable as "static", why are we doing this?

case class LPAConfig(maxIter: Int, encodeId: Boolean = false)

object LPAConfig {
  var maxIter: Int      = _
  var encodeId: Boolean = false

  def getLPAConfig(configs: Configs): LPAConfig = {
    val lpaConfig = configs.algorithmConfig.map

    maxIter = lpaConfig("algorithm.labelpropagation.maxIter").toInt
    encodeId = ConfigUtil.getOrElseBoolean(lpaConfig, "algorithm.labelpropagation.encodeId", false)
    LPAConfig(maxIter, encodeId)
  }
}
Nicole00 commented 1 year ago

the original intention is to set default value for some configs. But the default value is set in GetOrElse function, so the var looks no useless. we can update it as

     val maxIter = lpaConfig("algorithm.labelpropagation.maxIter").toInt
    val encodeId = ConfigUtil.getOrElseBoolean(lpaConfig, "algorithm.labelpropagation.encodeId", false)
    LPAConfig(maxIter, encodeId)