代码设计之 Guard clause

  • Post author:
  • Post category:tech
  • Post comments:0 Comments

大家有没有看过这样的代码?就是一个方法里面,整个就是一个if语句。然后这个if语句非常长长长长。。。一屏都放不下,你都不知道这个if语句会在哪里结束。 fun runRule() if (rulesEnabled) { var maxConsecutiveCount = 0 var currentConsecutiveCount = 0 var previousReceiver = "" expression.children.forEach { if (it is KtBinaryExpression) { val currentReceiver = getReceiver(it) if…

Continue Reading代码设计之 Guard clause