On Java and C++

W

Walter Bright

Gernot said:
The so called "ugly" features is what makes C++ so powerfull.

I don't agree with the fatalistic idea that a feature must be ugly in
order to be powerful. The warts in C++ are not due to its power, but to
its desire to integrate new features in while retaining source
compatibility with 30 years of past decisions, good and bad.

If you're willing to give up legacy compatibility, it's possible to
design a language with similar and even greater power, but in a much
simpler and straightforward package. Such is the D programming language,
www.digitalmars.com/d/

For an example of how an "ugly" power feature like templates can be made
easier (and even more powerful), see
www.digitalmars.com/d/templates-revisited.html .


-Walter Bright
Digital Mars
 
B

Bent C Dalager

I hate feeding trolls but it is just unfair for C++...

I learned Javascript before C++. My impression is even though C++ is
noticeably more complex, it is not more difficult to learn than Javascript.

That may say more about Javascript than it does about C++ though :)

(Personally, I found ECMAScript pretty straight forward up until I
reached the chapter of the spec titled "automatic semicolon
insertion". It went downhill from there <g>)

Cheers
Bent D
 
G

Gernot Frisch

Walter Bright said:
I don't agree with the fatalistic idea that a feature must be ugly
in order to be powerful. The warts in C++ are not due to its power,
but to its desire to integrate new features in while retaining
source compatibility with 30 years of past decisions, good and bad.

If you're willing to give up legacy compatibility, it's possible to
design a language with similar and even greater power, but in a much
simpler and straightforward package. Such is the D programming
language, www.digitalmars.com/d/

For an example of how an "ugly" power feature like templates can be
made easier (and even more powerful), see
www.digitalmars.com/d/templates-revisited.html .

OK. True, the D language has cleaned up old C inheritances C++ suffers
from. However, I doubt anyone would switch to D unless you provide a
large class library for almost everything. That's the only true
benefit of Java, the large std library.

I hope to see D grow and be _the_ (C++)++ one day, though.
 
M

Mishagam

OK. True, the D language has cleaned up old C inheritances C++ suffers
from. However, I doubt anyone would switch to D unless you provide a
large class library for almost everything. That's the only true
benefit of Java, the large std library.
Yes, large standard library helps. However Perl, Python, C# have
something close.
I would give additional benefits (for me).
a) You don't have to think should you include fields of have variables
as objects or references or pointers. It is decided for you usually
close to optimal way (closest to references).
b) You don't have to bother to use auto_pointer (not working with
collections) or new delete or automatic destructor. It is decided for
you to use something like auto_ptr but much better.
c) You don't have to decide about programming style. Sun provided
standard Java style.
d) You don't have to decide about naming of files and classes - they are
the same.
e) Logical package directory structure is forced on you.
f) You don't have to choose between char *, string, CString ... - String
is better (or same) than either of them and it is only choice.
g) you don't have to choose between long int, unsigned int, WORD, DWORD,
size_t .... - close to optimal choice if forced on you.
h) You don't decide do you use internal or external functions
definitions, or do you use macro. - close to optimal choice if only one
possible.
i) You don't have to decide if you use methods or define new operators.
Java choice is sometimes more verbose, but usually more clear.
....
As you can guess, I can continue.
Dropping all these choices first - makes programming easier, you have
less things to bother about, second - makes language smaller and more
easy to understand. Of course such approach could lead to very bad
language - but Java luckily has good design. And I thing C++ standard
committee just made bad design - introducing complexities which doesn't
add enough benefits to justify them.
 
G

Gernot Frisch

a) You don't have to think should you include fields of have
variables
as objects or references or pointers. It is decided for you usually
close to optimal way (closest to references).

What about pointer to a pointer? A pointer is a pointer, a reference
is a reference, a variable is a variable. Period.
b) You don't have to bother to use auto_pointer (not working with
collections) or new delete or automatic destructor. It is decided
for you to use something like auto_ptr but much better.

