473,889 Members | 1,367 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 21637
Chris Smith wrote:
Noah Roberts <ro**********@g mail.com> wrote:
Chris Smith wrote:
Unfortunately, the meaning of the term "reference" and "pointer" is
language-dependent. Java certainly does not have references in the C++
sense. All Java identifiers are used to designate distinct variables;
you never have two different variable names that both mean the same
thing.

Really?


snipped nice post...

Noah, its important that you get Java's concept of variable and objects,
not being the same thing, if you want to try and map this to how C++
works.

Variables are more than names/alias but they aren't the object they
point to, they have the Type information of the object they point to at
most.
May 5 '06 #421
"Noah Roberts" <ro**********@g mail.com> wrote in
news:11******** **************@ v46g2000cwv.goo glegroups.com:

Otis Bricker wrote:
And this is fully understood by any good Java programmer.
Stupid argument. Any X language developer is aware of the quirks and
limitations of the language they use.

So why are you so concerned that it is confusing? I am quite tempted to
adapt your insulting tone but "last refuge" and all.

As all calls are by value, it cannot change i.
Had the code been
{
A a= new A();
foo(a);
}

a would also have not changed. It would still reference the same
object. But the actual object refered to by a might have changed.


You are purposfully skewing the discussion to match the point you are
trying to make...which is a pointless point anyway. The object the
variable a refers to changes if any mutable operations are performed
on it....you cannot stop it from happening or label if it will or not.
Stop playing with definitions and argue intelligently.


second time you choose to be insulting. All I was pointing out was that
is expected by Java developers. You seemed unable to recognize that.

Point taken on the rest...


I'm glad my stupidity and lack of intelligence didn't stop you from
getting something out of my comments.

From your hostile response, my contribution to the discussion seems to
be causing you some discomfort. Please feel free to stop responding.

I assure you I will. I cannot abide a lack of civility.

c.l.c++.m is more interesting than this anyway.

OB

May 5 '06 #422
"Otis Bricker" <ob******@my-dejanews.com> wrote in message
news:Xn******** *************** ***********@216 .196.97.136...
I don't know any halfway good java programmer that it confuses. I
couldprobaly find some butthen I could probaly find C++ programmers that
have trouble understanding references or const.


In java if you have made a linked list, worked with strings etc you will
know how the code works.

I remember trying to show my code to some "supposed" C++ programmers, and
everyone was confused by the notation, dereferencing, what was a variable,
what was an address etc.

So we have concluded that Java is easier to learn, more consistent, more
predictable. It is virtually impossible to hide what an object is (IE there
will never be a question as to if it is an pointer, reference or an object.)

Noah said earlier:
Java references are pointers without the benefits of being pointers and
without an explicit notation to label them as such to reduce confusion.


Java references, or whatever you call them behave EXACTLY like C++ pointers.
References in C++ are just pointers that are automatically dereferenced. (I
mean from a usage standpoint, if it is handled differently somehow in the
compiler I am not aware of it.)

So we concede on two points (except that they are the same point):
1. Java has no way of having a pointer to a primitive
2. Java has no way of having a pointer to pointer/reference

You refer to the inane inherent power of C++ notation, like some kind of
He-man crap. No one here is saying that C++ doesn't have more concise
methods of passing data around. What we are saying is that they add
complexity without adding significant value. In fact it has been my
personal experience that using things like references, and pointers to
pointers generally do nothing but obfuscate the code whether deliberate or
not.

Noah, you mentioned that when a function gets a class instantiation passed
in that it receives the object by value, as a copy - this way you can be
sure that no one is changing your object. IIRC in programming class I was
taught that a class wasn't supposed to have publicly accessible data
anyway - that everything was supposed to be accessed through a function -
unless it was from inside the same class (in which case we considered
transactions trusted.) This seems odd from seasoned professors if C++, the
language we were studying at the time, was immune to data corruption because
of passing by value. A poorly designed copy constructor, of which I have
seen many, can create ridiculous overhead, and corrupt data in a way that
genuinely confuses the programmer.

Where did you get it in your head that C++ needs to be better than Java
anyway? Can there be only one?

My points:
1. Regardless of inherent superiority C++ and Java exist independently, and
both sides have many satisfied users (and sometimes fanatics like you)
2. Yes, C++ semantics have inherent benefits. The problem isn't the
language, it is the users who don't understand and/or misuse them. Java
has been designed, deliberately, in such a way that misuse and confusion is
kept to a minimum. This seems to make everyone happy except you, because
you can't write your obfuscated piece of do nothing code whose functionality
could otherwise be represented in java, just not with the same
implementation.

If you want to argue the benefits of C++ against Java - you will find it has
already been done, but having no way to address a primitive or pointer is a
stale point - you are beating a dead horse. It doesn't help that many of
the things you are saying make no sense at all.

--
LTP

:)

May 5 '06 #423
Ed Jensen <ej*****@visi.c om> wrote in news:125nj074p4 5j964
@corp.supernews .com:
In comp.lang.c++ Noah Roberts <ro**********@g mail.com> wrote:
void foo(const I & i);

