Which is easier? Translating from C++ or from Java...

C

cjl

Hey all:

I'm working on a 'pure' python port of some existing software.

Implementations of what I'm trying to accomplish are available (open
source) in C++ and in Java.

Which would be easier for me to use as a reference?

I'm not looking for automated tools, just trying to gather opinions on
which language is easier to understand / rewrite as python.

-cjl
 
P

Patrick Useldinger

cjl said:
Implementations of what I'm trying to accomplish are available (open
source) in C++ and in Java.

Which would be easier for me to use as a reference?

I'm not looking for automated tools, just trying to gather opinions on
which language is easier to understand / rewrite as python.

Depends on what language you know best. But Java is certainly easier to
read than C++.

-pu
 
W

woodsman

Depends on what language you know best. But Java is certainly easier to
read than C++.

There's certainly some irony in those last two sentences. However, I
agree with the former. It depends on which you know better, the style
of those who developed each and so forth. Personally, I'd prefer C++.
 
H

Harry George

cjl said:
Hey all:

I'm working on a 'pure' python port of some existing software.

Implementations of what I'm trying to accomplish are available (open
source) in C++ and in Java.

Which would be easier for me to use as a reference?

I'm not looking for automated tools, just trying to gather opinions on
which language is easier to understand / rewrite as python.

-cjl

I've done a bit of manual porting from C++ and from Java, but never
for the same algorithm. Here are some points to consider:

1. Java is already garbage collected, object oriented, and generally
"safe". So an algorithm could be copied almost verbatim into
Python. In C++ you might get pointers, casts, etc. which would
leave you stumped.

2. Java as a community is trying to reinvent the wheel for everything
you might already have in a library. So whereas in C++ you might
just bind to the same library, in Java you might have to fight your
way through layer after layer of java-isms. You could end up doing
more work replicating the java-esque libraries than in doing the
actual code of interest.

Thus there is a tradeoff. For pure algorithms and
computer-science-ish programs, java may be easier. For anything that
uses libraries and API's, C++ may be easier.

As a practical matter, I have found I need to read the code and
understand it in the original language. Then, inspired by this
insight, I write a wholly new python program, using python-esque
idioms. So it comes down to which particular piece of code is easier
to understand, and that in turn depends more on the original author's
style than on the language.
 
K

Kent Johnson

cjl said:
Hey all:

I'm working on a 'pure' python port of some existing software.

Implementations of what I'm trying to accomplish are available (open
source) in C++ and in Java.

Which would be easier for me to use as a reference?

I haven't touched C++ in a long time, my experience porting Java to Jython is that it mostly
involves deleting stuff :)

I hacked together a script that does a lot of the work by applying a bunch of regex replacements.

Kent
 
S

Stefan Seefeld

There's certainly some irony in those last two sentences. However, I
agree with the former. It depends on which you know better, the style
of those who developed each and so forth. Personally, I'd prefer C++.

I don't think the OP was asking for personal preference, and so I happen
to agree with the reply: parsing Java is definitely *much* simpler than
parsing C++, no matter how well you know either. As far as manual translations
go, that is much less a matter of ease of parsing but instead how closely
programming idioms match between the two languages that are involved.
And that obviously also depends on the specific code that needs to
be rewritten and the style it is written in (i.e. for example OO vs. templates,
etc.).

Regards,
Stefan
 
R

Roy Smith

"cjl said:
Hey all:

I'm working on a 'pure' python port of some existing software.

Implementations of what I'm trying to accomplish are available (open
source) in C++ and in Java.

Which would be easier for me to use as a reference?

I'm not looking for automated tools, just trying to gather opinions on
which language is easier to understand / rewrite as python.

-cjl

My guess is you'd be better starting from the Java as a reference. So much
of C++ code tends to deal with low-level stuff like memory management and
pointers. At least in Java you won't have any of that stuff to wade
through.
 
A

alainpoint

Patrick said:
cjl wrote:
Depends on what language you know best. But Java is certainly easier
to read than C++.


There is a difference between theory and practice. In theory, Java is
easier to read than C++.
In practice however, the average Java programmer is MUCH less talented
than the average C++ programmer (let alone the average Python
programmer). The upshot of all this is that in practice (and my own
personal experience: we use both C++ and Java), Java code is bloated
with design patterns, obfuscated with many layers of indirection,
etc...
As a summary, Java code can most of the time be thrown away and
re-written from scratch (the fastest way). C++ code on the contrary can
easily be ported/wrapped.
Of course this is a matter of personal opinion. I love neither Java nor
C++. C is for me the purest language and there is no match when
combined with Python !

My 2 cents

Alain
 
P

Patrick Useldinger

There's certainly some irony in those last two sentences. However, I
agree with the former. It depends on which you know better, the style
of those who developed each and so forth. Personally, I'd prefer C++.

Not really.

If you know none of the languages perfectly, you are less likely to miss
something in Java than in C++ (i.e. no &, * and stuff in Java).

However, if you are much more familiar with one of the two, you're less
likely to miss things there.

-pu
 
C

cjl

Hey all:

Thanks for the responses...

I've found a third open source implementation in pascal (delphi), and
was wondering how well that would translate to python?

-cjl
 
B

Bill Mill

Hey all:

Thanks for the responses...

I've found a third open source implementation in pascal (delphi), and
was wondering how well that would translate to python?

cjl, I think that the responses on the list so far collectively point
the the correct answer: mu.

pick your favorite, or the most well written, or the clearest code, or
the one that contains the most 'e's, and try to translate it.
Whichever you choose, dig deep enough to get to the underlying meaning
of what's going on so that you don't end up writing another language
in python. If you do this, it doesn't matter which of the three you
pick.

Peace
Bill Mill
bill.mill at gmail.com
 
P

Patrick Useldinger

cjl said:
I've found a third open source implementation in pascal (delphi), and
was wondering how well that would translate to python?

Being old enough to have programmed in UCSD Pascal on an Apple ][ (with
a language card, of course), I'd say: go for Pascal!

;-)
 
P

Peter Herndon

If you have three different implementations, and can read all three of
them well enough to understand the code, use all three.

If you are going to port software from one language to another, and
want to reimplement it properly in your target language, you won't be
porting word-for-word anyway. So use all three sources to find out
what the problems were in the domain, and how they each solved them.
Using that knowledge, figure out the best way to tackle those same
problems in Python -- if those problems even exist.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top