I like new/delete. Makes me feel I'm in charge. Just my .02$

c) You don't have to decide about programming style. Sun provided
standard Java style.
Juck!

d) You don't have to decide about naming of files and classes - they
are the same.

no, they _have to be_ the same. Otherwise the compiler pukes.
e) Logical package directory structure is forced on you.

What about freedom of choice?
f) You don't have to choose between char *, string, CString ... -
String is better (or same) than either of them and it is only
choice.

Yeah, and a lot slower in some cases. User std::string where you need
dynamic strings, use char[] where you need static strings. You don't
have to - but you _can_!
g) you don't have to choose between long int, unsigned int, WORD,
DWORD, size_t .... - close to optimal choice if forced on you.

Just a question of style. I use the built-in tpyes for everything.
h) You don't decide do you use internal or external functions
definitions, or do you use macro. - close to optimal choice if only
one possible.

That's a real feature of java and D! Include files totally suck!
Internal functions are a great benefit as well. Though I'd not want to
loose the preprocessor.
i) You don't have to decide if you use methods or define new
operators. Java choice is sometimes more verbose, but usually more
clear.

?? I don't understand that. You can't define operators in Java, can
you? Defining operators is one of the most important things for OOP
IMHO.
And I thing C++ standard committee just made bad design -
introducing complexities which doesn't add enough benefits to
justify them.

Well, if you knew C++ as good as Java, you wouldn't say so I guess.
Anyway - I don't give a **** about what others use to write stuff, so
this is all just blahblah about nothing. There's no point making one
language better than the other. You will pick what suits you best or
what your boss indoctrinates on you.
 
R

REH

Luc said:
Java is simpler, cleaner - but programming is programming.

Yeah, and that's why I write real-time systems in Perl. Languages are
tools. Use the right one for the right job. No language has yet
filled the "one-size-fits-all" catagory.

REH
 
R

Remon van Vliet

I normally dont get involved with pissing contests, but there's only so much
bs in a single post i can take without replying...

I like new/delete. Makes me feel I'm in charge. Just my .02$

So, your entire reasoning behind preferring manual memory managment over
garbage collection is that "you feel in charge"? You should give assembly
language a go. Meanwhile, in the real world most recent garbage collectors
outperform manual memory managment in the vast majority of applications, and
as a bonus you get the complete lack of memory leaks and such.

I'll grant you that it's a matter of taste, but no self respecting developer
will consider standards a bad thing. If you do, draw your conclusions.
no, they _have to be_ the same. Otherwise the compiler pukes.

And the ability to stick tons of classes in a single file with a non-related
name would be a good thing because....? Again, standards -> good
What about freedom of choice?

Can you think of a single instance where having an illogical directory
structure is preferred over a logical one?
f) You don't have to choose between char *, string, CString ... - String
is better (or same) than either of them and it is only choice.

Yeah, and a lot slower in some cases. User std::string where you need
dynamic strings, use char[] where you need static strings. You don't have
to - but you _can_!

When was the last time you benchmarked Java strings vs. C++?
Just a question of style. I use the built-in tpyes for everything.

It's freedom that doesnt add anything but confusion and hurts readability.
?? I don't understand that. You can't define operators in Java, can you?
Defining operators is one of the most important things for OOP IMHO.
He's not claiming you can, he simply says the exact same functionality can
be achieved albeit more verbose (i.e. .add rather than +). There are
certainly instances where operator overloading provides more readable code,
but at the same time it can also be the cause of rather unpredictable code.
On this point my stance is that if used with care operator overloading is a
pretty neat thing.
Well, if you knew C++ as good as Java, you wouldn't say so I guess.
Anyway - I don't give a **** about what others use to write stuff, so this
is all just blahblah about nothing. There's no point making one language
better than the other. You will pick what suits you best or what your boss
indoctrinates on you.

