views:

47

answers:

2

I am an iOS developer and I found a great library that handles all kinds of astronomy related calculations for me. The problem is that it's written in Java. Although I have enough experience with languages close to Java, I can't run Java on iOS.

I'd like to port it, but being that I've never ported anything before. Like I said, I don't think language will be the issue. It's a fairly simple library, involving mostly Date objects and math.

I'm trying to figure out the best way to do go about porting. Do I start with the core methods/functions of each class, or can I just go line by line in each file until I have translated everything?

+2  A: 

Just start wherever you please. Generally, you'll want to start near the core, and work your way out. Just remember these three steps:

  1. Make it work
  2. Make it right
  3. Make it fast/clean

So don't worry about getting it looking pretty or anything right off the hop, just get it working how it needs to, test it. Then look at where you can refactor if possible, etc.

jer
Great points. I do have this bad habit of trying to make code clean the first time around.
Moshe
+1  A: 

Since this seem to be a library of functions, it would not depend on any platform specific functions.

Porting this should really be straightforward. You can port function by function, maybe start with functions that are important for your app.

The really tricky part (given it's a math lib) will be assuring that it works correctly: you should have the same set of unit tests as original lib. The best would be to create a java wrapper classes that call your lib via JNI so that you could run original unit tests on your lib. Pure Objective-C lib (no platform bindings) should run on both OS X and iOS, so you can run tests on OS X. Do something like this:

  1. Look at original Java lib, and create functionally similar API in Objective-C: Same classes, same method names.
  2. Take the original java classes and replace all content of methods with JNI calls to your native library.
  3. Implement functionality in your lib.
  4. Run java unit tests (which now calls your native lib) to make sure your lib works correctly.

For easier JNI development you can use JNA or any other JNI wrapper listed here.

Peter Knego
Thanks so much!
Moshe
You're welcome.
Peter Knego