Oracle not about to sue anybody over Javascript

Here is my Rhino Wrapper, FWIW. (download)

From your example it’s not exactly clear what you’re trying to do, it’s just a big mess :slight_smile: I see how feeling to have to write such code can be demotivating.

Here is how I grab the results of File.list() from JS:


   public static void main(String[] args)
   {
      try
      {
         JsScope scope = new JsScope();

         System.out.println(scope.eval("importClass(Packages.java.io.File)"));
         System.out.println(scope.eval("var file = new File('M:/');"));
         System.out.println(scope.eval("var list = file.list();"));
         String[] list = scope.getVariable("list", String[].class);
         System.out.println(list);
         System.out.println(list.length);
      }
      catch (JavaScriptException exc)
      {
         System.err.println("Exception: Line " + exc.lineNumber() + ": " + exc.getMessage());
      }
      catch (EvaluatorException exc)
      {
         System.err.println("Line " + exc.lineNumber() + ": " + exc.getMessage());
      }
   }

Did my code help to cleanup your accessor-code?

Sorry Riven, I missed your post!

It looks like your class would handle a lot of what I was annoyed with. Hard to believe the Rhino API doesn’t have something like that already. However, I decided to go ahead with my project (Scar) with just Java code, and I think that was a good move. It forced me to make the API simple and concise in Java, rather than relying on a scripting language to make it easy to use. This way the core of it is tight, and a scripting language can still be used later. Right now I’m just using the JDK6 compiler to compile and run Java snippets on the fly.

As an aside. Dynamic typed language advocates will argue that strongly typed language are hard to maintain. You have to keep rewritting the same pieces of code, over and over to provide a given functionality over a specific (potentially root) type. This code duplication requires time to create and for any needed code modification (bug, optimization, etc) then all the copies have to be tracked down and modified. All of these things decrease productivity and increase the probability of bugs.

That’s interesting.

Interfaces are meant to solve that problem though aren’t they? If you code to an interface then anything can implement the interface and it works out.

I used to try and make interfaces everywhere but it just ended up very verbose to have an interface for everything, because effectively it’s like writing code twice - once for the interface which has the method declarations and once for the implementing class. And it’s not easy to modify things because you have to change the interface and all of the implementing types.

I think sorting is a good example here, check you the code in Arrays:

Arrays.sort(byte[]) Arrays.sort(short[]) Arrays.sort(char[]) Arrays.sort(int[]) Arrays.sort(long[]) Arrays.sort(float[]) Arrays.sort(double[]) Arrays.sort(Object[])

It’s a lot of duplicated code. C has templates, C# has generics supporting primitives, but in the end, you either have to write the different implementations yourself (Java), or let them be generated (C/C++/C#), but you end up with duplicated code. In dynamically typed languages, you have this code exactly once, even in memory. It will figure out everything at runtime, as a huge performance cost, ofcourse.