178
PhiMa
6y

I always put redundant parentheses in formula like ((b - a) / 2) + a because I just don't trust the compiler.

Comments
  • 21
    I feel you bruh 😂
  • 22
    I do this on my calculator all the time.

    Better safe than sorry lol
  • 19
    Those aren’t redundant though
  • 2
    I do that too ! But then I always end up having imbalance x)
  • 4
    @inaba one pair is
  • 17
    I don't trust the compiler, and I don't trust the future devs.
  • 14
    float cal_y = ((float)(y2-y1)/(float)(x2-x1))*(float)(x) - ((float)(y2-y1)/(float)(x2-x1))*(float)x1 + (float)y1;

    This shows how much i trust my compiler.
  • 6
    @ay2306 Can't be entirely sure what comes out of the multiplications and divisions are floats. Also the final sums and differences aren't guarenteed to be a float either. Fixed it for you!

    float cal_y = (float)((float)((float)((float)((float)y2-(float)y1)/(float)(x2-x1))*(float)(x)) - (float)(((float)(y2-y1)/(float)((float)x2-(float)x1))*(float)x1) + (float)y1);
  • 1
    @inaba isn't division and addition of two floats also float? Why type comversion even beyond that?
  • 0
  • 1
    I think it makes it more readable as other people have already pointed out.
  • 4
    You could try LISP - then you'll be so fed up with parentheses that you'll naturally hate them.
  • 0
  • 0
    its already fast to write with a decent text editor tho. Bothering whether to write or not takes much more time than just inserting these parantheses.
  • 3
    @Fast-Nop Lithper here and parenthetheth are thill amathing to me. I love them!!
  • 1
    It makes compiler lazy
  • 2
    The preprocessor macros in C justify this paranoia

    #defne SQUARE(x) x*x

    int a = 3;
    int y = SQUARE(a+2);
    // y = 3+2*3+2 = 11
    // instead of (3+2)*(3+2)
  • 1
    @Batburger those are not "redundant" parenthesis, just explicit.

    redundant parenthesis are like these: ((a + b)) / 2.

    I don't know if @inaba was talking about that fact, or about the fact that putting explicit parenthesis is better, since a lot of people seems to forget/ignore the operand priority rules.
    As someone said, better be safe than sorry (for a misunderstanding)
  • 1
    @taglia No @Batburger is right. The order of operations dictate that the outer most parenthesis are redundant

    ((b - a) / 2) + a => (b - a) / 2 + a

    In postfix both expressions would give the same as well, which is

    b a - 2 / a +
  • 0
    @inaba had to check the full definition of redundant. For me was just "exact copy", that's why I said "explicit, not redundant".
    My bad.
    Btw, I didn't argue the logic, just the term. (even if I made a mistake 😂)
  • 0
    Actually this can be simplified as:
    (3a - b) / 2

    I'm sorry, I like math...
  • 0
    When it comes to non essential parantheses, IMHO, readability is the most important factor... Do they help with reading the code? Jus add them
Add Comment