Conditional logging with minimal cyclomatic complexity

前端 未结 12 1839
情歌与酒
情歌与酒 2020-11-27 10:58

After reading \"What’s your/a good limit for cyclomatic complexity?\", I realize many of my colleagues were quite annoyed with this new QA policy on our project: no more 10

12条回答
  •  有刺的猬
    2020-11-27 11:15


    (source: scala-lang.org)

    Scala has a annontation @elidable() that allows you to remove methods with a compiler flag.

    With the scala REPL:

    C:>scala

    Welcome to Scala version 2.8.0.final (Java HotSpot(TM) 64-Bit Server VM, Java 1. 6.0_16). Type in expressions to have them evaluated. Type :help for more information.

    scala> import scala.annotation.elidable import scala.annotation.elidable

    scala> import scala.annotation.elidable._ import scala.annotation.elidable._

    scala> @elidable(FINE) def logDebug(arg :String) = println(arg)

    logDebug: (arg: String)Unit

    scala> logDebug("testing")

    scala>

    With elide-beloset

    C:>scala -Xelide-below 0

    Welcome to Scala version 2.8.0.final (Java HotSpot(TM) 64-Bit Server VM, Java 1. 6.0_16). Type in expressions to have them evaluated. Type :help for more information.

    scala> import scala.annotation.elidable import scala.annotation.elidable

    scala> import scala.annotation.elidable._ import scala.annotation.elidable._

    scala> @elidable(FINE) def logDebug(arg :String) = println(arg)

    logDebug: (arg: String)Unit

    scala> logDebug("testing")

    testing

    scala>

    See also Scala assert definition

提交回复
热议问题