POV-Ray : Newsgroups : povray.general : POV-CSDL (or Java Binding?) : Re: POV-CSDL (or Java Binding?) Server Time
10 Aug 2024 09:16:53 EDT (-0400)
  Re: POV-CSDL (or Java Binding?)  
From: Nieminen Juha
Date: 12 Mar 2000 13:24:40
Message: <38cbe0e7@news.povray.org>
Jon A. Cruz <jon### [at] geocitiescom> wrote:
: Well, it seems you have been misinformed. C++ has some horribly ugly things
: that are intentionally kept out of Java, while C++ had to keep back-wards
: compatibility with C and also add new OO support.

  The fact that it has ugly things doesn't mean you have to use them.

  When I try to code with Java I feel more like I am being limited and that
handy features that I would like to use to make my work easier have been
taken out, thus making my life harder. Many times some handy shortcuts in C++
(like typedef, enum, etc) have been left out of Java, and altough you can
do the same thing with other ways, it's usually a lot of extra work (for
example defining lots of const variables with their initial values instead
of just typing their names into an enum). They are often little things, but
annoying nevertheless.

  Here are some annoyances about Java I have found that usually forces you
to make _BAD_ code:

  - The enum type has been left out:
    This means that you have to define a series of values by declaring constant
    variables with their respective initial values. If you want to add a new
    name in the middle, you have to change the numeration of the rest of the
    names.
    The order of the numeration can be important, for example when sorting or
    if the names are someway hierarchically defined.

  - The typedef declaration has been left out:
    Which means that you must use the specific data type when making the code,
    instead of using an 'alias' type. This means that if you want to _change_
    that data type later, you have to do it in _tons_ of places instead of
    just in one place.
    Of course the most correct way is to use only class-types, which can be
    modified later without needing to modify the code. However, since there's
    no operator overloading, you will need to make a lot extra work to make
    your code if you just want to use integers or similar. See also:

  - No operator overloading:
    Since you can't overload operators, you have to make all method calls
    explicitly. This may be a good thing in the sense that you really see
    what's happening. However this makes the code very unreadable.
    Just suppose this case:
    You have defined your own Complex-class type which handles complex
    types. In C++ you could do something like:

    Complex i(2,3),j(4,5);
    i = (i*j) + (i/j)*3 + j/2;

    In Java, since we don't have operator overloading, all that has to be
    done with method calls, like this:

    Complex i(2,3),j(4,5);
    i.set(Complex.sum(Complex.sum(Complex.mul(i, j),
          Complex.mul(Complex.div(i, j), 3)), Complex.div(j, 2)));

    Which one is more readable? Which one is easier to debug?

    It also makes copying one class instance into another more difficult
    (specially if the class has many variables).

  - There is multiple inheritance of interfaces, but not multiple inheritance
    of classes:
    I just ask why? Why you are allowed to inherite multiple interfaces but
    not multiple classes?
    Why is this bad? It's bad because if you want to inherit your class from
    several interfaces (allowed in java for some reason), you will have to
    implement all of their methods! If you want to inherit a certain interface
    to several different classes, you will have to implement those same
    methods in all of them, even if they were identical!
    This means that you are copying the same code to several places, which
    is a BAD THING.
    At least in C++ you can specify default implementations for all methods
    that are not likely to be changed in inherited classes. In Java you can't
    do this if you want to inherit more than one interface.
    Someone may argue that don't use multiple inheritance then. I would just
    ask that why is it then possible in Java in the first place? If multiple
    inheritance is such a bad thing, why is it included in Java then? And
    included in a way that forces you to make bad code if you want to use it.

  - Pointers has been removed.
    Ok, this is a good thing if it were true. It isn't. I would say that
    _everything_ in java is handled with pointers (except integer and other
    basic types). Their use is limited, which is a good thing, and they are
    named references. The syntax has been designed so that it hides those
    references behind it.
    I'm not saying that C++ is better in this way, but in my opinion this
    deliberated hiding of references in the syntax makes code more prone to
    confusions (at least for me).
    Consider these two examples:

    void F(int x)
    { x = 5;
    }

    void F(complex x)
    { x.set(5);
    }

    The syntax of the function definitions are quite the same. There's nothing
    that indicates that the first function DOES NOT modify the original
    variable given as parameter to the function, while the second function
    DOES modify the original value.
    You just have to know that it works this way.
    Yes, I know C++ is full of similar things, but I'm not saying that C++
    is better in this way. In this specific case it might be a little better,
    in my opinion.

  - No templates:
    You have to make separate functions to handle classes and basic types.
    You can't make generic functions that work with everything (eg. swap).

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):5;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.