473,842 Members | 1,933 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 21563
Chris Smith wrote:
I find this to be not at all true. In fact, most of what I do for a
living these days is write code (and manage a development team that
writes code) in Java on Windows, and deploy the code on Linux.


Me too. I could have kicked off the list with a less cheap shot. For
example:

"Java : the elegant simplicity of C++ and the blazing speed of Smalltalk."
--Jan Steinman
- adds keywords, like interface, based on
someone else's preconceived notion of good
design. Not keywords like 'virtual', based
on what the hardware will actually do


So you don't like the lack of multiple inheritance. That's fine.
However, the existence of interfaces as a language feature is perfectly
sensible in a language without multiple inheritance. This is not a
separate gripe.


Ooh, I was gonna snip it all, but you finally got thru to me.

I didn't mention MI!!!

When I was a tiny kid, my mom read me a children's book about a rabbit
scolding another rabbit (or something like that) for sneaking into a
garden. The one rabbit complains, "but I didn't sneak in!" "Because you
stopped in time!!" "But I wasn't _gonna_ sneak in!!" etc.

I apologise for just being about to mention MI and stopping in time.
(Noah!;)

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
May 3 '06 #351

Phlip wrote:
I apologise for just being about to mention MI and stopping in time.
(Noah!;)


?

May 3 '06 #352
Noah Roberts wrote:
Mishagam wrote:
Noah Roberts wrote:
Mishagam wrote:

C++ references are not SO different from pointers. Just like Roedy Green
said - one more addressing mode. I doubt any well designed language
(like Java) would have (or has) references.
Java has references.

Excuse me. I meant separate references and pointers with so close
functions. Java has references, but they have also some features of C++
pointers like they can be null.


C++ pointers and references have completely different purposes. The
fact that Java lacks pointers is just another can't.

I can't say Java's, "everything is a reference except when it is not,"
is a move up from having explicit value, reference, and pointer
semantics that operate in a uniform manner.


Java has a thing called 'references'. Its more like a C Pointer than a
C++ reference, as in it can be nulled. The major difference is that no
pointer arithmetic can be done with it.

Java references are passed by value. The objects that they point to does
actually move.

Granted a better name than 'reference' or 'pointer' would have helped -
though I cant think of one.
May 3 '06 #353
Noah Roberts wrote:
Mishagam wrote:
Noah Roberts wrote:
Mishagam wrote:

C++ references are not SO different from pointers. Just like Roedy Green
said - one more addressing mode. I doubt any well designed language
(like Java) would have (or has) references.
.... C++ pointers and references have completely different purposes.


'purpose' is what language designers imagined references would be used
for. Functionaly, as I understand, difference between references and
pointers is little syntax sugar [ -> replaced with . ] + what values
they can hold - references cannot hold null or objects allocated by new.
But you CAN have reference to destructed object out of scope (or field
in deleted object allocated on heap). Also references syntax resembles
value objects enough that is is difficult to distinguish what you are
using now. It is one more way where C++ loses C clarity.
What I meant is difference with pointer is too small to justify
existence of references for well designed language. I think that
designers of C++ just hated C pointers too much to think rationally.

By the way, I have little problem. I Wiki about C++ reference types I read:
"Once a reference is created, it cannot be later made to reference
another object; we say it cannot be reseated. This is often done with
pointers."
But in my VS 2003 C++ compiler you can easily put new value to
reference, like code sample below. Do you know who is correct here?

