Extending Xojo Operators ( ++, --, +=, -=, /= and *= )

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)

Feedback Case Number: 72752

1 Like

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.

7 Likes

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.

When used on a line of its own and not inline, they are exactly equivalent. X is incremented.

That would be fine, however, not a lot of operations are inlined in Xojo. Having an inline method would be good.

We must assure that only the equivalent to (x = x + 1; return x) exists. So x++ should be semantically avoided.

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.

Not my choice. Any compiler designer would feel ashamed if he need to implement ++n as equivalent of n++. It would create a fight with his boss…

I’m also ok with that.

You misunderstand, I never asked for ++x to be implemented at all. Only x++.

Yes they are different.

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.

And what about negative numbers? and decrement by 1?

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 :man_gesturing_no:
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.

No, what I’m trying to say is that x = +1 doesn’t exist in Xojo today but x = -1 does exist. So how do I know the difference?

This code in current Xojo:

Var x as integer = 5
x = -1 // x becomes -1

how can your code work here?

Edit: looks like you added some information to your post. So you mean

x = --1

?

Edit2: Xojo runs and this code creates x = 1:

var x as integer = 5
x = --1 // x is now 1

You cannot have spaces between +=, -=, /= or *= operators, precisely to avoid such issues. That would be a syntax error.

“X+=1” or “X += 1” are both allowed.
“X + = 1” is not valid.

1 Like

I understand those new operators, I don’t understand what DerkJ proposes with +1 and -1 (with spaces or not).

Why? This isn’t even implemented in xojo currently ?