If you are interested in the following operators being added to Xojo, please thumbs up to the following feature request. Equally, if you don’t like them you can down vote it.
variable++ (increment variable)
variable-- (decrement variable)
variable += 10 (add 10 to variable)
variable -= 10 (subtract 10 to variable)
variable *= 10 (multiply variable by 10)
variable /= 10 (divide variable by 10)
If I recall correctly, the old Xojo compiler designer thought that those above could be possible, but…
Those “inline” (++x or x++) would present some resistance/difficulty to be implemented. And a “x += 1” would not be too verbose instead of a lone ++x. Well, nothing was implemented anyway…
I stress in the bug report that I didn’t support inline use of ++ and --. Only one per line, as per my example. If it only operates on a line of it’s own the ++X and X++ are exactly the same thing, in my experience X++ is more commonly used.
// I don't want to be able to do this
SomeMethod( x++ )
Yes, I would be happy with just X += 1, for increment.
If you programmed some C based language you must know that they aren’t, and people will make wrong assumptions if we can’t have it working as they expect as in all other variants.
wouldn’t a more basic style be to have an Inc and Dec operator?
Inc variable
Dec variable
to increase and decrease by one.
And the parser should change it to the operation to get the variable and increase/decrease value by one without a function call to getting any object twice.
At that time I asked that ++x was acceptable and x++ caused a compiler error. Also ++x should be alone, not in expressions. This could be a solution. Some C users would be confused when a ++i would work and a “x = ++i * 3” caused an error, but a good error message as “++variable can’t be used in expressions” would help.
That’s your choice and I’m happy for you to push for that. I, for myself, disagree. If all I can get is += I would be happy. Anything to avoid having to type the variable or even compound class property path duplicated.
i think to keep things more basic this would be great:
Var x As integer = 0
x =+ 1 // x = now 1 - same as the one above just a typing preference difference.
x inc 1 // x = now 2 - same as the one above just a typing preference difference.
// All above have the same result but make it easier to read an are closer to other languages.
Would be the easiest to understand. But i’d like to see the language more compatible with other langues, this cause it makes things easier to find online (or at least closer to a solution).
Basicly this brings developers from different languages also closer to understand Xojo. So the changes should win more users.
Edit removed the one line that already is implemented and cannot be used.
Var x As integer = 5
x = -1 // x = now -1
x =- 1 // x = now 3 - same as the one above just a typing preference difference.
x dec 1 // x = now 1 - same as the one above just a typing preference difference.
// All above have the same result but make it easier to read an are closer to other languages.
Do i need to fill in all blanks?
We should be able to expect that that will be provided to. This is just my preference.
So the negative numbers should just have their negative part to it…
x = - -1 etc.
Just as unclear as “”“” (quote quote) to escape quotes
Xojo needs more portability, we ask for years on this. We all benefit from this.
We need general solutions that are already known worldwide:
Just like the "" as an escape character instead of or additional to the quote quote
Just like we got “Var” (additionally) instead of the old scool dim only.
Just like “&h” is a result to Color.ToString, this could have just been “#” as many others.
There are many of those things that just take a long way around what could been a short road.
Edit so i removed the “x = -1” as that already exist.