X++ new operators
It has been some time now since I have done any blogging, and that is a shame because we have been busy at work here in the X++ laboratory. For this brief installment I will be talking about two new operators that we have introduced, and some long overdue changes to the way that internal works.
As you may know, X++ (and most other imperative languages I can think of) have short hand operators to add and subtract values from a given variable. In other words:
X = X + 3;
Can be more succinctly expressed as
X += 3
The advantage (apart from the light syntactic sugar) is that the variable (or, more precisely, the address where the value gets stored and the value retrieved from) does not get evaluated more than once. Therefore if the expression has side effects, they are also only executed once. The X++ language has provided this short hand notation for as long as I can remember, and now we have added the multiplication and division variants:
X *= 2
X /= 2
These are short for X = X * 2 and X = X / 2.
Not a huge deal perhaps, but I thought I would mention it here, since there is no way to otherwise guess that this has become available. We do not have plans for introducing any more of these operators, like <<= and >>= (assign with shift left and shift right).
The new bits will appear in your compiler bits before you know it.
Comments
-
Thanks Peter. These new operators are cool, but the real pain point in X++ is C# interobility, for example, you can't call C# functions that require iterators as parameters(like functions with '<' or '>' or '=>' or '[]' symbols). X++ compiler generates an error during this. The current workaround is creating a C# project that wraps these functions, but it is will be great to see some improvements in this area for X++. As an option for example introduce maybe some C# area tag, and inside this area all code will be compelled according to C# rules
*This post is locked for comments