beanshell / beanshell

Beanshell scripting language
Apache License 2.0
815 stars 183 forks source link

Handling of unknown variables different from bsh2 #746

Open opeongo opened 10 months ago

opeongo commented 10 months ago

The handling of unknown variables (not previously used or previously declared) is different between bsh2 and bsh3. The previous version returned a void where undeclared variables were used, the current version throws an exception.

For example, in bsh2:

BeanShell 2.0b5 - by Pat Niemeyer (pat@pat.net)
bsh % print("hello "+a);
hello void

and in bsh3

BeanShell 3.0.0-SNAPSHOT.5569
bsh % print("hello "+a);
// Error: Evaluation Error: illegal use of undefined variable, class, or 'void' literal : at Line: 1 : in file: <unknown file> : ) ;

There is nothing wrong with either choice of returning a void or throwing an exception. This is a language design decision, not a rule of nature. In this case it seem like this seems to be another one of those gratuitous differences where PatN felt one way about it and the person making this change feels another way (before you say it, yes I know that bsh2 was a beta and BeanShell is not java and so on).

These small differences add an impedance to people converting to bsh3 from bsh2. People try bsh3, their script breaks, and they probably think it's a bsh3 bug. After all, the script worked fine before. Maybe they will just stick with old bsh2.

So I would suggest to slow down and have a reflection on this. Who do you expect to be the audience for bsh3? Are these changes really worth the churn that it will put on the current bsh2 user community that make upgrade to bsh3.

And if these incompatibilities are really a hill to die on, then make a list of all the things that have been changed to be different and incompatible with bsh2, like an upgrade guide, to let people know what to watch out for.

opeongo commented 10 months ago

For the record, I think that throwing an exception is a better choice. My grumpiness about it is the surprise factor that I don't recall seeing or hearing about this. I guess my main point is that it would be really great if there were a list of differences and incompatibilities. This should be a separate list than new features or bug fixes, so people who are upgrading can have a quick look and know what to be aware of.

opeongo commented 10 months ago

I have stumbled across a few things that have broken my script such as

"Untyped variables in BeanShell, however, are not constrained by blocks. Instead they act as if they were declared at the outer (enclosing) scope's level. With this in mind, BeanShell code looks just like Java code. In BeanShell if you declare a typed variable within a block it is local to the block. But if you use an untyped variable (which looks just like an ordinary assignment in Java) it behaves as an assignment to the enclosing scope. "

In bsh3 this changes so that loosely typed variables act as if they were declared in the current scope.

There are likely to be other incompatibility issues that can be added on to this list.