Pass function parameters by reference #4062
Unanswered
FranKusmiruk
asked this question in
Suggestions
Replies: 1 comment
-
I like this idea, it can be useful in many cases instead of using But as you said, this would cause bugs with functions that was created before this change. Therefore, I myself would prefer to add this as a new feature instead of changing the default behavior of functions, so the colon However, this would be a great addition to Skript and will uplift it to a new level. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Proposed by: @ShaneBeee
Description
As you may know, Skript currently passes function parameters by value, or so is the case for the majority of types. After the introduction to the Cloner interface for some of the types which didn't really follow this behavior we broke functions which depended on these types to be more or less passed-by-reference but now are globally passed-by-value, such as:
While the example makes this look seemingly harmless (and to be fair, that's a very bad one considering you could use the slot type there), this can potentially break a lot of scripts without people realizing it.
That being said, if we revert this change then we will be back in the same spot where the behavior would become inconsistent so instead of doing that we decided to question whether we should instead make function parameters pass-by-reference by default and per Shane's suggestion add another pattern like the below one (though, pattern doesn't really matter, it's more of an example to demonstrate the concept) to allow pass-by-value so that users still have the option to do so if that's what they desire. The advantages of this approach are what has been mentioned before about transitioning for the users depending on pass-by-value behavior making us less worried on the change of the default behavior of function parameters.
So, what are the advantages of passing function parameters by reference?
And while all of the above sounds amazing, there might be cases where passing-by-value is in fact critical for a common usage of functions, we can't think of any yet so we hope you can help us with that :)
As of now, the disadvantages are:
Example
Related
TL;DR
This proposal aims to communicate two things, one is whether to change the default behavior for passing function parameters and the other is to introduce a new pattern to allow users still approach functions the same way they used to do in case we choose to go ahead with the former.
Beta Was this translation helpful? Give feedback.
All reactions