SUGGESTION: Operators

Started by Trent R, Mon 17/11/2008 19:27:10

Previous topic - Next topic

Trent R

This was originally question in Beginner's Tech asking why += and -= weren't in the manual. This sparked a 'discussion' on the other operators and that they should be implemented.  I changed the topic title, but it was never moved (as I found out, most likely because those mods hardly log in)

1) Add += and -= into the manual. They already work, so why not update the manual? I find them immensely useful, and more so than the binary ones.

2) Added support of *=, /=, and %=. As dkh said in the orig, *= and /= are used very often, and I don't see how hard it can be‡ to implement all of them into AGS.


~Trent
‡  I bet people use that phrase all the time.



From the other topic:
Quote from: monkey_05_06 on Thu 06/11/2008 08:00:04
I can't say for sure why the += and -= shortcut operators aren't included in the documentation (but yet, as you say, the binary operators are...).

Definitely I'd say it would be useful for new members to know about.

It is notable that at the moment there are no *=, /=, or %= operators however.
Quote from: dkh on Thu 06/11/2008 10:30:56
While we're talking about these, I have often noticed the lack of *= and /* respectively and thus would welcome their addition. Can't imagine it can be much of a time investment to implement them?
Quote from: dkh on Tue 11/11/2008 17:45:51
I really use the remainder operator % so rarely that it's not a big hassle to type in the few more characters. I use *= and /= often though!

Of course, if Chris implements *= and /=, it wouldn't be a problem (I suspect this should be pretty easy to get into AGS) to just add the %= as well, at the very least for consistency's sake!
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Radiant

You forgot the shift operators :)

Anyway, I regularly type in *= in AGS because I'm used to C / C++, and then I remember that it doesn't work. But it's just a bit of shorthand, no big deal really.

What I'd actually find far more useful is a switch statement, if that would give better performance than a sequence of } else if (....) {

Also, there's no for, but I don't think anyone really misses that.

Snarky

Actually...

Quote from: Snarky on Sat 15/11/2008 15:50:47
Throw in for-loops and switch/case, and I'd be a very happy camper indeed.

Quote from: ProgZmax on Sat 15/11/2008 18:23:56
I'd definitely like to see switch/case.  That would make doing the custom dialogs much easier.  I wouldn't mind for loops, either.

Ishmael

Quote from: Trent R on Mon 17/11/2008 19:27:10
1) Add += and -= into the manual. They already work, so why not update the manual? I find them immensely useful, and more so than the binary ones.

They are in the manual. If you know enough scripting to use them you'll probably too notice which ones work and which ones don't, so I really don't see the storm in a tea cup about this you've brought up.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Trent R

Actually, I would really like the other operators implemented. There's no meaning to the numbering, so it's not a 'storm' that I'm cooking up about a tiny issue.

As for the manual, isn't it about teaching someone how to script? Yes, I know that they work and I know quite of scripting because I've used other languages, but what about others that might not know? And when they're 'in the manual' it's the scripting tutorial, but I skipped that because I already knew about all of those topics. I'm talking about the Operators entry.

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

Ishmael

Well, they're not there, sure. I can see your point there. But if you don't need to read the scripting tutorial you supposedly already know about the short cut operators then, is my logic here.
I used to make games but then I took an IRC in the knee.

<Calin> Ishmael looks awesome all the time
\( Ö)/ ¬(Ö ) | Ja minähän en keskellä kirkasta päivää lähden minnekään juoksentelemaan ilman housuja.

Pumaman

Yes I agree that these operators could/should be added. I also agree that "switch" and "for" and "continue" and "break" should be added and that when  debugging you should be able to see the values of variables.

At some point I will dive into the script compiler and do these, but not right now.

Monsieur OUXX

I am fiercely opposed to all of these operators, because the only thing they do is to confuse beginners (+= first computes and then evaluates the expression, which gives random results e.g. in a "while" statement when the user doesn't really know what he's doing).

Those are my principles, and if you don't like them, I've got others.  ;)

 

Khris

I'm fiercely opposed to not understanding that the use of these operators is optional.
And why would you use them in a while statement?
x += y is a substitute for x = x + y, not a condition.

Ryan Timothy B

There is always   x=x+5;  if you really don't like it the easier way.

I personally prefer the  x+=5;
Surely it may look confusing at first, but you get used to it.

edit: ahh as Khris says it before me..

Shane 'ProgZmax' Stevens

Scripting language in general confuses beginners.  Learning new things is a part of the process, and condensed operators, once understood, reduce the size of your code and save you time (both of these are good).  Of course, if you don't like them you don't have to use them, but I certainly do.

Rocco

for loop would be nice, but one thing would be great.
I missed this very often, and the workarounds are laborious - multidimensional arrays.
At least 2-dimensional would be very nice for the future.

TheMagician

@Rocco:
In case you don't know this module:
Multidimensional Arrays

monkey0506

@TheMagician:

Lol. Honestly, I doubt the actual viability of that module. Used in an actual project it's better to hard-code your own functions (basically it's too slow and requires too many loops).

If there was a way to check the size of a dynamic array...or if I just accepted that it's going to crash trying to verify the data anyway I suppose I could rewrite it to be more efficient.

But honestly, in most cases it's something as simple as:

Code: ags
int my_arr[];

my_arr = new int[3*4*5];

function set_my_arr(int a, int b, int c, int value) {
  int i = (((a * 4) + b) * 5) + c;
  my_arr[i] = value;
}

function get_my_arr(int a, int b, int c) {
  int i = (((a * 4) + b) * 5) + c;
  return my_arr[i];
}


To me, not honestly that high priority when it's simple to work around.

[/offtopic]

Anyway, the operators aren't that difficult to work around either. It's as simple as, "D'oh!" I always end up using *= and /= but as soon as the compiler kicks it up I remember and just fix it.

Also, not high priority IMO. 8)

SMF spam blocked by CleanTalk