Skip to content

BeanShell vs Java #501

@nickl-

Description

@nickl-

There are a lot of new features in BeanShell and I would like to bring this topic up for discussion to get a sense how you feel about it and so that we may reach a consensus as to what can be expected. This is a discussion and you should treat it as such whether you agree or disagree lets hear it.

BeanShell original mission statement

From the introduction in the original documentation the following claims were made. I believe we are still true to this vision.

BeanShell is a small, free, embeddable Java source interpreter with object scripting language features, written in Java. BeanShell executes standard Java statements and expressions but also extends Java into the scripting domain with common scripting language conventions and syntax. BeanShell is a natural scripting language for Java.

So lets visit each of these topics...

BeanShell is small, embeddable

Of course enabling new features and functionality naturally means growth, whether they are enhancements or just implementing missing java features alike, but we still aim to keep the footprint small. A lot of refactoring helps reduce bloat and with the increased minimum java version (now JDK 1.8) opportunities arise to remove redundant work arounds and fixes that pertained to older versions of the VM as well.

Another aspect alongside keeping the size small is optimizing for performance, improving routines reducing bloat applying new and optimal java features and replacing old legacy code. As a source code interpreter it is important that we try and keep things running fast and faster. The parser grammar also inherited a lot of legacy from what is the "officially unofficial" (because it is not used for java at all) java 1.5 grammar which parses java syntax (albeit from 10 years ago) but not necessarily optimally. There is still a lot that can be done to reduce complexity which in turn increases performance.

BeanShell is free

Yip free as in beer... cheers! Which is secured by the Apache open source license to ensure it stays that way.

Works like Java

"Java source interpreter, BeanShell executes standard Java statements and expressions."

We do not compile java or use any of the Sun/Oracle building tools instead BeanShell parses and understands standard java source code and syntax. Even though we are running in a java virtual machine all the language features has to be implemented by BeanShell. Something as simple as instantiating an Object can't happen unless we wrote that implementation.

Many existing language features are still not implemented and simply does not work, until we get around to it. Similarly there is source code that we cannot parse or understand also because this too needs to be developed. Just being able to load a java source file successfully without any errors not to mention interpreting or executing any of what it describes requires a lot of work to be done.

Work that will always take preference and we would want you to expect BeanShell to be able to read, understand and successfully execute any java. Missing features will always be considered, implemented and hopefully one day we will catch up with compatibility with the current java release. Without contest the one project goal with the highest priority is for BeanShell to work like java.

This is not the only goal, BeanShell is also a scripting language and we aim to make it functional, easy to get common things done and super fun to work with. Where java stops BeanScript goes onwards and upwards and we do take many liberties that completely contradict java. You can do things in BeanShell that you cannot do in java but we will always try and make things work like they do in java.

We have a strict java mode, with the goal in mind to disallow the use of any BeanShell enhancements and language features, and only allow what java does. Some aspects would only be practically implemented in strict java mode because it disables the BeanShell features. For the current development road map and next release strict java is not a priority and something we can perhaps focus on for the following release.

It is important to make one clear distinction however, when we say BeanShell aims to "work like java" it must not be mistaken to also mean that BeanShell will "break like java does". While we may make every effort to run working code with all the bells and whistles like it does in java, it is not part of our focus to consider anything that is expected to fail in java. Even with strict java mode the aim remains towards making things work like they do in java. Only code that works perfectly in java without any faults or errors, expected or otherwise, can be considered runnable with BeanShell.

The fact of the matter is BeanShell is not the same as java. For starters there is no compiler so no compile time warnings or type parameter assignments. Syntax problems begets parser errors which has no similarity or comparison to any faults reported in java. Even when BeanShell produces similar runtime exceptions to those found in java, these should be considered as being for informational purposes only. BeanShell does not make any attempt to emulate the way java fails. In some cases BeanShell may even choose not to fail by design. Just because it fails in java does not mean it is expected to fail in BeanShell. It is the developers responsibility to ensure that the code doesn't fail and BeanShell will attempt to work like it does in java.

"With object scripting language features, BeanShell, extends Java into the scripting domain with common scripting language conventions and syntax. BeanShell is a natural scripting language for Java."

As much as BeanShell loves interpreting java code, wait till you get your hands on BeanScript. Since we can already consume pure java code you know that BeanScript will also be java centric which feels intuitively familiar. An experience akin to the natural evolution from what you already know about java maybe even expected. No matter how surprising some things may be nothing will ever seem foreign or strange. It is like the best friend you never had but already you finish each others syntaxes.

I sometimes imagine, if you had to abandon this project for several years, until you can barely remember how cool it once was (I know hard to imagine but lets try). When you finally return you'll find that the language somehow evolved all on its own, all grown up and mature like you always knew it could. If that was only true and it didn't take any effort but that is how I like to think when considering a feature and I ask myself, can it's roots be found in java.

Where java ends BeanScript continues, instead of failing what also makes sense for next, where java prevents we can find new doors to open. Some things extreme which java ignored that we can borrow from other languages, some so subtle you could swear java has it too. We don't just do syntactic sugar or anything that strays from java syntax constraints. It is taking the building blocks available in java and setting them free without limitations or constraints. If ever you ask yourself in java, why not?, that's probably something we'd like to care about too so do share.

If you don't like it that's fine, you can keep doing things the hard way because it doesn't break java, rest assured what works in java should work with BeanShell. If things really get in your way, which they shouldn't that would be wrong, you can always switch to strict java and make it go away. Strict java in theory though so please don't shoot anyone if it breaks. Not being thoroughly tested nor is it in scope for the next release but be patient and someone will work on it soon.

The latest feature enhancements have been introduced as discussions which also aims to provide content for documentation, you're welcome to share your opinions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions