A (maybe dumb) question about adding a value ...

BlitzMax Forums/BlitzMax Beginners Area/A (maybe dumb) question about adding a value ...

Doc Holliday(Posted 2011) [#1]
Hi, folks!

I'm working with bmx since dec. last year. When I have to add a value to an existing variable I code it like this:

var = var + value

Now I discovered this notation:

var :+ value

Personally I think the first one is better to read. But:
Is there any difference in the compiled exe? For example, is
the second notation faster while executing?

Thanks in advance!

Doc Holliday


BladeRunner(Posted 2011) [#2]
Nope, will be the same on the codeside.


Czar Flavius(Posted 2011) [#3]
Yes it's just a shortcut.


H&K(Posted 2011) [#4]
But I think

Var :+ 1 is faster

And possibly

Var :+ Const

Im not sure, and cannot be bothered to time check


ima747(Posted 2011) [#5]
In some languages the shorthand can be more optimized, don't think this is a factor in bmax. Use whichever you prefer.


Perturbatio(Posted 2011) [#6]
But I think

Var :+ 1 is faster

And possibly

Var :+ Const

Im not sure, and cannot be bothered to time check


They produce exactly the same code (I tested to be sure). So they will be the same speed. The shortcut is just, by it's nature, quicker to type.


GfK(Posted 2011) [#7]
I do wish people (i.e. H&K) wouldn't clutter up the forums with misinformation. It completely knackers people who are searching for information later and serves no useful purpose at all. Just don't reply if you - as you openly admit - don't know.


Doc Holliday(Posted 2011) [#8]
Thanks for the answers. So I don't have to worry about the notation.
I think the long notation is better to read, especially when you read
older code where you have to find into the inner working of the code
after a long(er) time. But that's only my personal opinion. :-)

Doc Holliday


Czar Flavius(Posted 2011) [#9]
In some languages the shorthand can be more optimized, don't think this is a factor in bmax.
This can be the case with operator overloading with C++ classes. Too tired to explain now and it's not very relevant as Blitz doesn't do overloading. The important thing is they are both equivalent in speed for basic number types in either language.

Last edited 2011