473,889 Members | 1,352 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
Luc The Perverse wrote:
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;
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.


Noah's point - between the cheap shots - was that C++ does _not_ allow that
kind of BS.

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

Luc The Perverse wrote:
"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.


Can't figure out who you're quoting??

I have just been convinced that Java is a superior programming language for not allowing this kind of BS.


Java doesn't allow this huh? Hmm...guess that will be news for some.
Can't exactly function as a language I guess...

May 3 '06 #362
Luc The Perverse schrieb:
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.


I think a simple chart of sourceforge projects by programming languages
would be much more meaningful. It wouldn't be representationa l because
it's far from complete, but at least you know what you are measuring.
Timo
May 3 '06 #363
In comp.lang.java. advocacy, Noah Roberts
<ro**********@g mail.com>
wrote
on 3 May 2006 09:51:31 -0700
<11************ **********@e56g 2000cwe.googleg roups.com>:

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.


Pointers are a means to an end (well, so is everything else in
a computer language, really). Exactly what is it that Java can't
do in this space?

(Especially since java.nio.channe ls.FileChannel. map() is Java's
answer to C/C++'s mmap() method.)

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.


It would help if "uniform" = "consistent with type declaration".

int a[5];
int * b = a;

just isn't quite kosher to those schooled in Pascal, convenient as it
might be otherwise; it should be:

int a[5];
int * b = &a[0];

(I don't remember the actual Pascal offhand. It's been too long,
and in any event standard Pascal didn't have an addr() method.)

I'm also not all that sure of the usefulness of such things as

const char * p = "A rainy day in Georgia";
const char * q = p + 15; // q="Georgia"

unless q is an index variable stepping through p's string,
usually in a for or while loop:

for(q = p; *q; q++) { ... }

And of course there are the problems with such things as punning:

char * p = "Another rainy day in Georgia";

void routine(const char * p, char * q)
{
for(;*p;p++, q++) *q = (*p) + 1;
}

routine(p,p);

which could confuse maintainers of routine() -- especially
if routine() for some reason frees its arguments without
checking them first.

For its part Java has its own problems with arrays:

int[] s = new int[]{1,2,3};
int[][] a = new int[][]{
s,
new int[]{1,2,3},
s,
new int[]{4,5},
new int[]{6},
null,
new int[]{7,8,9,10,11}
}

can quite easily trip up naive coding in programs; also,
the int/Integer dichtotomy is a bit of a wart, though not
nearly as bad a lesion as it could have been had Integer
been implemented with a setIntvalue() method.

I like the syntax, though. :-)

--
#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
May 3 '06 #364
Timo Stamm wrote:
Luc The Perverse schrieb:
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.


I think a simple chart of sourceforge projects by programming languages
would be much more meaningful. It wouldn't be representationa l because
it's far from complete, but at least you know what you are measuring.


SourceForge is very non random selection, not very representative of all
language usages.
May 3 '06 #365
Oliver Wong schrieb:
"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!

[...]


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.


No. But maybe it could have looked like this:

class Foo : List

"public" is made default, ":" replaces "implements " (extends could be
replaced by "<").
A better example for superfluous verbosity:

ArrayList<Entry <String, Integer, Object>> l = new
ArrayList<Entry <String, Integer, Object>>();

Wouldn't it be nice to have local type inference here?

def l = new ArrayList<Entry <String, Integer, Object>>();
Getters and Setters are another good example. Sure, the IDE can generate
them. But C#s properties are a lot more elegant. You can start with
simple public members and introduce getters and setters later without
any need to change the clients of the class.
Anonymous classes are also quickly generated by the IDE, but true
closures with a short syntax would certainly make the code more
expressive and readable.
I don't say that these changes should be made. Java sacrifices
flexibility and expressiveness for readability, and that's fine in many
situations. But I think Phlip raised a valid point, even if it was
comically exaggerated.
Timo
May 3 '06 #366
Mishagam schrieb:
Timo Stamm wrote:
Luc The Perverse schrieb:
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.


I think a simple chart of sourceforge projects by programming
languages would be much more meaningful. It wouldn't be
representationa l because it's far from complete, but at least you know
what you are measuring.


SourceForge is very non random selection, not very representative of all
language usages.


I know my english isn't perfect, but did you even read what you replied to?
Timo
May 3 '06 #367
Timo Stamm wrote:
Mishagam schrieb:
Timo Stamm wrote:
Luc The Perverse schrieb:
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.

I think a simple chart of sourceforge projects by programming
languages would be much more meaningful. It wouldn't be
representationa l because it's far from complete, but at least you
know what you are measuring.


SourceForge is very non random selection, not very representative of
all language usages.


I know my english isn't perfect, but did you even read what you replied to?

I meant that not only SourceForge doesn't represent all programmers, it
also represents very non random subset of programmers [and this
selection is very potentially dependent from language used], so any
conclusions about SourceForge projects has very little relation to
language use in general world.
Much better (through less "complete") would be to select 1000
programmers in random and ask them.
May 3 '06 #368
Timo Stamm wrote:
Getters and Setters are another good example. Sure, the IDE can generate
them. But C#s properties are a lot more elegant.


A good design that doesn't need them at all is slightly more elegant
there. ;-)

--
Phlip
http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
May 3 '06 #369
Phlip schrieb:
Timo Stamm wrote:
Getters and Setters are another good example. Sure, the IDE can generate
them. But C#s properties are a lot more elegant.


A good design that doesn't need them at all is slightly more elegant
there. ;-)


That's the point.

The following link explains it better than I did
http://cephas.net/blog/2004/02/16/c_..._and_setx.html
Timo
May 4 '06 #370

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 Im 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); Im sure that code is ok. In fact, Ive 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
9807
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
10789
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...
1
10889
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,...
0
10441
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...
1
7993
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
6028
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4251
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3255
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.