26.06.2007, 08:00 | #1 |
Участник
|
Issues concerning X++: Operator precedence of && and ||
Источник: http://blogs.msdn.com/x/archive/2007...ce-of-and.aspx
============== There is an issue concerning logical expressions (i.e. expressions that are evaluated to true or false, a.k.a Boolean expressions) in X++. The essence of this issue is that the X++ language is not aligned with other languages in its precedence of the logical and (&&) and or (||) operators. In X++ these two operators have the same precedence, whereas in other languages && is higher priority than ||. The issue here is that programmers might unexpectedly create bugs for themselves when writing complex Boolean expression involving these two operators. For instance: A || B && C (where A, B and C are Boolean subexpressions) will be evaluated as (A||B) && C in X++, but as A || (B && C) in every other languages that I know of. This unfortunate operator priority choice has been there since the first version of the X++ language. The workaround, of course, is simple (use parenthesis to group together the sub-expressions), but there is a potential for bugs that may be subtle. We have had no reports from the user base about this problem. It is unclear to me at this time if this is explicitly called out in any documentation that we have, but I doubt it. The morale is this: Always group together your complex Boolean expressions with parenthesis to aid both you and the compiler. We have been very reluctant to align the precedence of the logical operators to other languages, because we fear breaking existing code in the user code base. I would love to hear the opinions of the people out there in the trenches. Let us know: Do we let sleeping dogs lie, or go ahead and fix it? Источник: http://blogs.msdn.com/x/archive/2007...ce-of-and.aspx
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору. |
|
|
|