473,889 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

On Java and C++

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

"Oooh operator overloading confuses me! The expression x + y is so
confusing, who knows what's happening with that? If x and y are
complex numbers, what the hell could x + y mean?"

"Oooh multiple inheritance is so confusing! Though I am both a father
and a programmer, I still find it so confusing how the same object can
be two different things! How confusing!"

"Oooh and virtual bases are so bizarre! I am a student --- myself
'the father' is the same student as myself 'the programmer' --- but
nonetheless the idea of virtual bases is absolutely confounding and
confusing to me!"

Again, Occam's Razor is a valuable tool here. In deciding among
competing hypotheses, choose the simplest one. To impartial observers
of indoctrinated Java programmers, the explanation is simple indeed.

Apr 26 '06
458 21648

Walter Bright skrev:
Roedy Green wrote: [snip] This is insightful, and in my experience, correct. C++ has a problem in
that the 'right' way to do things is significantly more work than the
'wrong' way. For example, instead of:

int a[3];

I am supposed to write:

#include <vector>

vector<int> a(10);

If one expects people in general to write better programs, the
programming language should be designed so that the straightforward ,
simpler expression is the right one. Doing the wrong thing should
require more work.

This principle is evident in things like power tools and aircraft
design. In the former, you've got to do extra work to remove things like
guards and safety interlocks. In aircraft design, one of the terrible
no-no's is for a mechanic hook up the flight controls backwards. So the
designers go to great lengths to make it very hard for the mechanic to
do so, hopefully hard enough so that at some point the mechanic realizes
he must be doing something wrong. If it's easy to install the flight
controls backwards, sooner or later it will be, with deadly consequences.

I do not disagree with you here. C++ is not the perfect language,
inheriting as we all know some of the bad stuff from C - including
What you can do is not teach beginners about e.g. pointers, build in
arrays and stuff like that. Just as e.g. Koenig and Moe do in their
introductory text.
Your comparison with the aircraft design is also not quite fair. When
you write software, you hopefully do lots of testing and review before
slipping anything out the door - and this testing can easily be done
without any deadly consequences. In my opinion, these dangerous
facilities in C++ come in handy in some situations (e.g. when you
implement the std::vector class!) and are very easy to avoid. The first
review will easily find them.

-Walter Bright
www.digitalmars.com C, C++, D programming language compilers

May 2 '06 #301

Bent C Dalager skrev:
In article <11************ *********@g10g2 000cwb.googlegr oups.com>,
peter koch <pe************ ***@gmail.com> wrote:

Large parts of the C++ libraries are implemented in C++.
This is also the case with Java. Even the Java compiler is implemented
in Java.

So e.g. Swing, JDBC and Vector are all implemented in Java? Without a
single JNI-call in the code? It seems my knowledge of Java needs an

Bent D
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs

May 2 '06 #302
"Oliver Wong" <ow***@castorte ch.com> wrote in message
news:9GQ5g.4422 $Fg4.335@clgrps 12...

"Walter Bright" <wa****@digital mars-nospamm.com> wrote in message
news:ia******** *************** *******@comcast .com...
Mishagam wrote:
I think the fact that nobody uses D means suggests that it has not only
one stupid feature, but a lot of stupid features.

For a stupid language nobody uses, the D programming language is doing
remarkably well, having moved up to number 19 on

(referring to http://www.tiobe.com/tiobe_index/images/tpci_trends.gif
as of May 2nd, 2006): I wonder what happened in 2004 that made Java drop
considerably, and everything else jump up a bit.

It would appear that the rise in Python users (From virtually nothing)
corresponds almost exactly with the drop in Java users. VB also rose,
which probably stole a little java use.


May 2 '06 #303

Roedy Green skrev:
On 27 Apr 2006 12:31:12 -0700, "peter koch"
<pe************ ***@gmail.com> wrote, quoted or indirectly quoted
someone who said :
This is ridiculous - like claiming you only know to drive a car with
automatic shifts because manual shifts are all to difficult. I do not
know what gear to use!
come on. There are alternate notations that generate the same
assembler code. That is a legacy wart, not a feature.

Are you talking about C++ references and C++ pointers? While they might
be identical under the covers, they have widely different semantic uses
and you can't substitute one for the other.

/Peter --
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

May 2 '06 #304
"Noah Roberts" <ro**********@g mail.com> wrote in
news:11******** *************@y 43g2000cwc.goog legroups.com:

