Jump to content
  • Advertisement
Sign in to follow this  
_Vicious_

Go-inspired features in Angelscript

This topic is 761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Andreas,

 

thanks for your continued work on the wonderful language!

 

I have recently gotten my feet considerably wet with Golang and have found some of its features pretty cool and useful, multiple return values and short variable declarations to name a few. Now I would consider the former to be somewhat more difficult to implement than the later, which seems to be a little more than syntax sugar for the 'auto' declaration.

 

Is there a chance you would consider implementing some of these features in AngelScript? Now I'm aware your TODO list is already miles long but I figured I'd ask you anyway :)

 

Best regards,

Victor

Share this post


Link to post
Share on other sites
Advertisement

Thanks for the suggestions.

 

multiple return values is something that I find myself thinking about every once in a while. It is something I find very useful when I do some work with perl scripts, and may try to include something like this for AngelScript too. It's way too soon to think about when or how though.

 

I'm not too sure about short variable declarations though. It would probably not be too difficult to implement, but it looks like something that could be a cause for lots of bugs when used by non-experienced programmers. I'll keep it in mind though.

Share this post


Link to post
Share on other sites

Thanks for the suggestions.

 

multiple return values is something that I find myself thinking about every once in a while. It is something I find very useful when I do some work with perl scripts, and may try to include something like this for AngelScript too. It's way too soon to think about when or how though.

 

I'm not too sure about short variable declarations though. It would probably not be too difficult to implement, but it looks like something that could be a cause for lots of bugs when used by non-experienced programmers. I'll keep it in mind though.

Could you please elaborate on what kind of bugs you think are possible with such approach to variable declaration?

Share this post


Link to post
Share on other sites

What are the benefits of short variable declaration? All I can see it doing is obfuscating the code. It makes it much harder to tell the type of a variable, its moment of declaration, and initial value. As a person who is often asked to read and debug others' code, I'd much rather encounter the current declaration syntax.

Share this post


Link to post
Share on other sites

