I’ve been using Real Basic/Xojo for a while, but I haven’t come across an increment operator. Does Xojo support it? ++i or i += i don’t work. Am I stuck with i = i + 1 ?
No increment operator… and that is religious war around here.
I’m in the camp that likes it the way it is!
Just say no to C syntax!!!
The “+=” operator is already assimilated by other Basic compiler flavors, so I don’t see any reason for Xojo not evolving too.
I do really prefer to write:
Dim MyAddAndAssignOperatorVar as Double = Rnd*1000
MyAddAndAssignOperatorVar += Rnd
And for those who prefer the old style, it still works, so why not? :
Dim MyAddAndAssignOperatorVar as Double = Rnd*1000
MyAddAndAssignOperatorVar = MyAddAndAssignOperatorVar+Rnd
And their partners: += , -= , /= , *=
I wish for a shift left/right operator (i.e. <<, >>).
Yes. And their counterparts too <<= and >>= .
All those exist in VB.Net, just for an example of one popular Basic compiler who accepts all those.
while not >> and << there is bitwise.shiftright and bitwise.shiftleft functions already in Xojo
I love that this topic has come up. Again. But the folks at Xojo have already said, many times that they aren’t going to do this. While I don’t have to use these operators, I would still have to read your code that does, and they aren’t readable by someone who doesn’t already know what they do.
For me, this:
MyAddAndAssignOperatorVar += 1
Is much cleaner at a glance then this:
MyAddAndAssignOperatorVar = MyAddAndAssignOperatorVar+1
And if this topic is always coming back, that’s just a sign of a desire of people for evolving the language as other compilers already have done.
The one thing I can say is that you’ll never see the pre-increment and post-increment operators.
You may find it so, but I don’t. Therein lies the rub.
BTW, even cleaner: myVar.Increment. You can make this happen now.
As you noticed, I did not included those in my arguments.
Interesting. I was the last poster and can’t adjust my last post. Tried refresh, etc. Edit options just don’t appear.
Xojo is a high level language which uses natural language elements making it fairly easier to learn, that’s why you will not
see increment operators.
For whatever reason I have a hard time remembering “bitwise” when coding. I guess its the many years of c coding that is tainting my brain. I tend to use the ‘and, or, xor and not’ operators. The idea of adding << and >> operators (or something more like a word) would fill the gap of missing operators and one could choose between bitwise and operators completely.
Nope. The real reason is that increment/decrement INLINE option is just out of the scope of the nature of the Basic language. But, the extra smarter assignments ( as += ) where accepted and adopted for the newer versions of the language. Having shorter/smarter options can coexist with their prolix counterparts for BASIC purists.
You can make that happen too: myVar.Add value
.
But I still don’t want += in the language. Not only do I find it less readable (as any person who is not a seasoned programmer would agree), it will lead to incrementalism. “You added those, so why not just add ___ too,” and the next thing you know, Xojo code is indistinguishable from perl.
[quote=21622:@Kem Tekinay]You can make that happen too: myVar.Add value
.
But I still don’t want += in the language. Not only do I find it less readable (as any person who is not a seasoned programmer would agree), it will lead to incrementalism. “You added those, so why not just add ___ too,” and the next thing you know, Xojo code is indistinguishable from perl.[/quote]
An extension method called ‘Add’ won’t work in a lot of cases that an operator would. For example:
foo.bar.baz += 1
Why wouldn’t an extension method work there? I’m envisioning something like:
Sub Add(Extends ByRef var As Integer, value As Integer)
var = var + value
End Sub
[quote=21630:@Kem Tekinay]Why wouldn’t an extension method work there? I’m envisioning something like:
[/quote]
Overhead of a method call. That doesn’t get inlined.