The Ghost In The Machine wrote:
In comp.lang.java. advocacy, Walter Bright
<wa****@digital mars-nospamm.com>
on Tue, 02 May 2006 11:47:54 -0700
<co************ ********@comcas t.com>:
> Roedy Green wrote:
>> On 28 Apr 2006 00:59:19 -0700, "al pacino"
>> <si************ *@gmail.com> wrote, quoted or indirectly quoted
>> someone who said :
>>> improve your programming skills and what better tool to do that
>>> than using c++.
>> You might find the work of W. Edwards Deming interesting. He was
>> the man who taught the art of quality control to the Japanese.
>> He argues there is no point in exhorting people to be better. You
>> have to change the environment so they naturally and without
>> additional effort produce better results.
> This is insightful, and in my experience, correct. C++ has a
> problem in that the 'right' way to do things is significantly more
> work than the 'wrong' way. For example, instead of:
> int a[3];
> I am supposed to write:
> #include <vector>
> vector<int> a(10);

I'm not entirely sure of this. Ideally, of course, int
a[3]; would allow for constructs such as Java's .length,
although a workaround might be to use

#define Nsize(a) ( sizeof(a)/sizeof(*(a)) )

or some such. But it's a bit of an ugly mess, and party
because of C's "attitude of convenience" regarding arrays
and pointers.

You have arrays when you want and vectors when you want. A
std::vector isn't always warranted. Sure, 99% of the time that is
what you want, but not always.

I doubt it is 99%. Most of the time what I need is a boost::array<in t,7>,
soon to be a tr1::array<int, 7>

In short, int *b = a; is a perfectly legal assignment in C,
and it's far from clear that it should be, but presumably
nobody wanted to write int * b = &a[0] instead way back
when, or incur extra overhead in passing the length around.

Either you are passing around a length or you are somehow finding the
end each time. Java can be no different in this area even if the
language might hide that fact from you.

I would not say quite that. In Java, the array hold the length for you.
It is a property of the object you created. It is more like the tr1:array
than a raw(int a[3]) C array.
> If one expects people in general to write better programs, the
> programming language should be designed so that the
> straightforward , simpler expression is the right one. Doing the
> wrong thing should require more work.

If one can achieve consensus on the term "wrong" in this context.
Both constructs have issues; the int a[3]; allows for fast access but
nonextensibilit y; vector<int> a; has slightly slower access but
can dynamically extend the array as necessary (however, be careful
of constructs such as &a[4] in the latter case; the rug might
very well vanish from under you!).

You've of course profiled this so lets see the result...

It would vary by compiler and settings. But you are free to test this
sort of thing yourself. The main force behind the STL was Alexander
Stepanov and he has done a lot of work on testing the cost of these
Abstraction penalties.


Look at the section on Source Code.

My memory is that accessing the vector via an iterator usually had no
penalty but there was some cost to using opertor[] and more for using
vector.at(). Again, this would be compiler dependent.

May 2 '06 #305

Roedy Green skrev:
For C++ I think I would nail down the names and sizes in bits of each
primitive the way Java does.Why? If a CPU does not have a 32-bit integer or an 8-bit char or a IEEE
floating point you could then not write C++ programs on it. That seems
a severe restriction to me.

the two are not mutually exclusive.

You could do it by saying for example that int32 is a built-in type
and must have precisely 32 bits. That does not stop you from having
some other type

Not all processors have 32-bit integers. Also not all processors
floating point unit is IEEE compliant. There are processors out there
where the smallest addressable unit is 32-bits. They still have a

/Peter --
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

May 2 '06 #306

Roedy Green skrev:
On 28 Apr 2006 00:59:08 -0700, "peter koch"
<pe************ ***@gmail.com> wrote, quoted or indirectly quoted
someone who said :
It's time to come out of the bush. What adressing mode is not needed?
Anyone with a reasonable knowledge of C++ knows theyre all necesarry
C++ has more addressing modes than other languages except for
assemblers. So obviously they are not "necessary" in some absolute
sense. They are only necessary in the legacy sense. Java has only one
addressing operator.

This is not quite true. Take old fashioned Pascal as an example. Pascal
has all the adressing modes of C++. Algol has (had) more.

Java has two adressing modes - one for the ints and one for the
objects. And this approach is simple but with drawbacks.

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

May 2 '06 #307

Java Progammer Criteria?

On Thu, 27 Apr 2006 10:43:36 GMT, Mishagam <no*****@provid er.com>
a) You don't have to think [...]
Okay. No thinking when programming...
b) You don't have to bother to use auto_pointer (not working with
Never having to bother... yeah.
c) You don't have to decide about programming style. Sun provided
No decisions... right.
d) You don't have to decide about naming of files and classes - they are
the same.
Once again.
e) Logical package directory structure is forced on you.
Likes being "forced." Ugh...
f) You don't have to choose between char *, string, CString ... - String
Once again.
g) you don't have to choose between long int, unsigned int, WORD, DWORD,
size_t .... - close to optimal choice if forced on you.
Ohhh, yes, how horrid to have to actually make an informed decision. I
feel for you.
h) You don't decide do you use internal or external functions
I'm starting to see a pattern.
i) You don't have to decide if you use methods or define new operators.
There IS a *clear* pattern. Quite clear.
Java choice is sometimes more verbose, but usually more clear.
Well apparently it's *not* the Java programmer who is going to be
clear, so something has to be, right? I mean s/he is too busy not
making decisions, right. I get the feeling there would be lots of
left-over rotten food and sticky keyboards that could never be decided
upon either. Hygiene would be something to consider though.
As you can guess, I can continue.
Dropping all these choices first - makes programming easier, you have
less things to bother about,