Ofcourse there's a point in making languages "better" or at least different
than others. Sometimes a language is simply outdated, sometimes it's just
not a viable option for certain applications (people generally dont write
web-based application in C++ for example, just as you wont find many
commercial games or OSs written in Java). As for bosses, people usually get
a job based on their language skills and preferences, not the other way
around.

Anyway. there's room for both, but most of your arguments in the post above
are flawed or outdated in my opinion, as i feel you're considering rather
obvious weaknesses of C++ to be benefits. And to the OP, anyone claiming C++
programmers are somehow better than Java programmers is a tool. 90% of
skills related to being a "good developer" is completely unrelated to the
language you're using.
 
R

Remon van Vliet

Bent C Dalager said:
That may say more about Javascript than it does about C++ though :)

We're all aware Javascript is completely unrelated to Java right?
 
R

Remon van Vliet

Luc The Perverse said:
Learning C++ is marginally more difficult than learning Java.

I used to be a die hard C++ advocate - but the added complexity doesn't
really add a great deal of usability; but it is great for obscuring the
meaning of the code.

Java is simpler, cleaner - but programming is programming. Java is
designed to be able to more easily make integrated GUI apps. This might,
in turn, make the code of two programmers with otherwise equal talent, one
in C++ and one in Java, differ and their end results differ. In C++ you
have to reinvent the wheel all the time. Except, it's not like you're
rediscovering, just annoyingly doing the same thing repetitively to take
up more time. In Java you implement one of the provided algorithms, and
you are good to go, with an exponentially smaller possibility that the
underlying algorithm code is in some way flawed. (With as many Java users
as are out there, a bug should pop up pretty quick.) GUIs are easier, in
general, so the java programmer can use that time to make their GUI
better. Web examples (sample code) tend to work, unlike C++ where if you
download something, there is only a miniscule chance that it will compile
after 20-30 minutes of fiddling.

Blah - I'm just blabbering. My point is that coding in Java saves times,
and lessens bugs. It will make the end result better. All the bad
things I thought of Java are pretty much gone.

The reason I am replying is you just seem to have contempt. "Actual
Programming" problems will arise, they will just be less mundane.

I think you might be confusing Java with VB.

Trust me though - you can practice algorithms and data structures in
Java - I do so at least 3 times a week on topcoder.

Well said. "Actual programmers" shouldnt spend a large chunk of dev time on
things like standard data structures, memory managment and well known
algorithms.
 
T

The Ghost In The Machine

In comp.lang.java.advocacy, (e-mail address removed)
<[email protected]>
wrote
Java programmers seem to always be whining about how confusing and
overly complex C++ appears to them. I would like to introduce an
explanation for this. Is it possible that Java programmers simply
aren't smart enough to understand C++?

This is not merely a whimsical hypothesis. Given my experience with
Java programmers --- the code they write and the conversations they
have --- Occam's Razor points to this explanation. For example,

"Oooh I'm confused about the difference between pointers, references,
and objects! How confusing!"

[rest snipped]

First rule of software: know thy tools. This includes
the computer, the compiler, and the environment.

Both Java and C++ aim for a niche: the specification of
instructions to a modern computer. There are, of course,
many differences.

[1] Java hides pointers. This can be a good or a bad
thing; it's good in that Java has the option of playing
garbage collect (built in). It's a bad thing when Java
developers forget and leave an object to moulder in
a global collection map and then wonder why there's a
"memory leak".

[2] Java does not have operator overloading. C++ does.
In C++, this can be a convenience but it also can lead to
some hairy expressions.

[3] Java does not have a C preprocessor. C++ does. And
one thought operator overloading was bad. The Obfuscated
C process is testimony to some of the abuses of a useful
construct; fortunately those are for humorous purposes.

[4] C++ doesn't have packaging. Java does. While there
are some quirks in the implementation of packaging in Java,
it's a very nice way to organize one's code.

