hlovdal
hlovdal

Reputation: 28180

Effort needed to port from C to Java

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).

Upvotes: 0

Views: 2425

Answers (5)

Artelius
Artelius

Reputation: 49089

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.

Upvotes: 2

Paul de Vrieze
Paul de Vrieze

Reputation: 4918

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.

Upvotes: 2

CPerkins
CPerkins

Reputation: 9018

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.

Upvotes: 12

Joachim Sauer
Joachim Sauer

Reputation: 308031

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.

Upvotes: 2

Kieveli
Kieveli

Reputation: 11075

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.

Upvotes: 3

Related Questions