Comment

Comment by Zardoz84

Just today, I was talking with a team mate about this. We had some pice of code that it's like this :

    public boolean foo() {
      

      if (!this.doesSomethingWithA()) {
        return false;
      }
      
      if (!this.doesSomethingWithB()) {
        return false;
      }
      
      if (!this.fooBar2000.isEmpty()) {
        return false;
      }
      
      if (!this.anotherLongAttribute) {
        return false;
      }
      
      if (!this.anotherMethod()) {
        return false;
      }
      
      return true;
   }
We try to replace to a "one liner" return !A && !B && !C ... Well, the expression was very long and we noted that was more hard to read that the multiple if's. I suggested split the one liner expression on multiples lines doing something like this :

    return !this.doesSomethingWithA()
        && !this.doesSomethingWithB()
        && !this.fooBar2000.isEmpty()
        && !this.anotherLongAttribute
        && !this.anotherMethod();
However, the code formatter (eclipse), changes every time it to the hard to read one liner expression. So we ended using the multiple if's.
parent Zardoz84 8 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton