asar icon indicating copy to clipboard operation
asar copied to clipboard

Preventing user functions from overwriting builtins

Open p4plus2 opened this issue 6 years ago • 7 comments
trafficstars

As the title suggests, while rewriting asar_math's function handling code I corrected the bug where users could overwrite a builtin. This now generates an error.

Pros: Prevents users from making code that is accidentally misinterpreted. User may be trying to reimplement said builtin (especially math-like operators) not realizing it already existed Cons: Adding a new builtin has a small chance of being backward incompatible.

I personally believe the chances of such a name conflict are quite tiny and fairly trivial to correct should they happen. (either by renaming in asar or simply updating the patch.)

p4plus2 avatar Dec 15 '18 12:12 p4plus2

I feel like the best solution in this case is a warning: it doesn't make old patches incompatible, and it lets the user know of the builtin just as well as an error. You can also disable a warning if you know what you're doing.

trillllian avatar Dec 20 '18 11:12 trillllian

A warning would be a good idea. Or if we decide to remove the feature altogether in the future, it would still be useful to have at least one release with a deprecation warning.

RPGHacker avatar Dec 20 '18 12:12 RPGHacker

Should we keep user defined overwriting as an error or make it consistent with builtins?

p4plus2 avatar Dec 20 '18 13:12 p4plus2

"User defined overwriting"? As in, overwriting previously user-defined function?

RPGHacker avatar Dec 20 '18 13:12 RPGHacker

I'd keep it consistent with the built-ins.

trillllian avatar Dec 21 '18 14:12 trillllian

I would keep them as an error, since overwriting previously user-defined functions was never supported in the first place, and it can also lead to nasty problems if someone were to make some kind of shared code library or something like that, for example. Functions could overwrite other functions from the library. Of course we could throw a warning for that, but I think it's better to prevent users from doing that in the first place and throw an error. Can't think of a good reason to allow usage of a bad practice that wasn't usable before.

RPGHacker avatar Dec 21 '18 14:12 RPGHacker

currently made overwriting either builtins or user functions a warning. not closing ths though since we didn't reach a consensus about overwriting user functions.

trillllian avatar Jul 09 '20 22:07 trillllian

Warning + deprecation added to 1.9, error in 2.0, closing as completed.

p4plus2 avatar Jan 21 '24 01:01 p4plus2