That function accepts a reference to an I object that cannot be changed
by foo without purposfully breaking the language's protections through
a const_cast. Callers can rely on the fact that i is not changed as
that definition is a statement to that effect.


Translation: The const "guarantee" can trivially be broken by casting
away const; thus, it's no real guarantee at all.


Not fair. Any decent C++ programmer would not do this EXCEPT to correct a
problem with some legacy code. Like using a const char* with a C api like
strlen. The definition predated const and was not updated because of the
large body of existing code.

There are plenty of other ways that const is not always const. I gave a
couple of example. Deliberately doing things that are just wrong is...

Just wrong.
OB
May 5 '06 #424
"Luc The Perverse" <sl************ ***********@cc. usu.edu> wrote in
news:44******** *************** @news.csolution s.net:
Noah, you mentioned that when a function gets a class instantiation
passed in that it receives the object by value, as a copy - this way
you can be sure that no one is changing your object. IIRC in
programming class I was taught that a class wasn't supposed to have
publicly accessible data anyway - that everything was supposed to be
accessed through a function - unless it was from inside the same class
(in which case we considered transactions trusted.) This seems odd
from seasoned professors if C++, the language we were studying at the
time, was immune to data corruption because of passing by value. A
poorly designed copy constructor, of which I have seen many, can
create ridiculous overhead, and corrupt data in a way that genuinely
confuses the programmer.


While I agree with most of what you said above and in the snipped part, I
think that is is unfairly presenting his view.

You might well have code such as( forgive the lack of detail):

Iterator i;

....

if( find(i,"fred") )
return "Fred's Here";
else if ( find(i,"Barney" ) )
return "Barney's Here";
else
return "Just us Girls";

By copying the Iterator, you do not have to preserve its original state.
That remains safely held in the original, outside the method call. It is
the copy that is changed by the code in find. And this happens regardless
of whether we are calling Iterator.getNex tItem() or looking at member
variables.

OB

May 6 '06 #425
In article <445bde5f$0$276 15$3a2ecee9
@news.csolution s.net>,
sl************* **********@cc.u su.edu says...

[ ... ]
You refer to the inane inherent power of C++ notation, like some kind of
He-man crap. No one here is saying that C++ doesn't have more concise
methods of passing data around. What we are saying is that they add
complexity without adding significant value. In fact it has been my
personal experience that using things like references, and pointers to
pointers generally do nothing but obfuscate the code whether deliberate or
not.
I think there are two more or less separate things being
conflated here. It's true that C++ has separate notation
for pointers, references, etc. It's also true that the
separation of this notation rarely adds much (if
anything).

"...using things like references..." is a whole different
story. I have a hard time believing that anybody would
claim using references obfuscates code. Generally
references clean up code compared to using pointers.
Comparing to Java is difficult, simply because Java
doesn't really have a close analog to a C++ reference. In
addition, C++ references don't stand by themselves --
they're often (typically?) used in conjunction with other
things that have no analog in Java either.

I, for one, think that when used carefully the result can
be substantially cleaner than anything I've seen in Java
to do the same job, but it's hard to attribute that
entirely to references. In fact, the real improvement in
most cases comes from things like overloaded operators,
and references just happen to be more or less necessary
to do the job.

[ ... ]
2. Yes, C++ semantics have inherent benefits. The problem isn't the
language, it is the users who don't understand and/or misuse them. Java
has been designed, deliberately, in such a way that misuse and confusion is
kept to a minimum. This seems to make everyone happy except you, because
you can't write your obfuscated piece of do nothing code whose functionality
could otherwise be represented in java, just not with the same
implementation.
The previous example about merging classes does seem to
point out at least one situation in which Java makes a
job more difficult than the same job would be in C++. In
fairness, there is a tradeoff involved -- the necessary
capability is directly supported by C++, but no by Java.

In fairness, however, there are lots more tools to
support doing the job in Java. Some of these tools are
good enough that the amount of actual work for the
programmer is little or no greater using Java than C++.
In the other direction, these tools are hardly perfect
either -- at least of those I've tried, every one has had
at least a few things it supported poorly if at all.

At least IME, in most cases you're trading off one
complexity for another -- the language itself is simpler,
but instead you play with a half dozen different tools,
each with its own strengths and weaknesses.

Of the two basic directions, I know which _I_ prefer, but
I'm hardly conceited enough to think that means anybody
else should or will agree.
If you want to argue the benefits of C++ against Java - you will find it has
already been done, but having no way to address a primitive or pointer is a
stale point - you are beating a dead horse. It doesn't help that many of
the things you are saying make no sense at all.


This is, unfortunately, often true in both directions. At
least IMO, the problem is fairly simple: the strengths of
the two languages are sufficiently different that I think
it's difficult to come up with a comparison that doesn't
make the result of the comparison almost a foregone
conclusion. When they look competitive, it's usually at
doing something you'd probably never really do in
_either_ language. I'm not really interested in knowing
whether C++ or Java is worse at something that Lisp does
at least twice as well as either one!

