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

Discussion in 'Python' started by cjl, Mar 28, 2005.

  1. cjl

    cjl Guest

    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
    cjl, Mar 28, 2005
    #1
    1. Advertising

  2. cjl wrote:

    > 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
    Patrick Useldinger, Mar 28, 2005
    #2
    1. Advertising

  3. cjl

    Guest

    Patrick Useldinger wrote:
    > cjl wrote:
    >
    > > 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++.


    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++.
    , Mar 28, 2005
    #3
  4. cjl

    Harry George Guest

    "cjl" <> writes:

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

    --

    6-6M21 BCA CompArch Design Engineering
    Phone: (425) 294-4718
    Harry George, Mar 28, 2005
    #4
  5. cjl

    Kent Johnson Guest

    cjl wrote:
    > 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
    Kent Johnson, Mar 28, 2005
    #5
  6. wrote:
    > Patrick Useldinger wrote:
    >
    >>cjl wrote:
    >>
    >>
    >>>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++.

    >
    >
    > 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
    Stefan Seefeld, Mar 29, 2005
    #6
  7. cjl

    Roy Smith Guest

    In article <>,
    "cjl" <> wrote:

    > 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.
    Roy Smith, Mar 29, 2005
    #7
  8. cjl

    Guest

    Patrick Useldinger wrote:
    > 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
    , Mar 29, 2005
    #8
  9. cjl

    Roy Smith Guest

    wrote:

    > There is a difference between theory and practice.


    You know the difference between theory and practice? Well, in theory,
    there is no difference :)
    Roy Smith, Mar 29, 2005
    #9
  10. wrote:

    > Patrick Useldinger wrote:
    >>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++.
    >


    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
    Patrick Useldinger, Mar 29, 2005
    #10
  11. cjl

    cjl Guest

    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
    cjl, Mar 29, 2005
    #11
  12. cjl

    Bill Mill Guest

    On 29 Mar 2005 11:02:38 -0800, cjl <> wrote:
    > 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
    Bill Mill, Mar 29, 2005
    #12
  13. cjl wrote:

    > 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!

    ;-)
    Patrick Useldinger, Mar 29, 2005
    #13
  14. 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.
    Peter Herndon, Mar 29, 2005
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. b83503104
    Replies:
    5
    Views:
    577
    KC Wong
    May 25, 2004
  2. Replies:
    5
    Views:
    413
  3. Herman
    Replies:
    16
    Views:
    608
    Mark Shaw
    May 27, 2004
  4. ToddLMorgan
    Replies:
    17
    Views:
    475
    Lawrence D'Oliveiro
    Apr 27, 2006
  5. Daniel Gee

    Translating some Java to Python

    Daniel Gee, May 20, 2007, in forum: Python
    Replies:
    9
    Views:
    286
    Gabriel Genellina
    May 21, 2007
Loading...

Share This Page