473,889 Members | 1,443 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
In comp.lang.java. advocacy, Andrew McDonagh
<ne**@andmc.com >
wrote
on Tue, 02 May 2006 19:42:45 +0100
<e3**********@n ews.freedom2sur f.net>:
ebhakt wrote:
It's not of being smarter or not....

I am both a C/C++ and JAVA coder :

There is NO C/C++ language.

There is the C Language and the C++ language. There are compilers that
will compile source files from both languages - but there is no C/C++
language.


No, but C++ will accept most of Ansi C, and gcc compiles both,
as well as Objective-C.

c is flexible :
this is both a merit and demerit (depending on programmers
capabilities)

Java takes care of this for both lame and stunt performers...

Its simple for those who want to go that way
but for big guys JAVA has much more......

You should not forget that JAVA was the Impetus behind internet ,
this language should be given respect
what are you talking about?


Indeed; I'm not sure C was all that extant when the
Internet was first formulated in the late 1960's, though
it wasn't long after -- never mind C++, Java, and C#.

Of course Java goes well with the Internet, and is
probably responsible for a goodly chunk of modern server
implementation code and the occasional applet. However,
Mosaic and NCSA came first, and FTP, telnet, and rsh
before them.



....
.......and its programmers are not just smart..they are bigger than
that

Bhaskar

--
#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
May 2 '06 #291
In comp.lang.java. advocacy, Walter Bright
<wa****@digital mars-nospamm.com>
wrote
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.

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.

(For its part Java doesn't even have this issue, since it
has neither of C's unary '*' (pointer dereference) nor '&'
(address of) operators.)

In the case of int a[3]; the array size is quite fixed,
unlike the vector, which is variably sized but potentially
incurs an extra page fault thereby. (There might be a way
around that using an allocator but I'd have to look.)

Java has a vaguely similar problem, and in fact a vaguely
similar syntax:

import java.util.Vecto r;

Vector<Integer> a = new Vector<Integer> ();

as of Java 5, anyway.

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

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.
Murphy was an optimist. :-)


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

--
#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
May 2 '06 #292
The Ghost In The Machine wrote:
In comp.lang.java. advocacy, Andrew McDonagh
<ne**@andmc.com >
wrote
on Tue, 02 May 2006 19:42:45 +0100
<e3**********@n ews.freedom2sur f.net>:
ebhakt wrote:
It's not of being smarter or not....

I am both a C/C++ and JAVA coder :

There is NO C/C++ language.

There is the C Language and the C++ language. There are compilers that
will compile source files from both languages - but there is no C/C++
language.


No, but C++ will accept most of Ansi C, and gcc compiles both,
as well as Objective-C.


Yes I said this about the compilers....
May 2 '06 #293

Phlip wrote:
Ruby: - No comment. Do agree on the syntax point from the little I've worked
with it.
Java: - No comment. One positive aspect is their uniformity (one lib).
Negative aspect is that sometimes one needs bare-bones. They've also
dropped some good features in C++ (No comment on D just yet).
C++ (deep breath):
- where in memory do you want to
accidentally jump today?
- This is not so much of a problem anymore. Actually, it's not a
problem at all. Using vectors instead of arrays. Using combo of shared
and weak pointers. Wrapping strings or using std::string. We have large
c++ apps running like a clock.
- the only smart pointer that could pass
the 97 committee was one so primitive
and broken that its copy constructor
changes the copied-from object!
Yes, a very, very handy feature. Especially for passing buffers from
lower layers to application layers. Passing data from one thread to
another etc. Certainly used often by me. But hey, long since 97, aint
it.
- mutable; because constancy is enforced
at compile time, not runtime, yet it
_could_ exploit hardware support
Because logic and physical constness is 2 different things.
- strings, strings, and more strings. The
ISO Standard string came so late in the
language's history that every serious
library has its own (multiple) string
classes
Agreed. How about writing your own :->. You can!
- what the >F---< does imbue() do???
Admittedly, I've used it <iostreams> less often. Others consider it
very scalable. To extend a good book is required, but very extensible.
- void main is neither illegal nor legal!
Some, but not all, compiler-specific
extensions use a __ prefix
Hmmm, I think most of them are working towards confomance.
- of course RAII can be better than
redundant finally blocks. But _all_
these systems are cheap imitations
of the Execute Around Pattern, which
requires block closures, so objects
can clean themselves up, exception-
safely, deterministical ly, and
_without_ elaborate destructors
I wonder which came first.
- the majority of the glitches and
common bugs when implementing code
in C++ happen because it's designed
to be efficiently compiled by a
simple compiler. A reinvented language
could make better use of modern
compiler technology
Yes, your humbleness ...
- teachers, bosses, and colleagues make
us use the language because it's
popular, even for inappropriate
situations. This newsgroup gets
a dozen questions per month asking
how to do something that a scripting
language can do
Often trivial examples are used to solve more complex problems. Given
the trivial example, readers don't need to focus on the unnecessary.
Obviously they (the trivial examples) can be performed using scripts
too, but they fit into a bigger picture/application, therefore your
point is?
- you can do an "Applet" in C++ trivially,
using ActiveX. And because C++ has no
security model to speak of, anyone
using your applet exposes their browser
to gawd-knows-what-else is out there...
No comment, mainly because I don't write applets.
- how many here have _ever_ written a
program with _absolutely_ no undefined
behavior? How many _know_ they did??
Yes, you have a point. Many libraries do exists that has been ported to
various (umpteen) platforms, though. Tested and working... Testing is
knowing. This is not only due to language imperfection, but due to
human imperfection (you could even make mistakes with perfect languages
- not meeting user requirements). The most imperfect humans of course
are those that believe they are perfect. Do you fall into that
category, your humbleness? :-)
- when folks say C++ is portable, they
mean the _compiler_ ports easily to
other platforms. By marrying your
statements to the metal, a C++
implementation forces you to
consider _endless_ portability issues
at port time
Blah, blah...
- the exception handling model is so
complex it makes me wonder if Bjarne
Stroustrup actually determined how to
write exception-safe programs when
he invented the language