--
Later,
Jerry.

The universe is a figment of its own imagination.
May 6 '06 #426
In comp.lang.java. advocacy, Noah Roberts
<ro**********@g mail.com>
wrote
on 5 May 2006 14:16:29 -0700
<11************ ********@y43g20 00cwc.googlegro ups.com>:

The Ghost In The Machine wrote:
Const can turn into a bit of a mess (mostly because if one
changes a parameter from (A &) to (A const &) in a routine
declaration, implementations tend to propagate the change
down) but at least it's allowed,...


True, but such conditions indicate one of two things:

1) The object you are trying to make const should not be const because
you do in fact modify it in the code.

or

2) The functions you are calling in the code should have been const to
begin with.

In the case of 1 it is obvious that you are in error and the language
is telling you so...still, it will let you do it by using some casts to
get rid of constness and ignore the advice of the compiler.

In the case of 2 you are really just fixing bugs by propegating the
const chain.

This is a daily thing for me in certain legacy code I work on
actually...it was implemented poorly...I'm fixing it by adding const
where it belongs when I need to.


Yeah, well, not all of us can be perfect designers. ;-) I for one
routinely go back into my code and wonder how I could have written such
cruft and how asleep I was when I did so... :-)

--
#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
May 6 '06 #427
In article <e3**********@o rkan.itea.ntnu. no>,
bc*@pvv.ntnu.no says...
In article <MP************ ************@ne ws.sunsite.dk>,
Jerry Coffin <jc*****@taeus. com> wrote:

If you'd read what I posted (the code in particular)
you'd realize that the same is possible when you DO use
public variables.
My comment was largely based on language neutrality. I would rephrase
it to only cover languages that do not have other means of
accomplishing the same effect.


I think we're basically in agreement. You need some way
of getting code of your choice executed at the
appropriate times. From there it's a question of how
cleanly the language supports getting that done.
Data encapsulation is the goal. Trivial getX/setX accessors are a
means to reach that goal, and quite defensible in languages that
provide no other (better) means of getting there.
Here I disagree, at least with what you've said (though,
I suspect not with what you really think). Data
encapsulation isn't really the goal -- it's just a means
to an end. The real goal is cleaner code that's easier to
read, more maintainable, dependable, etc.
I need to add that in the context of the original suggestion (that
being able to directly access another object's state is wrong in
itself), your operator-based approach would be equally wrong, only
with a nicer syntax. It remains a poor man's approach to
encapsulation: Any algorithms that need to alter an object's state
should be internal to that object itself, not external to it.
In that context, yes. That's not the only framework
within which things make sense though -- at times, it
makes more sense to have classes that are little more
than containers, with the algorithms that apply to the
data being external.
According to this philosophy, you would never write
employee.wage *= 1.1;
You would write
employee.raiseW agePercent(10);


For that example, I completely agree.

--
Later,
Jerry.

The universe is a figment of its own imagination.
May 6 '06 #428

Otis Bricker wrote:
I cannot abide a lack of civility.


Doesn't seem to stop you from being plenty proficient at it.

May 6 '06 #429
Luc The Perverse <sl************ ***********@cc. usu.edu> wrote:
Java references, or whatever you call them behave EXACTLY like C++ pointers.
Sorta. There are, obviously, fewer operators defined to operate on a
Java reference than on a C++ pointer.
References in C++ are just pointers that are automatically dereferenced. (I
mean from a usage standpoint, if it is handled differently somehow in the
compiler I am not aware of it.)


The problem is not usage versus compiler viewpoints. The problem is
that you are introducing a more complex concept (a pointer) in order to
explain a less complex concept. A C++ reference isn't any kind of thing
at all -- it's just a name, used to signify some other thing that
already exists. The new name (the reference) can be visible in a
different scope, but it is still the same thing.

C++ references CAN be described as pointers, except that operators and
type conversions and method overload resolution and so forth all act
differently on them. Then again, I could just as validly describe a
Java int as a String, except that the "." syntax for accessing methods
or fields is illegal, than <, <=, >, >=, -, <<, >>, >>>, and so forth
are defined, that == and != do different things, that type conversions
and method overloads and so forth act differently on them, etc. There
are an infinite number of possible and valid mental models that can be
coerced into making sense to describe the behavior of a language with
sufficient complexity, but that doesn't means it's always reasonable to
think of things according to those models. References can be easily
understood by someone who's never heard of pointers. They are not
pointers, even if it remains possible to describe their behavior in
terms of pointers.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
May 6 '06 #430

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

Similar topics

0
6823
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
1
6927
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
11
9298
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();
0
5664
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)
1
9675
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?
12
5939
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).
0
3295
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 <...
1
4314
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...
0
3304
oll3i
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);
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9805
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11188
Oralloy
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...
0
10785
jinu1996
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...
0
10439
tracyyun
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...
0
9603
agi2029
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...
0
5825
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...
0
6025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3253
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.