doing C++ the Java way

Discussion in 'C++' started by Carmen Sei, Mar 8, 2008.

  1. Carmen Sei

    Carmen Sei Guest

    I need to write a C++ application prototype that uses a graphics
    engine in 2 weeks.

    http://openframeworks.cc/about

    I know Java pretty well, but I don't know C++.

    Can i write the C++ prototype using only Java equivalent features?

    I only use Class objects, static variable, single inheritance
    (extends), new+free()/delete(), #define

    C++ features that I don't use - no struct, no enum, no extern, no
    non-OO, no multiple inheritance, no template ... etc

    I think if I do that way, I will be able to finish my C++ prototype
    quickly, all I need to do is translate the Java program (.java) file
    into .cpp and .h file.

    Is it a good idea for a person need to finish a C++ app (about 8 - 10
    cpp files) in 2 weeks and don' t know C++?

    the app need to call some Class / Library from the graphics framework
    above and do some internet XML parsing and render data into cool
    graphics ... etc.
     
    Carmen Sei, Mar 8, 2008
    #1
    1. Advertising

  2. Carmen Sei

    Guest

    On Mar 7, 7:20 pm, Carmen Sei <> wrote:

    > Can i write the C++ prototype using only Java equivalent features?
    >
    > I only use Class objects, static variable, single inheritance
    > (extends), new+free()/delete(), #define


    First, don't use free with new, use delete. And what is the Java
    equivalent of #define?

    > Is it a good idea for a person need to finish a C++ app (about 8 - 10
    > cpp files) in 2 weeks and don' t know C++?


    Good? Sounds like a typical management decision. You can probably
    kludge something that does what you want, but make sure you burn the
    prototype and learn C++ before they ask you to flesh it out to a
    product.
     
    , Mar 8, 2008
    #2
    1. Advertising

  3. Carmen Sei

    Greg Herlihy Guest

    On Mar 7, 7:55 pm, wrote:
    > On Mar 7, 7:20 pm, Carmen Sei <> wrote:
    >
    > > Can i write the C++ prototype using only Java equivalent features?

    >
    > > I only use Class objects, static variable, single inheritance
    > > (extends), new+free()/delete(), #define

    >
    > First, don't use free with new, use delete.


    To be more "Java-like" I would not use delete either, but instead rely
    on shared_ptr's to manage allocated pointers.

      And what is the Java
    > equivalent of #define?


    Pretty much the same as it is in C++. In both C++ and Java, a (non-
    macro) #define would be replaced by a const variable declaration -
    while a #define that creates a preprocessor macro would be rewritten
    as a - in the C++ case, an inline - function.

    > > Is it a good idea for a person need to finish a C++ app (about 8 - 10
    > > cpp files) in 2 weeks and don' t know C++?


    Well, I guess in two weeks you will know the answer to that question.

    Greg
     
    Greg Herlihy, Mar 8, 2008
    #3
  4. Carmen Sei

    James Kanze Guest

    On 8 mar, 02:20, Carmen Sei <> wrote:
    > I need to write a C++ application prototype that uses a graphics
    > engine in 2 weeks.


    > http://openframeworks.cc/about


    > I know Java pretty well, but I don't know C++.


    In which case, you can't write a reasonable application
    prototype in C++ in two weeks. It's that simple.

    > Can i write the C++ prototype using only Java equivalent
    > features?


    There are fundamental differences in the language---it's not
    just a matter of feature sets, but differences in the way the
    languages work.

    > I only use Class objects, static variable, single inheritance
    > (extends), new+free()/delete(), #define


    > C++ features that I don't use - no struct, no enum, no extern,
    > no non-OO, no multiple inheritance, no template ... etc


    No extern? You mean you write everything in a single source
    file?

    > I think if I do that way, I will be able to finish my C++
    > prototype quickly, all I need to do is translate the Java
    > program (.java) file into .cpp and .h file.


    You can find a common subset of features, and only use them.
    You may even be able to get something through the compiler doing
    this. It won't have the same semantics, however.

    > Is it a good idea for a person need to finish a C++ app (about
    > 8 - 10 cpp files) in 2 weeks and don' t know C++?


    If you don't know C++, I don't think you'll be able to get
    anything reasonably working in 2 weeks. If you're talking about
    8-10 source files, it depends on what you put in the source
    file. I know that there are a lot of applications which would
    only be 8-10 classes that I couldn't do in two weeks, and I
    already know the language.

    > the app need to call some Class / Library from the graphics
    > framework above and do some internet XML parsing and render
    > data into cool graphics ... etc.


    If it's only a prototype... You're best bet (although it's still
    a long shot) would be to learn enough C++ to write a Java
    mapping in JNS, and write the actual prototype in Java. C++ is
    not a simple tool which can be learned in a few days.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Mar 8, 2008
    #4
  5. Carmen Sei

    James Kanze Guest

    On 8 mar, 07:18, Greg Herlihy <> wrote:
    > On Mar 7, 7:55 pm, wrote:


    > > On Mar 7, 7:20 pm, Carmen Sei <> wrote:


    > > > Can i write the C++ prototype using only Java equivalent features?


    > > > I only use Class objects, static variable, single inheritance
    > > > (extends), new+free()/delete(), #define


    > > First, don't use free with new, use delete.


    > To be more "Java-like" I would not use delete either, but
    > instead rely on shared_ptr's to manage allocated pointers.


    shared_ptr aren't very Java-like. To be more Java-like, he
    could install a garbage collector. But C++ with garbage
    collection isn't really very Java-like either (and you do need
    someone who really knows what they're doing to configure the
    garbage collector for your environment).

    In his case, since it's a prototype, the simplest solution is
    probably just to use raw pointers, call delete when it's obvious
    when delete needs to be called, and let the application leak a
    bit.

    > And what is the Java


    > > equivalent of #define?


    > Pretty much the same as it is in C++. In both C++ and Java, a
    > (non- macro) #define would be replaced by a const variable
    > declaration - while a #define that creates a preprocessor
    > macro would be rewritten as a - in the C++ case, an inline -
    > function.


    And a #define which plays games with program structure doesn't
    have an equivalent in Java. Going from Java to C++, he can
    pretty much ignore #define to begin with, except for include
    guards.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Mar 8, 2008
    #5
  6. Carmen Sei wrote:
    > I need to write a C++ application prototype that uses a graphics
    > engine in 2 weeks.
    >
    > http://openframeworks.cc/about
    >
    > I know Java pretty well, but I don't know C++.
    >
    > Can i write the C++ prototype using only Java equivalent features?


    Coding in C++ in the same way as you would code in Java is usually a
    bad idea. Even though they remotely resemble each other, C++ is not
    Java, and the coding principles are totally different. If you try to
    code in C++ as if you were coding in Java, you will get memory leaks
    with almost 100% certainty (yeah, bummer, but it just is like that) and
    the code will most probably be less efficient (both speedwise and
    memorywise) than doing it in the "C++ way".
     
    Juha Nieminen, Mar 8, 2008
    #6
    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. shahzad

    Problem in new way of doing??

    shahzad, Jun 25, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    1,266
    Tony Sedgwick
    Jun 25, 2003
  2. Lerp

    Standard way of doing ...

    Lerp, May 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    515
    DalePres
    May 14, 2004
  3. Morten Wennevik

    Any elegant way of doing this?

    Morten Wennevik, Nov 8, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    394
    Morten Wennevik
    Nov 8, 2005
  4. Prabh
    Replies:
    11
    Views:
    623
    Mike Baranczak
    Sep 22, 2003
  5. Replies:
    14
    Views:
    665
Loading...

Share This Page