styleguides icon indicating copy to clipboard operation
styleguides copied to clipboard

Wrong example for "Don't chain assignments"?

Open ConjuringCoffee opened this issue 2 years ago • 2 comments

Chapter "Don't chain assignments" currently has the following two code snippets:

var2 = var3.
var1 = var3.
var1 = xsdbool( var2 = var3 ).

Can someone please explain to me what the xsdbool code snippet has to do with the topic? It doesn't make any sense to me to assign the boolean abap_true to var1. It has the value of var2 and var3, but not necessarily a boolean and it is not necessarily true.

ConjuringCoffee avatar Mar 30 '22 13:03 ConjuringCoffee

It's about ABAP lacking the syntax distinction between assignment (=) and comparison (=). JavaScript assigns with = and compares with == or ===.

The ABAP statement a = b = c. thus looks ambiguous, and if we intend a = ( b == c ) then we should use xsdbool.

pokrakam avatar Mar 30 '22 14:03 pokrakam

OK, thanks for the explanation. I believe this information could be better conveyed in the guideline. I have proposed a change to this section.

ConjuringCoffee avatar Mar 30 '22 14:03 ConjuringCoffee

This issue is resolved by 22a5818 into SAP:main on 25 Jul

rdibbern avatar Oct 17 '22 14:10 rdibbern