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:
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.
This is a good point, however I don't think it will ever be changed, it would be too sensitive for users to move. This can have serious consequences on calculations etc.
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.