If you were never meant to be a programmer in the first place I
guess.... Hmm, VB and Java programmer are a lot alike. A river in
Egypt, baby, a river in Egypt....

Wow, given that list I would feel more comfortable paying a monkey to
code my apps. Why pay a human just to follow the banana around when I
can get chimps to do it for less.

"Some drink at the fountain of knowledge... others just gargle."
May 3 '06 #308

Roedy Green skrev:
On 27 Apr 2006 12:45:27 -0700, "peter koch"
<pe************ ***@gmail.com> wrote, quoted or indirectly quoted
someone who said :

That is simply false - and most probably a bloody lie. About on par
with the other posts I've seen from you. Others might want to have a
look at
Have you read the book? Were in there on BIX when Stroustrup dropped
by for a month or two?

I have read the book and numerous articles from Bjarne describing the
evolution of C++.
First let me reinsert the part you accidently snipped: you wrote: Stroustrup wrote a book about his trials designing C++ called the
Design and Evolution of C++ with a sprouting oak tree on the cover. He
was heavily constrained by his committee of C users who insisted on
strict upward compatibility. The language was designed and implemented
a bit at a time. He was never permitted to have a reintegration/tidy
up phase. So tell me - where was that committee insisting on strict backward
What was those trials Bjarne faced?
What tidy up phase was he forbidden to have? I felt much better about C++ knowing at Stroustrup was on my side in
wanting a cleaner language. It was just he was not forceful enough to
persuade his committee of bosses focused on the current job (which was
not designing a new language) of the need.
When did Bjarne try to persuade his "committee of bosses" to let him
write a cleaner language?
If anyone would care to spend just a few minutes at his website, they
would find your description at best grossly misleading. As I said
before, I see it as a bloody lie.

Just a few quotes from Stroustrups homepage:
(Would he rather have created something like Java?)
No. Java isn't even close. If people insist on comparing C++ and Java -
as they seem to do - I suggest they read The Design and Evolution of
C++ (D&E) to see why C++ is the way it is, and consider both languages
in the light of the design criteria I set for C++. Those criteria will
obviously differ from the criteria of Sun's Java team. [...]Much of the
relative simplicity of Java is - like for most new languages - partly
an illusion and partly a function of its incompleteness.

(About comparing C++ to other languages)
[...]That said, I consider C++ the best choice in programming language
for a wide variety of people and applications.

(Are there features Stroustrup would like to remove from C++?)
Not really. People who ask this kind of question usually think of one
of the major features such as multiple inheritance, exceptions,
templates, or run-time type identification. C++ would be incomplete
without those. I have reviewed their design over the years, and
together with the standards committee I have improved some of their
details, but none could be removed without doing damage.

/Peter --
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

May 3 '06 #309
peter koch wrote:
Your comparison with the aircraft design is also not quite fair. When
you write software, you hopefully do lots of testing and review before
slipping anything out the door - and this testing can easily be done
without any deadly consequences. In my opinion, these dangerous
facilities in C++ come in handy in some situations (e.g. when you
implement the std::vector class!) and are very easy to avoid. The first
review will easily find them.

No comparison or analogy is perfect, but such cross-pollination from
seemingly unrelated fields can be very useful. In a former life, I
worked on aircraft flight control systems for Boeing. I learned an awful
lot about practical ways to make things safe and reliable in the
presence of unreliable, perverse human beings. A lot of those ideas
*can* be transferred to the practice of computer programming.

Airframe design testing can be done with little to no risk to life and
limb. There's very little that cannot be simulated on the ground in an
appropriately designed test rig, or in computers.

Boeing's test pilots are incredibly good. If you're lucky enough to snag
a ride on a test flight, if they happen to be looking up at the ground,
the most you'll likely get out of them is a laconic "cool".

May 3 '06 #310

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to connect to the DB I get the following exception at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2120)
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it says: usage: java fit.FitServer host port socketTicket -v verbose I think this is because I do not understand the jython mechanism for inheritance (yet).
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)) and in both cases, get the following list returned from calling getDeclaredFields() on java.lang.ClassLoader via this code snippet: Field fields = loaderClass.getDeclaredFields(); for (int i = 0; i <...
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all I´m using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in Linux there is an error. The code that fails is the following: SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); I´m sure that code is ok. In fact, I´ve found that in several...
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.