开发者

Need help with formatting logical functions -- parentheses

I have a while loop whose condition is a conjunction of two statements, one of which contains nested ORs. I couldn't find any standard method of organizing the statements around the operators or using parentheses. Keep in mind that the actual statements are longer than 'a', for example 'Math.Pow(double,exponent)*Math.Pow(Math.SQRT(double)),exponent)', otherwise the second version would be the obvious choice. Any suggestions on the proper way to write this so another programmer would find it easiest to read?

while
                        (
                            (
                                (a > b)
                                ||
                       开发者_StackOverflow中文版         (
                                    (
                                        (a > d)
                                        ||
                                        (
                                            (p < q)
                                            ||
                                            (r < s)
                                        )
                                    )
                                )
                            )
                            && t < y
                        )
                            {
                                g = g + 0.25;
                            }

OR

while (((a > b) || (((a > d) || ((p < q) || (r < s))))) && t < y)
      {
          g = g + 0.25;
      }


Put them into methods with speaking names and use those methods in your while loop. Everything else is unmaintainable!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