I can only disagree with this one. But what do you suggest? You can
only criticise if you have a better alternative (Philips language,
whoa!). Better start implementing, that others like you can start
critting.

Hah, hah, hah (Feel like I'm feeding a troll).

Werner

May 2 '06 #294

The Ghost In The Machine wrote:
In comp.lang.java. advocacy, Walter Bright
<wa****@digital mars-nospamm.com>
wrote
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.
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.

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

May 2 '06 #295
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
http://www.tiobe.com/tpci.htm

<g>
May 2 '06 #296
werasm wrote:
C++ (deep breath):
- where in memory do you want to
accidentally jump today?


- This is not so much of a problem anymore. Actually, it's not a
problem at all. Using vectors instead of arrays. Using combo of shared
and weak pointers. Wrapping strings or using std::string. We have large
c++ apps running like a clock.


In general, >70% of all software features are not used as first delivered,
and malware is a crushing burden on global productivity. We have a new form
of war on our hands - a new kind of arms race.

Yet when you look at the sources of security breaches, over and over again
you find the things that sloppy C++ programmers revel in. Double deletes,
array overruns from unchecked buffers, runaway recursion, gratuitous
typecasts, etc.

http://c2.com/cgi/wiki?MicrosoftSampleCode

People are learning that technology in their lives that fails the most often
is software. And C++ is leading the charge.

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

"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
http://www.tiobe.com/tpci.htm


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

- Oliver

May 2 '06 #298
In comp.lang.java. advocacy, Noah Roberts
<ro**********@g mail.com>
wrote
on 2 May 2006 14:38:03 -0700
<11************ *********@y43g2 000cwc.googlegr oups.com>:

The Ghost In The Machine wrote:


[snippage]
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...


I have not; the considerations are theoretical. However,
the implementation of std::vector<... >::push_back( ) on my
system (gcc 3.4.5) includes a call to
_M_insert_aux(e nd(), __x), which among other things calls
_M_allocate(2 * size()), to allocate a bigger chunk, and
_M_deallocate() on the existing storage.

This makes constructs such as b = &a[4] dangerous if one
holds onto b for too long and also inserts additional
stuff into a. One would hope most reasonable coders wouldn't
do that, of course, but anyone who's seen Jeff Relf's code
(or a facsimile thereof) has to wonder. :-)

It is barely possible that a very smart compiler might
have equivalent code for the sequences:

a[0] = 1;
a[n-1] = 2;

except for a single register load (in the case of std::vector<> the
field value _M_start). However, I'd have to experiment.

--
#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
May 2 '06 #299
In comp.lang.java. advocacy, Andrew McDonagh
<ne**@andmc.com >
wrote
on Tue, 02 May 2006 21:04:49 +0100
<e3**********@n ews.freedom2sur f.net>:
The Ghost In The Machine wrote:
In comp.lang.java. advocacy, Andrew McDonagh
<ne**@andmc.com >
wrote
on Tue, 02 May 2006 19:42:45 +0100
<e3**********@n ews.freedom2sur f.net>:
ebhakt wrote:
It's not of being smarter or not....

I am both a C/C++ and JAVA coder :

There is NO C/C++ language.

There is the C Language and the C++ language. There are compilers that
will compile source files from both languages - but there is no C/C++
language.


No, but C++ will accept most of Ansi C, and gcc compiles both,
as well as Objective-C.


Yes I said this about the compilers....


Yes you did. :-) Oops.

--
#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
May 2 '06 #300

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,...
1
10887
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
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
7148
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
6025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4249
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
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.