4 ms·
I think the goal was if (a==='80' || (b==='443'&&http===false)) {...}
by cowsandmilk 13y ago
I think the goal was
if (a==='80' || (b==='443'&&http===false)) {...}
- ssharp 13y agoI think you're right, but it's funny that both the code and the written explanation do not make that clear. Missing parenthesis in one case and missing comma in the other. I feel like I tend to use parenthesis when they are not required, but I err on the side of caution and I think it makes things more readable.
- blt 13y agoI use a lot of unneeded parentheses. Makes the intent of the program clear. If the expression gets ugly, factor out subexpressions into boolean variables. If you are depending on short circuiting to avoid computing costly subexpresions, make the dependency explicit with a nested `if`. I had a thought the other day: Complicated code should look complicated. Don't try to hide your convoluted logic. In the end, someone will have to mentally unpack it into the multi-line verbose version to understand it anyway.
- methodover 13y agoThat's an excellent thought. I feel like programmers too often try to make something complicated "pretty" -- but really this just usually has the effect of making it that much more difficult to understand.
- mox1 13y agoEither way, it's called "Boolean Logic" and as far as I knew every Computer Scientist had to take this class in college...Not sure how you could get a job as a programmer without understanding that...