A (maybe dumb) question about adding a value ...
BlitzMax Forums/BlitzMax Beginners Area/A (maybe dumb) question about adding a value ...
| ||
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 |
| ||
Nope, will be the same on the codeside. |
| ||
Yes it's just a shortcut. |
| ||
But I think Var :+ 1 is faster And possibly Var :+ Const Im not sure, and cannot be bothered to time check |
| ||
In some languages the shorthand can be more optimized, don't think this is a factor in bmax. Use whichever you prefer. |
| ||
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. |
| ||
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. |
| ||
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 |
| ||
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 |