473,889 Members | 1,387 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 21629
Bent C Dalager wrote:
(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>)

Automatic semicolon insertion is one of those ideas that perennially
keeps popping back up. The trouble is, it sounds good, and it is only
after experience with it that one eventually realizes what a bad idea it
is. And then a newbie comes along, and goes through the same process
again <g>.

-Walter Bright
www.digitalmars.com C, C++, D programming language compilers
Apr 27 '06 #71
In article <e2***********@ ns.felk.cvut.cz >,
Martin Vejnár <av****@volny.c z> wrote:

Garbage collector may be good when it comes to releasing memory, but
memory is not the only resource you use. How about files, network
streams, database connections, synchronization primitives, etc?
One classic leak is putting things into event listening lists in Swing
and forgetting to remove them at the appropriate time.
A reply from "The Ghost In The Machine" has mentioned try..finally.
Whenever you use that construct to safely dispose of a resource, you're
better off using RAII.

Btw, I'm not really sure, but is the finally block executed, when you do
'return' from inside the try block?

The finally block will _always_ be entered before the method returns.
Whether the "finally" runs to completion depends on whether an
unhandled exception gets thrown in the finally-block itself. If that
happens, then the remainder of the finally block is skipped.

Bent D
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
Apr 27 '06 #72

Walter Bright wrote:
Noah Roberts wrote:
Also, you could read that article above which shows some shortcommings
of both RAII and finally. However, the "scope guard" appears to be a D
language particular construct so is rather moot in this discussion.

There's a link at the end of the article with Andrei Alexandrescu's
technique for doing a limited form of scope guard in C++.

Well, that is on my list of things to read now; I am always up for
learning new techniques...wh ether I use them or not is a different

At any rate, exception safety is not a C++ only problem. Any language
that uses exceptions has exception safety issues and so far I haven't
seen one that did any better than another in this regard.

Apr 27 '06 #73
In article <Uu************ *************** ***@comcast.com >,
Walter Bright <wa****@digital mars-nospamm.com> wrote:

Automatic semicolon insertion is one of those ideas that perennially
keeps popping back up.
I do admit to many times having run a C, C++ or Java compiler, had it
stop with a "semicolon expected" type error and cursing inwardly at it
thinking "well why don't you just _insert_ a bloody semicolon you
stupid compiler pos since you obviously realise that one is missing
right there".

In my world, however, there is a long way to go from just projecting
my own shortcomings onto the compiler and to actually implementing
complicated heuristics for trying to guess when the programmer did or
did not want a semicolon in the source code :-)
The trouble is, it sounds good, and it is only
after experience with it that one eventually realizes what a bad idea it
is. And then a newbie comes along, and goes through the same process
again <g>.

Yes, but, I used to think that this was a self-solving problem.
Newbies don't write programming languages, after all, and by the time
they have the skill required to do so, one would have thought they
were long past the "let the language just guess what I mean" stage
.. . .

Obviously not though :-)

Bent D
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
Apr 27 '06 #74
Alf P. Steinbach wrote:
* Walter Bright:
Noah Roberts wrote:
Also, you could read that article above which shows some shortcommings
of both RAII and finally. However, the "scope guard" appears to be a D
language particular construct so is rather moot in this discussion.

There's a link at the end of the article with Andrei Alexandrescu's
technique for doing a limited form of scope guard in C++.


I think you should get the attributions right (sorry, how could I put
this in a more gentle way?): ScopeGuard was Petri Marginean's invention,
and he co-authored the CUJ article with Andrei.

You're right. I apologize for the error.
Apr 27 '06 #75

"peter koch" <pe************ ***@gmail.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.com.. .

I believe most large system out there in the real world relies on C or
C++. Examples are numerous, but I could mention banking,
telecommunicati on and database management systems. I doubt you will
find any large product of this type in Java. There will be lots of Java
in the "supporting " infrastructure of course - most likely my
homebanking solution is Java. But all the "real" and "heavy" stuff is
most likely C/C++.

You're wrong. I don't know about telecommunicati on and DBMS, but for
banking, insurance and other "large systems" in the "real world", it's
mostly COBOL, and the businesses are looking to migrate their code to Java
or .NET. The reason I know this is that I work for a porting and migration
company (Castor Technologies) and we often get contracts from banks,
insurance companies, educational institues and the governments asking to
migrate their COBOL stuff to the above two platforms.

For what it's worth, usually for educational institutes they want to
switch to .NET, and everyone else wants to switch to Java.

- Oliver

Apr 27 '06 #76

"Noah Roberts" <ro**********@g mail.com> wrote in message
news:11******** ************@u7 2g2000cwu.googl egroups.com...

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

Well, that is one area where Java *can't* be used then isn't it.

Another can't. Where is the can?

I think it's a bit silly to complain that you *can't* write platform
dependent code in Java.

If you goal is to intentionally write platform dependent code, maybe
Java isn't for you.

- Oliver

Apr 27 '06 #77
Remon van Vliet wrote:
I normally dont get involved with pissing contests, but there's only so much
bs in a single post i can take without replying...

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$

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.
c) You don't have to decide about programming style. Sun provided
standard Java style.


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

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
e) Logical package directory structure is forced on you.

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

It's freedom that doesnt add anything but confusion and hurts readability.
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.

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.

Unfortunately I once saw one of the senior developers/team leaders
actually overload the comma operator.

That cause no end of problems.

Its a powerful tool granted, so is an electric screw driver - but most
times a simpler approach is better.
Apr 27 '06 #78

"Noah Roberts" <ro**********@g mail.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.com.. .

Chris Smith wrote:
I side with the
position that a language that's hard to understand has a weakness in
this even if it remains possible to write software using that language.

Lots of silly statements but no backing. "X is hard." Meaningless.

So how about instead of characterizing a language as being universally
hard or universally bad, we just accept that some people find it difficult
to program in C++, and so C++ is not the language for them? Similarly, maybe
some people find it difficult to program in Java, and so Java is not the
language for those people.

Can't we all just get along? ;)

- Oliver

Apr 27 '06 #79

"peter koch" <pe************ ***@gmail.com> wrote in message
news:11******** *************@i 40g2000cwc.goog legroups.com...

Roedy Green skrev:
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.
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


From your link:

Most of the features I dislike from a language-design perspective are part
of the C subset of C++ and couldn't be removed without doing harm to
programmers working under real-world conditions.
By now, C++ has features that allows a programmer to refrain from using the
most troublesome C features. For example, standard library containers such
as vector, list, map, and string can be used to avoid most tricky low-level
pointer manipulation.
Within C++, there is a much smaller and cleaner language struggling to get

I think of computer languages as like species of dinosaur. Each new
species can build on the last and do one new "trick". It would be
silly to expect one early dinosaur to be the ultimate. Because others
built on the shoulders of its design does not detract from the
"pioneering " work of the earlier species.

But Java was never meant to be a step forward in the evolutionary
chain. It was meant to be simpler and with less capability than C++,
and for that it sacrificed some safety features present in C++ (such as
e.g. const and ability to pass by value) while removing others (such as
pointer manipulators).

I think what Java was "meant to be" would best be defined by the people
who actually participated in its creation. I strongly doubt that one of the
design goals was "Let's make a language with less capability than C++",
depending on your definition of capability.

And for what it's worth, I'll mention now that in Java, you *ALWAYS*
pass by value. I hope you'll just take my word for it and/or google the
newsgroup archives for prior discussions on this, rather than have this
claim erupt into another branch of a flame war.

- Oliver

Apr 27 '06 #80

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: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
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: 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.