Strongly typed instance variables?

Discussion and feedback on Construct 2

Post » Sun Mar 06, 2011 8:57 pm

I find that 'Strongly typed' is a bit ambiguous in this case, so I'll respond using my understanding of the subject matter.

Short version: I'd be fine with it, as long as it seems uniform throughout.

I'm used to strong typing in most of the programming languages that I've used, where there is no implicit type conversion that happens at run time. If you want to perform an operation upon two different data types, you must explicitly cast one of them into the type of the other. I prefer this.

In my experience with the original Construct, it was at least somewhat weakly typed, in that one could concatenate numbers and strings implicitly. I did find it somewhat confusing that it was not uniform in that matter. For example, on a text object, if I 'set text' the result of the addition of a number and a string, it would implicitly cast the result to that of string in order to assign it to the object's Text instance variable, but the result would only be the string representation of the first variable. The second was just ignored, even if the string only contained numeric characters.

In my opinion, it should either result in error because the variables were not explicitly cast, or be more fully weakly typed and allow for implicit conversion of strings to numbers where the string consists of numeric characters.

On the other hand, I like dynamically typed variables. I like to be able to store whatever I want in a variable, whenever I want, even if I have to type check/cast in the code in some cases to make sure that it doesn't cause problems. I do occasionally use such practices.

I suppose that the cases that I can think of where this is useful can be worked around with using different variables. In fact, I'd not likely care if variables are statically typed, if the only types available are boolean, number, or string. I'd more likely use complex types in such a way.

I share newt's sentiment that there should be other data types allowed as regular variables, such as arrays (especially!) Construct was too limited with the use of arrays. They are essential to solving many problems.

However, I think that they also need to be able to be created at run time as well. I'm not sure how this would work with Construct 2. If they are allowed as instance variables, then I'd say that there needs to be a way to create arrays on-the-fly and allow arrays of arrays. Or, new instances of an object could be created in order to contain a new array, which would probably also work for me.

If arrays are separate objects as in Construct, then it would be nice if they can have more than one instance, as other objects can. Then, perhaps my sprite object (or whatever) can store an index number to the array instance that was created for it, and reference the array object by index. If I wanted each sprite to have an array associated with it, and I create sprites at run time...

Really, it's hard for me to say how I'd feel about it without knowing exactly what data types there are, and how they can be used.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Sun Mar 06, 2011 10:13 pm

[quote="Silent Cacophony":1uuk3zd2]If I wanted each sprite to have an array associated with it, and I create sprites at run time...[/quote:1uuk3zd2]
You can do this in 0.x by placing an array object in a container with a sprite.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Mar 07, 2011 1:21 pm

Well, I wasn't expecting such a unanimous response, guess it was an obvious thing to do :)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Mar 07, 2011 4:30 pm

Another question: should the 'set instance variable' action force the type?

For example if you set a number instance variable to MyText.Text, should it automatically convert it to a number as if int() or float() were around it? Otherwise, you get an error that you're setting the wrong type. Is it convenient, or error-prone since it allows things like "Set MyNumber to 'Foo' "?
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Mar 07, 2011 5:32 pm

I think a warning msg should pop up instead of an error msg with the options
Ok (which just proceeds with the conversion)
Cancel (so you can change it)
Or
Don't show this msg again (with the options :for this variable, for this session, for this project, ever)
Spriter Dev
B
88
S
21
G
12
Posts: 3,240
Reputation: 16,486

Post » Mon Mar 07, 2011 9:23 pm

Agree with lucid - pop up window with a choice.
ImageImage
B
25
S
6
G
8
Posts: 773
Reputation: 6,643

Post » Tue Mar 08, 2011 1:01 am

An option would be nice, as I could see where someone would want to use get text for debugging.
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Tue Mar 08, 2011 7:36 am

[quote="Ashley":okeecsim]Another question: should the 'set instance variable' action force the type? *SNIP*[/quote:okeecsim]

I'm of the opinion that it should fail if the type is incorrect, at run time.

If you're talking about when it's entered into the editor, then I suppose a choice would be good. The options that make sense to me would be:

1) Construct automatically coerces the value into the correct type by explicitly adding the correct typecasting function around the value in the editor, and points it out to the user, so that they know what they did wrong.

2) Cancel. Perhaps the user meant to use a different value entirely.

3) Always allow Construct to convert. Not sure I like that, but some may find it useful.

Pretty much what lucid said, I think. However, I'd be fine with just making the user pay attention to what values they are working with, and letting it error in all cases. As long as there is a meaningful error message, it would seem much the same as the choice to me.
B
3
S
2
G
2
Posts: 187
Reputation: 1,449

Post » Tue Mar 08, 2011 8:45 am

Make it an application setting.
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Previous

Return to Construct 2 General

Who is online

Users browsing this forum: Yahoo [Bot] and 16 guests