tags:

views:

304

answers:

5

Hi, does anyone have any pointers to (rough) estimates on how much effort is needed to port an application from C to Java? Of course it will depend a lot, but would for instance using Intermediate COCOMO make sense?

Estimating how much effort is needed for writing new code is difficult, but still needs to be done. When starting from nothing there is a lot of guessing involved. If you start with an existing code base I would assume that estimating at least would be a little bit easier, and this was one of my motivations for asking, if anyone had any input on how much easier.

Any studies made that shows converting say 100 000 lines of C code will typically result in 50 000 to 100 000, or 100 000 to 200 000 lines of Java code? Converting might mean just port from C or it might mean rewrite to Java. Both will of course give different results, but both will be interesting to know (I am not looking for a single answer).

+3  A: 

I think what I would do is separate the underlying functionality of the application from the user interface. You can call C libraries through JNI. If your design cleanly separates display from underlying processing, then you can save a lot of time by only migrating the user interface.

Kieveli
+1. Don't port from C to Java, leverage the old C library from new Java code. That might require doing some work on the C code to expose an API that can be consumed by Java, but that is probably still easier than porting the entire application to Java.
Grant Wagner
+2  A: 

As the comments already mention the answer depends a lot on how close to the metal your application is working.

If your C code is almost-object oriented (passing around structs, writing methods that take pointers to those structs, ...) then a conversion can become relatively easy.

If your C code plays around a lot with pointer arithmetic, unions and maybe even some direct-hardware access then a port to Java may become almost impossible (except by "wrapping" your C code in a thin JNI/JNA layer).

And even if you manage to do the conversion, the resulting Java code will be Java by syntax only. The C heritage will still shine through and make itself known.

Joachim Sauer
+11  A: 

You're probably better off either leaving it in C, or recreating it in Java.

Here's why:

If you simply port it, you'll end up with "C written in Java". You won't get any of the benefits of having your app be in Java. You'll introduce bugs (every port introduces bugs), so your users will be unhappy. Net outcome: effort expended, unhappy users, no positive result.

By contrast, leaving it in C also means no positive result, but at least there's no effort expended.

Just for reference: if you decide to redesign the system in Java, using OO principles and Java frameworks and all of the stuff that goes with it, there's effort expended, but you get more positive results.

CPerkins
+2  A: 

It depends very much on your desired results as well as your code base. Porting to java while not really using object orientation is possible, but certainly won't win you a beauty contest. If the code itself is already sort of object-oriented that gets better. If you use all kinds of preprocessor tricks, that complicates a lot out of porting to java. Using OS calls the same (as java proper (without JNI) does not support many non-generic calls.

Paul de Vrieze
+2  A: 

Here's a very rough metric:

12 + [number of lines]/1000 - [number of comments]/50
+ [number of functions]/100 + [number of pointer variables]/50
+ [number of macros]/10     + [number of bitwise operators]/5
+ [number of #if[def]s]/3   + [number of function pointers]/2
+ [number of pointer casts and unions]/2
- [average variable name length]

You get a figure in hours.

Artelius
Interesting. Any reference to origin/what this metric is called?
hlovdal
Yeah, it's called AMUOTS metric, which is an abbreviation of Artelius' Made-Up-On-The-Spot metric.
Artelius
Though as a very rough guide it's probably not bad. The idea is not to add up how long each function/macro/pointer takes to port, rather what the number of functions/macros/pointers tells you about program complexity as a whole.
Artelius
So an empty C file takes 12 hours to port to Java? Good metric ;-)
Joachim Sauer
@Joachim: Well, Eclipse takes a few hours to load, then there's all those tests you need to write, not to mention the amount of time you laugh when you discover you're required to port an empty C file...
Artelius