Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why do we need var? #87

Open
jxnu-liguobin opened this issue Sep 12, 2023 · 1 comment
Open

Why do we need var? #87

jxnu-liguobin opened this issue Sep 12, 2023 · 1 comment
Labels

Comments

@jxnu-liguobin
Copy link
Contributor

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)
  }
}
@jxnu-liguobin jxnu-liguobin changed the title Why can't we have an immutable configuration? Why do we need var? Sep 12, 2023
@Nicole00
Copy link
Contributor

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)

@QingZ11 QingZ11 added the type/feature req Type: feature request label Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

4 participants