[5] Java doesn't have explicit deletes. The garbage
collection is expected to take care of things. (There are
some exceptions; a FileOutputStream for example will be
left open indefinitely, even if the reference is lost.)

There's a fair number of others but these will do for a start.

In any event, many programmers, myself included, migrated
from C++ to Java. To call us stupid invites ridicule, if
not worse.

As for operator overloading -- I'll admit, I occasionally
miss it. Matrix operations in particular would benefit
somewhat from a shortening of the notation; one could write
P = M * N instead of P = M.multiplyBy(N). But operator
overloading does complicate the language, requiring the
compiler to sort out whether an operator is overloaded or
not (and operator precedence issues). In Java it would
be especially bad as the operator may require a run-time
lookup.

If one assumes that an operator can be declared by the pseudo-code
(which looks suspiciously like C++, of course :) )

String operator+ (String x, String y)
{
StringBuffer z = new StringBuffer();
z.append(x);
z.append(y);
return z.toString();
}

Integer operator+ (Integer x, Integer y)
{
return new Integer(x.intValue() + y.intValue());
}

and then have a code sequence

Object a;
Object b;
Object c = a + b;

what operator should be executed, and when should this be determined?
C++ doesn't have this problem, as all routines are determined at
compile time except for virtual methods.

It is possible Java could implement a C++-like solution (and complain
in the above case as I've not defined operator+(Object,Object)) but
someone will probably be unhappy with whatever solution is finally
implemented.

One can also compare Java to C#. I lack expertise in C# beyond what
I've seen in the press but know that C# has the interesting property of
converting an assignment:

a.b = c.d;

into a sequence of function calls:

a.setB(c.getD());

by a declaration within the classes somehow.

This can get arbitrarily tricky. I'm not sure if I like this property
or not. As I understand it, interactions with [] further complicate
things.

Java avoids all this; except for an issue that one can have variable
lengths in each array row in an Object[][] variable (which is easy
to resolve with some care), one can be sure that

a.b = c.d;

means

a.b = c.d;

:)
 
B

Ben

REH said:
Yeah, and that's why I write real-time systems in Perl. Languages are
tools. Use the right one for the right job. No language has yet
filled the "one-size-fits-all" catagory.

REH

I've programmed both in JAVA and C++

Try writing a OS in JAVA...wait is that even possible?

or try writing web based programs in C++, get ready for a headache...
 
M

Mishagam


You don't like Sun Style? I find it not worse than any other, and it has
advantage that most Java programmers use it. In C, for example, Linux
core uses one style, and Gnu uses other, incompatible style, and
Microsoft, of course, uses third.
no, they _have to be_ the same. Otherwise the compiler pukes.

Of course everything I wrote here (style is exception) is enforced by
compiler. That's what compiler is for.
What about freedom of choice?

My main idea in my post was that freedom of choice is often Bad. Anyway,
I don't insist on this as a law, only as my personal preference. May be
you value freedom of choice in programming more. Then C++ obviously has
advantages for you.
f) You don't have to choose between char *, string, CString ... -
String is better (or same) than either of them and it is only
choice.

Yeah, and a lot slower in some cases. User std::string where you need
dynamic strings, use char[] where you need static strings. You don't
have to - but you _can_!

I benchmarked strings long time ago. My impression - C strings are much
faster, STL/CStrings have about the same speed (I don't remember
exactly) as Java strings. But C strings created their own (apparently
very big) category of security breaches. Bottom line - you don't lose
much, if anything, by sticking to Java strings.
Just a question of style. I use the built-in tpyes for everything.

And I am a little bit sick of casting size_t to int. Or remembering what
to use: long long or _int64.
Well, if you knew C++ as good as Java, you wouldn't say so I guess.
I suspect it is not my fault that I better know Java than C++. I spend
10 years programming mostly on C++ and only 5 years mostly on Java. It
is just more easy to learn Java.
 
R

REH

