In most programming languages (such as C++, Java, or PHP) the boolean unary NOT operator has a higher precedence than e.g. the multiplication, division, remainder, or relational operators. It usually has a precedence same as the unary '+' or unary '-'.
But why does Twig deviate from this practice and puts the unary 'NOT' operator precedence between the ones below:
....
'+' (binary add)
'-' (binary minus)
'~' (binary concat)
'NOT' (unary not)
'*' (binary multiply)
'/' (binary division)
....
Not even Django (Python) has such a strange precedence placement.
There are several other bad habits in the Twig expression syntax, but I think above mentioned issue could be fixed, and if need be, add a runtime switch to ensure backward compatibility with older Twig versions, but have future Twig releases use a proper operator precedence.
In most programming languages (such as C++, Java, or PHP) the boolean unary NOT operator has a higher precedence than e.g. the multiplication, division, remainder, or relational operators. It usually has a precedence same as the unary '+' or unary '-'.
But why does Twig deviate from this practice and puts the unary 'NOT' operator precedence between the ones below:
....
'+' (binary add)
'-' (binary minus)
'~' (binary concat)
'NOT' (unary not)
'*' (binary multiply)
'/' (binary division)
....
Not even Django (Python) has such a strange precedence placement.
There are several other bad habits in the Twig expression syntax, but I think above mentioned issue could be fixed, and if need be, add a runtime switch to ensure backward compatibility with older Twig versions, but have future Twig releases use a proper operator precedence.