user1796942
user1796942

Reputation: 3528

First time porting a library from one language to another

I am porting a library from C++ to Java. This is my first time and I am not sure about what "porting" really means? Specifically, what if the author named a variable as 'A' and I think that a better name would be 'B'. Same for methods, classes and namespaces. Also, what if I think something can be done better? Does porting mean that I should try to keep as much of the original code spirit as possible, but still allow myself freedom to improve stuff?

Thanks

Upvotes: 2

Views: 1001

Answers (3)

hd1
hd1

Reputation: 34677

When "porting" a library from one platform to another, you are porting functionality. You are not porting style of code. It isn't like in literature, where one must maintain the style of the piece, keeping in mind metaphors and iambic pentameter or what have you.

Upvotes: 1

Ian Atkin
Ian Atkin

Reputation: 6366

When porting from System A to System B, the world is your oyster. You can pretty much change anything if you believe it's an improvement. The only caveats to that are when dealing with interfaces. Say, you are porting an API, for example, it wouldn't be a good idea to name externally-available methods, as that would break something down the road. Tracing naming issues across multiple classes is a major pain.

As someone who's done a fair bit of porting from language to language, I would recommend sticking to implementation details first and foremost. A good engineering principle is to change one thing at any time. That way, when things don't run as expected, you'll know that it's your implementation that is to blame, and not some silly naming issue. And when you do come to renaming, I suppose it goes without saying, be very careful and backup often. This is one case where software versioning may save you hours of time.

Upvotes: 1

Marcus Andrews
Marcus Andrews

Reputation: 221

It doesn't necessarily have to be a one-to-one translation (and in many cases, it can't be done). Porting is just rewriting a piece of software in a different language/environment/etc. Sometimes porting will require you to tweak things and implement them in different ways altogether, so I think the last sentence of your post pretty much captures the gist of things.

I view it as comparable to translating a book from English to another language. There will be instances where judgment calls need to be made in terms of how to express the intent/function of the source material.

Upvotes: 3

Related Questions