int main() {
int aa = 25;
int & ra = aa;
int bb = 323;
ra = bb;
printf("ra= %d\n", ra);
int *ii = new int;
*ii = 999;
ra = *ii;
printf("ra= %d\n", ra);
ii = NULL;
ra = *ii;
......
THis code compiled and run OK on VS 2003
May 3 '06 #354

Mishagam wrote:
Noah Roberts wrote:
Mishagam wrote:
Noah Roberts wrote:
Mishagam wrote:

> C++ references are not SO different from pointers. Just like Roedy Green
> said - one more addressing mode. I doubt any well designed language
> (like Java) would have (or has) references.
...
C++ pointers and references have completely different purposes.


'purpose' is what language designers imagined references would be used
for. Functionaly, as I understand, difference between references and
pointers is little syntax sugar [ -> replaced with . ] + what values
they can hold - references cannot hold null or objects allocated by new.
But you CAN have reference to destructed object out of scope (or field
in deleted object allocated on heap). Also references syntax resembles
value objects enough that is is difficult to distinguish what you are
using now. It is one more way where C++ loses C clarity.
What I meant is difference with pointer is too small to justify
existence of references for well designed language. I think that
designers of C++ just hated C pointers too much to think rationally.


You say that references are little more than syntatic sugar and then
directly quote at least one way in which they are drastically different
below. I guess logic isn't something you are good at.
By the way, I have little problem. I Wiki about C++ reference types I read:
"Once a reference is created, it cannot be later made to reference
another object; we say it cannot be reseated. This is often done with
pointers."
But in my VS 2003 C++ compiler you can easily put new value to
reference, like code sample below. Do you know who is correct here?

int main() {
int aa = 25;
int & ra = aa;
int bb = 323;
ra = bb;
printf("ra= %d\n", ra);
int *ii = new int;
*ii = 999;
ra = *ii;
printf("ra= %d\n", ra);
ii = NULL;
ra = *ii;
.....
THis code compiled and run OK on VS 2003


You obviously don't understand what a reference is. Print out aa and
you will have your answer. Print out bb after your second change and
it may become more clear.

May 3 '06 #355
[followups set to non-Java groups]

Mishagam wrote:
C++ pointers and references have completely different purposes.
'purpose' is what language designers imagined references would be used
for. Functionaly, as I understand, difference between references and
pointers is little syntax sugar [ -> replaced with . ]


Nope. A reference is an alias for an object. Unlike a pointer, you cannot
take the address of the refering thing (the thing that's probably secretly
a pointer). It's secret because the compiler can optimize it away, and go
to the real object if possible.
+ what values
they can hold - references cannot hold null or objects allocated by new.
They can hold heap objects; they just shouldn't.

int & i = *new int;
delete &i;

That's valid but high risk.
But you CAN have reference to destructed object out of scope (or field
in deleted object allocated on heap).
Yep. Even thinking about i after my delete line is illegal.
Also references syntax resembles
value objects enough that is is difficult to distinguish what you are
using now. It is one more way where C++ loses C clarity.
There's a difference between clarity and exposed plumbing...
What I meant is difference with pointer is too small to justify
existence of references for well designed language. I think that
designers of C++ just hated C pointers too much to think rationally.
If they burdened C++ with your misunderstandin gs of references, then your
point might be valid. References are good because they are the _weakest_
kind of alias or handle we have. Use them in preference to pointers.
By the way, I have little problem. I Wiki about C++ reference types I
read: "Once a reference is created, it cannot be later made to reference
another object; we say it cannot be reseated. This is often done with
pointers."
But in my VS 2003 C++ compiler you can easily put new value to
reference, like code sample below. Do you know who is correct here?

int main() {
int aa = 25;
int & ra = aa;
int bb = 323;
ra = bb;
That copys the value of bb into aa, which ra still refers to.
printf("ra= %d\n", ra);
int *ii = new int;
*ii = 999;
ra = *ii;
Right. Now that copies the 999 to the aa, which ra still refers to.
printf("ra= %d\n", ra);
ii = NULL;
I hope you didn't think that 'delete's ii. It just leaks the memory.
ra = *ii;


And that's undefined behavior.

So the well-defined parts of your sample program do indeed demonstrate how
references are aliases for their target objects. You may want to debug your
program, or even look at its opcodes, to see what's going on. The compiler
might optimize ra away, and the statement ra = bb might produce the same
opcodes as aa = bb.

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
May 3 '06 #356
"Andrew McDonagh" <ne**@andmc.com > wrote in message
news:e3******** **@news.freedom 2surf.net...

Java has a thing called 'references'. Its more like a C Pointer than a
C++ reference, as in it can be nulled. The major difference is that no
pointer arithmetic can be done with it.

Java references are passed by value. The objects that they point to does
actually move.


I'm assuming you mean "does NOT actually move".

- Oliver

May 3 '06 #357
"Chris Smith" <cd*****@twu.ne t> wrote in message
news:MP******** *************** *@news.astraweb .com...
- when a smart editor like Eclipse can finish
every line for you, it makes you wonder
what the language is _there_ for!


This is perhaps a useful thing for some to wonder, but only so that they
can get around to knowing the answer. The answer is that we're talking
about two different sets of things:

(1) What can be reasonably guessed, with the assurance that the
programmer will see the guess and correct it if it's wrong?

(2) What is so certain to be the programmers meaning that it can be done
without guessing?

Clearly, there are things that fit into set (1) without also fitting
into set (2). Those things should be implemented with IDE auto-complete
features, and not with the language itself. Whether the boundaries are
drawn correctly is another issue, and there are undoubtedly places where
the boundaries could be drawn better... but criticizing the need for
auto-complete entirely doesn't look reasonable.


Also, when some types in:

public class Foo i

the Eclipse Editor, and just about anyone else who is familiar with
Java, could probably safely assume that the programmer is about to type in
"mplements" to yield:

public class Foo implements

does that mean that the designers of Java should have used the string
"i" instead of "implements " as the keyword? It depends on whether one values
clarity or terseness.

- Oliver

May 3 '06 #358
"Mishagam" <no*****@provid er.com> wrote in message
news:na******** **********@sout heast.rr.com...
int main() {
int aa = 25;
int & ra = aa;
int bb = 323;
ra = bb;
printf("ra= %d\n", ra);
int *ii = new int;
*ii = 999;
ra = *ii;
printf("ra= %d\n", ra);
ii = NULL;
ra = *ii;
.....
THis code compiled and run OK on VS 2003


Wow. Noah your point is well taken. I have just been convinced that Java
is a superior programming language for not allowing this kind of BS.

--
LTP

:)
May 3 '06 #359
"Chris Uppal" <ch*********@me tagnostic.REMOV E-THIS.org> wrote in message
news:44******** *************@n ews.gradwell.ne t...
Oliver Wong wrote:
(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.


From the TIOBE faq:

Q: What happened to Java in April 2004? Did you change your methodology?
A: No, we did not change our methodology at that time. Google changed its
methodology. They performed a general sweep action to get rid of all kinds
of
web sites that had been pushed up. As a consequence, there was a huge drop
for
languages such as Java and C++. In order to minimize such fluctuations in
the
future, we added two more search engines (MSN and Yahoo) a few months
after
this incident.


It's a flawed method of rating to begin with. I do not believe we can
directly infer that web page occurrences some how indicate usage. It may
provide some kind of vague correlation - I suppose.

--
LTP

:)
May 3 '06 #360

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

Similar topics

0
6821
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
6923
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
9294
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
5662
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
9668
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
5935
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
3292
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
4310
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
3301
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
9715
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,...
1
10671
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,...
1
7855
isladogs
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...
0
7035
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();...
0
5696
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
5884
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4499
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4088
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3142
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.