Skip to main content
copy-edited
Source Link
Deduplicator
  • 9.2k
  • 5
  • 33
  • 53

Should I use parentheses in logical statements even where not necessaryfully parenthesize expressions or rely on precedence rules?

Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedentprecedence than OR. I could write this line of code:

If (a AND b) OR (c AND d) Then ...

But really, that's equivalent to:

If a AND b OR c AND d Then ...

Are there anycompelling arguments in forfavor or against including the extraneous parentheses? Does
Does practical experience suggest that it is worth including them forsignificantly improves readability? Or
Or is itwanting them a sign that a developer really needs to really sit down and become confidentconversant in the basics of their language?

Should I use parentheses in logical statements even where not necessary?

Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code:

If (a AND b) OR (c AND d) Then ...

But really, that's equivalent to:

If a AND b OR c AND d Then ...

Are there any arguments in for or against including the extraneous parentheses? Does practical experience suggest that it is worth including them for readability? Or is it a sign that a developer needs to really sit down and become confident in the basics of their language?

Should I fully parenthesize expressions or rely on precedence rules?

Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedence than OR. I could write this line of code:

If (a AND b) OR (c AND d) Then ...

But really, that's equivalent to:

If a AND b OR c AND d Then ...

Are there compelling arguments in favor or against including the extraneous parentheses?
Does practical experience suggest that including them significantly improves readability?
Or is wanting them a sign that a developer really needs to sit down and become conversant in the basics of their language?

Question Protected by gnat
Post Made Community Wiki by Arnab
Tweeted twitter.com/#!/StackProgrammer/status/347264537302552576
spelling cleanup
Source Link
gnat
  • 20.5k
  • 29
  • 117
  • 308

Should I use paranthesesparentheses in logical statements even where not necessary?

Let's say I have a boolean conditoncondition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code:

If (a AND b) OR (c AND d) Then ...

But really, that's equivalent to:

If a AND b OR c AND d Then ...

Are there any arguments in for or against including the extraneous paranthesesparentheses? Does practical experience suggest that it is worth including them for readability? Or is it a sign that a developer needs to really sit down and become confident in the basics of their langaugelanguage?

Should I use parantheses in logical statements even where not necessary?

Let's say I have a boolean conditon a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code:

If (a AND b) OR (c AND d) Then ...

But really, that's equivalent to:

If a AND b OR c AND d Then ...

Are there any arguments in for or against including the extraneous parantheses? Does practical experience suggest that it is worth including them for readability? Or is it a sign that a developer needs to really sit down and become confident in the basics of their langauge?

Should I use parentheses in logical statements even where not necessary?

Let's say I have a boolean condition a AND b OR c AND d and I'm using a language where AND has a higher order of operation precedent than OR. I could write this line of code:

If (a AND b) OR (c AND d) Then ...

But really, that's equivalent to:

If a AND b OR c AND d Then ...

Are there any arguments in for or against including the extraneous parentheses? Does practical experience suggest that it is worth including them for readability? Or is it a sign that a developer needs to really sit down and become confident in the basics of their language?

Fixed grammar error in title
Link
Jeff B
  • 858
  • 2
  • 9
  • 14

Should I use parantheses in logical statementstatements even where not necessary?

Source Link
Jeff B
  • 858
  • 2
  • 9
  • 14
Loading