We have the following scenario:
- There is a program (already written) in Java which runs on a server (in the web). Let's call it
JavaServerProgram. It takes user input, calculates stuff and finally generates a bunch classes. Let's call these classesJavaClasses. All these classes are serializable to json. - There is a library (already written) in C# that contains many classes describing a tree-like data structure. Let's call it
C#Data. Let's call the root classC#Root. All classes inC#Dataare (de-)serializable to/from json. - The bunch of
JavaClassesthatJavaServerProgramoutputs can be converted into aC#Rootinstance. We have a library written in C# for that which takes json representations of theJavaClassesas input and creates aC#Rootinstance. Let's call itC#Convert. This library will always be needed by another project; i.e. it can not be discontinued. - There is a program (already written) in C# that takes an instance of
C#Rootand does some actions (like shown a GUI, modifying files, ...) on a client. Let's call itC#ClientRun.
The workflow should be like this:
JavaServerProgramruns on the server and outputsJavaClasses.- The
JavaClassesare converted into aC#Rootinstance on the server. C#ClientRungets theC#Rootinstance as input and runs on the client.
The question is, how do we implement the whole thing?
Version A:
We use all already existing programs and libraries. That means:
We modify
JavaServerProgramso that after creation of theJavaClasses, it serializes them into jsons and outputs them.We write a C# program that takes the json representations of the
JavaClassesfromJavaServerProgramas input, usesC#Convertto create aC#Rootinstance, serializes theC#Rootinstance to json and outputs it.
Then, after JavaServerProgram has run, we run that C# program and finally send the resulting C#Root json to the client where it will be derserialized into a C#Root instance and input into C#Run.
Pro: We use existing code.
Con: We have overhead due to
- the conversion being an own program (it takes time and memory for the OS to manage it),
- "media discontinuity": Instead of directly converting the
JavaClassesintoC#Root, we must serialize them to json (in Java) to be able to send them to the converter. (The converter does NOT deserialize them toJavaClasses, though. It processes the jsons directly.)
Version B:
We make a Java clone of C#Covernt, i.e.
- we duplicate all classes from
C#Datain Java as well as their ability to be serialized to json, - we duplicate the conversion algorithm in Java but without using jsons in-between, i.e. we directly convert from
JavaClassestoC#Root.
Then we extend JavaServerProgram to contain the above clone, i.e. after creation of the JavaClasses it converts them into a C#Root instance and serializes it to one json. Then we send that C#Root json to the client where it will be derserialized into a C#Root instance and input into C#Run.
Pro: We have no own-program-overhead and no "media discontinuity".
Con: We need to maintain the C#Data classes and the conversion algorithm in two languages (C# and Java).
Version C:
We find a way to write code both in C# and Java but compile it to some common intermediate language that runs in one shared environment (like JVM / .NET-VM).
Pro: No duplicate code and no overhead/"media discontinuity".
Con: Cannot see any. (The time needed to get to know this new environment does not count as a con since it will be just invested once.)
Can anyone elaborate pros and cons from a practical perspective? Like:
- Version A: Will the expected overhead be relevant? Or is it going to be small?
- Version B: Is maintaining duplicate code in different languages practical? Is it common? Are there tools to assist? (Maybe there are tools that can automatically convert from C# to Java?)
- Version C: Does such an environment as described exist? Which one? Has anyone experience with it?