Ben said:
I've programmed both in JAVA and C++

Try writing a OS in JAVA...wait is that even possible?

or try writing web based programs in C++, get ready for a headache...

I don't know if you are agreeing with me or just misunderstood my
statement.

REH
 
T

The Ghost In The Machine

In comp.lang.java.advocacy, Ben
<[email protected]>
wrote
I've programmed both in JAVA and C++

Try writing a OS in JAVA...wait is that even possible?

It's been done, although AFAIK it didn't fare all that well in the
marketplace.

http://en.wikipedia.org/wiki/JavaOS

A freeware variant is also active. This one looks rather interesting,
although the compatibility list is a little skimpy...but then, that's
why freeware is such fun; someone will write those drivers (and one
might port them from equivalent Linux drivers) if they need them.

http://www.jnode.org/
or try writing web based programs in C++, get ready for a headache...

Not as bad as one might think if one avoids pointers and
sticks to the Standard Template Library. However, Java
may very well be more efficient under those conditions,
as it copies pointers instead of entire structures.

There is one thing missing from Java, the equivalent
of std::multiset<> and std::multimap<>. However, the latter
can be replaced by std::map<..., std::list<>>, and I don't
know of any really good uses for the former offhand that
wouldn't be better served by a std::multimap<> or a
std::map<...,std::list<>>.
 
R

Roedy Green

I agree that may be C++ programmers are smarter.

There are two meaning for smarter.

There is a the sort of guy who can keep his home books doing all the
arithmetic in his head.

There is the sort of guy who uses an adding machine with a tape for
verification.

The first has more raw skill. The second gets the job done more
accurately with less effort, and gets to go fishing sooner.
 
N

Noah Roberts

Mishagam said:
c) You don't have to decide about programming style. Sun provided
standard Java style.
d) You don't have to decide about naming of files and classes - they are
the same.
e) Logical package directory structure is forced on you.

Three things I _really_ hate about Java.
f) You don't have to choose between char *, string, CString ... - String
is better (or same) than either of them and it is only choice.

Actually, you are in err. Java also has char[] and there is nothing
stopping someone from using it or designing a new String. Therefor
Java suffers from the same "problem" as C++ here except there are no
Java functions and tools to work with char[]...you have to write them
from scratch.
g) you don't have to choose between long int, unsigned int, WORD, DWORD,
size_t .... - close to optimal choice if forced on you.
h) You don't decide do you use internal or external functions
definitions, or do you use macro. - close to optimal choice if only one
possible.
i) You don't have to decide if you use methods or define new operators.
Java choice is sometimes more verbose, but usually more clear.
...
As you can guess, I can continue.

Yes, but all the benefits you are listing are things you *can't* do and
the things forced upon you. Where are the list of things you *can* do?
You make Java sound like a jail sentance.

I don't think one is better than the other but common, these are just
bad arguments.
 
R

Roedy Green

a) You don't have to think should you include fields of have variables
as objects or references or pointers. It is decided for you usually
close to optimal way (closest to references).

This is a huge benefit. There are so many addressing modes in C++ that
really don't buy you much other than confusion.

The other huge benefit is platform independence. Java has everything
removed that would temp you to write platform dependent code.

Granted I tend to use a very vanilla style of coding, but platform
specific problems just don't happen to me.

Even writing something as UI-free as a compiler takes a huge amount of
platform-adjusting application code. In Java, that his already
handled by standard libraries.
 
R

Roedy Green

I like new/delete. Makes me feel I'm in charge. Just my .02$

The problem is a bit like "feeling in charge" at a 747 control panel.
You know you are not up to the job for any serious app.

I used to use Numega to track leaks in a C/C++ team's code. It was
not a matter of fixing them, but getting them down to a dull roar.

Mixing exception handling and memory management boggles the human
mind.
 

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,774
Messages
2,569,598
Members
45,150
Latest member
MakersCBDReviews
Top