personally Ive always found multiple returns a very limited and trivial feature. Most the time it is hardly useful and can become confusing. Furthermore there are not too many cases where it is nessary and normally its just easier to put the data in a struct (or class) and send it back that way. This is more organized and leads to less bugs down the line (like having to remember what return index belongs to what. If you just wanna send back varible amounts of data, i find that using non-casted arrays are easier, and about as volatile as multiple return types.

 

This second one is just plain useless to be honest. I dont think that this could ever be of use to anyone, and just makes code way too unreadable. Ppl have a hard enough time naming their variables, functions, classes, etc correctly this would just turn into a nightmare fast, with very very very very little use, other than to confuse everyone so no one has a clue what's going on.

 

chasester

Share this post


Link to post
Share on other sites

It makes it much harder to tell the type of a variable, its moment of declaration, and initial value.

The same kind of argument applies to 'auto', which found its way into AngelScript nonetheless.

 

 

Furthermore there are not too many cases where it is nessary and normally its just easier to put the data in a struct (or class) and send it back that way.

I believe you are wrong here. I find it that polluting the code with structs and classes that do not serve any purpose other than storing the return values for non-trivial functions is very much an anti-pattern. You can't have too many of them without making a mess.

 

 

This is more organized and leads to less bugs down the line (like having to remember what return index belongs to what.

Again, this is debatable. I would think that the same kind of argument applies to structs or classes (having to remember which class member corresponds to what).

 

 

Overall, it seems to me that neither of you have ever tried go lang, which I recommend you should do. I know you love your C++ but c'mon, there are other languages and technologies out there.

Share this post


Link to post
Share on other sites

 

It makes it much harder to tell the type of a variable, its moment of declaration, and initial value.

The same kind of argument applies to 'auto', which found its way into AngelScript nonetheless.

Not exactly. The auto keyword has its flaws and a good programmer knows not to overuse it, but it has only one of the issues I mentioned, which is that it's hard to tell the type of a variable. It doesn't however, create ambiguity regarding the moment of declaration or initial value. Let me demonstrate:

auto x = 1;
x += 1;

Easy to tell when x was declared - there's a keyword in front of it. The line especially stands out in editors with syntax highlighting.

x := 1;
x += 1;

The lines differ only by one character. In a busy function, it could take a long time to tell whether x is local or global.

auto g = 1.f, d = sqrt(2), i = pow(2, 4), t = sin(3);

Easy to tell the initial value of each variable.

g, d, i, t := 1.f, sqrt(2), pow(2, 4), sin(3);

It takes some counting to determine which variable has which initial value. Again, this is a trivial example but in a real life situation where variable names and initial values were somewhat longer, it would become unreadable.

 

Even the type is actually easier to tell with auto, because unlike in short declarations, you cannot declare multiple variables of different types in a single auto declaration, so if you know the type of one variable, you know them all.

 

Again, I was asking for benefits of short variable declarations. I think a proposed addition should be supported by rationale.

 

C++ is my primary and favorite language and my team chose AngelScript largely due to its resemblance to C++. I also know several other languages, and although Go is not one of them, Lua is, and it has both of the features you're suggesting. Not a fan of it. I'd rather type more code and know what I'm doing when I return to it after a month.

Share this post


Link to post
Share on other sites

This is more organized and leads to less bugs down the line (like having to remember what return index belongs to what.

Again, this is debatable. I would think that the same kind of argument applies to structs or classes (having to remember which class member corresponds to what).

 

 

Overall, it seems to me that neither of you have ever tried go lang, which I recommend you should do. I know you love your C++ but c'mon, there are other languages and technologies out there.

 

 

 

well if you name your structs correctly its not confusing. If you find you are using this alot i imagine you are doing something wrong. Maybe look at finding a better way to write your code so you dont find it is absolutely necessary to have to alway multi return :) I mean its debatable i guess but most languages dont use this, and its been around for a while, so at the very lest people that write coding languages dont like it. Personally I find no use for them, and have never ran into a case where they would have been better to use then an other method.

 

but whatever its a pointless debate :)

chasester

Share this post


Link to post
Share on other sites

 

Thanks for the suggestions.

 

multiple return values is something that I find myself thinking about every once in a while. It is something I find very useful when I do some work with perl scripts, and may try to include something like this for AngelScript too. It's way too soon to think about when or how though.

 

I'm not too sure about short variable declarations though. It would probably not be too difficult to implement, but it looks like something that could be a cause for lots of bugs when used by non-experienced programmers. I'll keep it in mind though.

Could you please elaborate on what kind of bugs you think are possible with such approach to variable declaration?

 

 

One bug that I can immediately imagine, is that the user mistypes the variable name when assigning a value. With the short variable declarations this would declare a new variable and thus not produce any compiler error. 

 

You mentioned 'auto' too. I'm actually not a huge fan of 'auto' either. However these have a great usability in macros and mixins, as with autos they macros/mixins can be reused without having to write a different one for each type. This was the argument that convinced me to add 'auto's in the script language in the first place.

 

 

personally Ive always found multiple returns a very limited and trivial feature. Most the time it is hardly useful and can become confusing. Furthermore there are not too many cases where it is nessary and normally its just easier to put the data in a struct (or class) and send it back that way. This is more organized and leads to less bugs down the line (like having to remember what return index belongs to what. If you just wanna send back varible amounts of data, i find that using non-casted arrays are easier, and about as volatile as multiple return types.

 

Currently a function can return multiple values through the use of output arguments, or by defining a structure with multiple members that can be initialized and returned. What I have in mind when I say returning multiple variables, is just a simpler syntax for this so that the writer still has full control but can accomplish what is desired with less typing. 

 

Perhaps it can be done with defining structures as inline in the function declaration itself, and then have an easy way of assigning these to multiple expressions. A bit like C++ tuples that were added in C++11. 

 

However, this is definitely a low priority feature. 

Share this post


Link to post
Share on other sites

 

One bug that I can immediately imagine, is that the user mistypes the variable name when assigning a value. With the short variable declarations this would declare a new variable and thus not produce any compiler error.

Not quite true in case of Go, which features different syntax for short variable declaration and assignment.

 

a := 0 // declares a variable 'a' and sets it's value to 0, same as 'auto a = 0'

a = 0 // sets value of variable 'a' to 0

b = 0 // produces compiler error because assignment only works for variables that have already been declared in this scope

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!