473,842 Members | 1,788 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 21553

Mishagam skrev:
Noah Roberts wrote:

[snip]
Third...COM is not C++, it is a MS specific standard of coding a set of
functionality in ANY language that can be used from ANY language
capable of interacting with COM. I do believe Java can be counted
among them but of course any such program instantly looses any platform
independance.

I programmed on COM on C/C++, and all COM procedures use HRESULT as
error code. Other often used COM Language is VB, where error codes
apparently are somehow hidden - I don't know VB very well. Java cannot
directly use COM, probably there exist JNI Libraries allowing
communications Java <-> COM through native calls.

This is absurd. If you program against a COM interface you use a
HRESULT. This is so in ANY language - even Java. Unless Java does not
support COM programming, of course.

Finally, if you don't know then your doubts are meaningless.


/Peter

Apr 29 '06 #211
Alex Buell wrote:
On Thu, 27 Apr 2006 16:07:01 -0700 Walter Bright
<wa****@digital mars-nospamm.com> waved a wand and this message
magically appeared:
Language design is complicated, with lots of tradeoffs. I don't know
any language that doesn't contain at least one stupid feature its
designer should have known better about.


OK, are there any stupid features in D? ;o)

It is not honest to ask about stupid feature of language nobody knows
much about.
Everybody knows about C++ stupid features, because it had it's period of
fame when everybody programmed on it. The same for Java.
I think the fact that nobody uses D means suggests that it has not only
one stupid feature, but a lot of stupid features.
Apr 29 '06 #212
Noah Roberts wrote:
Mishagam wrote:
Noah Roberts wrote:
Mishagam wrote: 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.
Actually, you are in err. Java also has char[] and there is nothing
stopping someone from using it or designing a new String. Therefor
Java suffers from the same "problem" as C++ here except there are no
Java functions and tools to work with char[]...you have to write them
from scratch. Yes, you can use char[] (or byte[]), but as you said it has no support,
so nobody uses it (as opposed to String, which is more heavily supported
than any C/C++ strings version). It is VERY rare Java programmer who
would spend time deciding which string representation to use. Everybody
just uses String. And the beauty it - it is really very close to optimal
choice. (as opposed too, for example, original Pascal strings)


Interesting statement. Just how close, in quantifiable values, to
optimal is it then? Also, optimal in what way?

For strings main feature is convenience. You can easily define strings,
you can easily make operations, especially concatenations, with strings.
You don't bother about allocating pieces of string. You can use strings
as keys. You can easily convert other type to strings, and simple types
from strings. Strings should be efficient.
C char * strings are very fast, have decent support and great
improvement over Pascal strings (not to mention Fortran), especially
because of sprintf / sscanf functions, but you always have to bother
where to allocate strings, and C strings are not safe.
STL string and CString are slower than C, but safe. They have some
support, but Java strings are supported better. You also always have to
choose which string to use, and different programs and libraries use
different strings. For example, part of pain of COM programming on
Windows was very frequent need to convert strings from one format to
another.
So Java String look better than any C/C++ strings version. This is what
I call close to optimal.
g) you don't have to choose between long int, unsigned int, WORD, DWORD,
size_t .... - close to optimal choice if forced on you.
h) You don't decide do you use internal or external functions
definitions, or do you use macro. - close to optimal choice if only one
possible.
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.
...
As you can guess, I can continue.
Yes, but all the benefits you are listing are things you *can't* do and
the things forced upon you. Where are the list of things you *can* do?
You make Java sound like a jail sentance. Yes, it COULD easily become jail. The beauty of Java is that all choices
are made so clever, that they are very close to optimal, and (I am sure
for me) that advantage of not having to think about alternatives
overweights possible gains from other choices.
It also makes different pieces of software much more compatible.


Cleverness is subjective. IMHO a lot of choices in Java where rather
dumb.

"Very close to optimal"...that seems like a fluff statement to me but
if you can quantify it I'll place more value in it.

Not having any choices doesn't seem to me to be that great.

I'm still looking for the can. You listed all the thing Java *can't*
do but haven't come with anything it can. I don't see much advantage
in *can't*.

Generally you can do anything on any general purpose computer language.
I can say you can write safe programs on Java, you can do GC on Java.
There is also very long list of things that is more easy to do on Java
(almost everything). For example.
Connect to databases.
Use http connections, requests and responses.
Write string to clipboard.
Write servlet (comparing to use CGI programs or ISAPI module).
and so on.

Apr 29 '06 #213
Bent C Dalager wrote:

Interestingly, of course, while there are no CPUs that support C++
instructions natively (that I know of anyway), there are those that
support Java bytecode natively. The conclusion being that while it is
possible to have a pure Java system, it is not possible to have a pure
C++ system :-)

Because C++ is compiled language, and has no defined intemediate
language, it is very difficult to see what Computer that "support C++
instructions natively" should look like. For Java there is defined
bytecode and so you can make computer to run this bytecode directly.
This doesn't mean that Java is better, but it does mean that speed
advantage of C++ wouldn't exist (it if still exists with modern JIT JVM)
on such computers.
Apr 29 '06 #214
Phlip wrote:
Ian Collins wrote:

You can do the same with a number of C++ compilers, whether or not they
support the 'export' keyword.

Newbie: Why do I have to define classes twice?

Guru: You don't define them twice. You declare them in header
files, define them in header files, and define their methods
in implementation files.

Newbie: Why do I have to de...scribe classes three times?

Because it makes then easier to read?

I've been doing a lot of PHP lately and the biggest problem I have is
not being able to see all of the methods on one page. So I end up
creating an interface for each class as a documentation tool.

--
Ian Collins.
Apr 29 '06 #215

Mishagam skrev:

[snip]
I understand that RAII is basically use automatically called
destructor's to dispose resources? That is correct. When the lifetime of an object, its destructor is
automatically called. I do not need to say that this is regardless of
whether an exception is thrown or not. I agree it is useful where it can be
used.
It works if you work with objects as values, it doesn't work if you work
with pointers or references. This is correct - and it should not work in such cases. In such cases destructor can easily leave
dangling pointer. I do not know that statement. If you work with references you are on your own, or
have to duplicate something like reference counting or Java GC. Replace references with pointers here and I agree. I don't
think you can work without using references in big program. (I assume again that you mean pointers here.)You surely can. Modern C++
uses almost no raw pointers. Instead it uses objects called smart
pointers and these could well rely on reference counting. I think because of this STL mostly works (in examples) with value
elements, and this creates a lot of problems - you cannot place
descended class objects were you can place base objects, you have to
deal with constructors, destructor's, copy constructors called in
strange places, you waste memory and so on. STL is value-based and rightly so in my opinion. For places where
value-based objects don't fit (your example with a container that
should hold elements of a type or descendants of that type), you simply
store a smart pointer. Also, you have to have
different generated code for different objects and use templates. This is partly true. By having different code generated for each type
you get far better runtime performance so this is a good thing. As an
example, the sort in C++ is three times faster than the C qsort for
double. This is primarily a result of having code inlined.
Still, sometimes code might be shared across different template-types.
E.g. std::vector<int > could share much of its code with
std::vector<uns igned>. And in
Java one Collections library works OK with any object.

If you do not use Java generics you basically end up with runtime type
checks. This is not nice.

/Peter

Apr 29 '06 #216
TJW

Andrew McDonagh <ne**@andmc.com > writes:
TJW wrote:
Hello,
On 28 Apr 2006 09:34:56 -0700 "Noah Roberts" <ro**********@g mail.com> writes:
Won't respond to your personal attack but I will respond to your claim
I am purposfully misinterpreting your statements.

As a purely outside observer to this thread, I found this
statement fairly amusing considering the following text that has
appeared in this thread.


snipped brilliantly researched response.

v cool TJW.


Thank you ... I got lucky on this one, a post of mine actually
made sense. :)

Peace,
TJW
Apr 29 '06 #217
TJW

"Noah Roberts" <ro**********@g mail.com> writes:
You can come to any conclusion you want and provide whatever view you
wish people to see if you quote people out of context.
I can, and I often do. Seriously, I was not trying to insult you.
That was in reply to someone telling me I'm a fundamentalist religious
nut because my parents apparently are because my name is Noah. That is
an incredibly stupid statement to make
.... I totally agree, any such statement is inappropriate. I think my
specific response to reading that statement was tempered however
because I thought that the poster was joking.

Everything in my reply fit, including the admision that the reply
itself was a personal attack that was not on topic...somethi ng you
neatly snipped from my post.
This is my error and was unintentional. I apologize, but this is
not totally my point. My point was simply that the set of
statements:
{
Statement 0: Ad-Hominem arguments are irrelevant and meaningless.
Statements 1..n: Ad-Hominem argument (i)
}
is inconsistent. I saw a series of statements in this thread that
match that pattern (qualified by the poster or not) which I found
humorous. Nothing against you personally, just a comment on what
the discussion had become.
Your post is no more informed, About the previous discussion on the costs/benefits of Java
vs. C++, you are 100% correct. I never claimed to be qualified to
engage in such a discussion. My comment however was on the thread
itself, which was informed as I quoted numerous references for the
single point I wanted to make.
balanced, Honestly, I'm not sure how this requirement applies in general to
a group that discusses the use of a programming language, but if
your referring to my omitted quote, again, I apologize.
or interesting than the person's to whom that above quote replies
to.

Matter of opinion. I happen to disagree.

I am way too new here to continue defending a mediocre joke, so I
will make this my last post in this thread.

Peace,
-TJW
Apr 29 '06 #218
peter koch wrote:
Mishagam skrev:
It works if you work with objects as values, it doesn't work if you work
with pointers or references. This is correct - and it should not work in such cases.
In such cases destructor can easily leave
dangling pointer.

I do not know that statement.

I mean here you pass pointer or C++ reference to your object, this
pointer is saved somewhere, and then you destruct you object. Then
pointer in pointing to basically random position. I name such pointer
dangling. I thought it is standard name for such pointers.
If you work with references you are on your own, or
have to duplicate something like reference counting or Java GC.

Replace references with pointers here and I agree.

You can work with C++ pointers or references. Both of them can have
problem of pointing to no longer existing objects.
I don't
think you can work without using references in big program.

(I assume again that you mean pointers here.)You surely can. Modern C++
uses almost no raw pointers. Instead it uses objects called smart
pointers and these could well rely on reference counting.

I, unfortunately, not very fluent in C++ smart pointers. I know that COM
objects used reference counting, and it was major pain in ass. However I
didn't use smart pointers there - mey be they would alliviate problem?
If you use reference counting you cannot be sure when you object gets
destructed, you cannot use RAII, you can get memory leak because
somebody forgot to delete reference. You are in the same position as in
Java, except that GC works with cyclic references.
I think because of this STL mostly works (in examples) with value
elements, and this creates a lot of problems - you cannot place
descended class objects were you can place base objects, you have to
deal with constructors, destructor's, copy constructors called in
strange places, you waste memory and so on.

STL is value-based and rightly so in my opinion.

Doesn't moving around full objects instead of just pointers to them feel
wasteful?
For places where value-based objects don't fit (your example with a container that
should hold elements of a type or descendants of that type), you simply
store a smart pointer. I never actively used smart pointers. I looked on Web - there are
actually a lot of different types of smart pointers in C++ (as usual,
Java has one close to optimal choice). I suspect it is another hole, not
"simply store a smart pointer".
Also, you have to have
different generated code for different objects and use templates.

This is partly true. By having different code generated for each type
you get far better runtime performance so this is a good thing. As an
example, the sort in C++ is three times faster than the C qsort for
double. This is primarily a result of having code inlined.

Yes, if in C you call custom function for every comparison of doubles it
should be slower. I bet if you sort array of structures C++ speed up
will disappear. Actually in Java they wrote separate sort procedures for
native types - because there are only about 8 native types it is
manageable. But all objects are sorted by the same procedure. And they
don't have to copy objects (with calling copy constructor and
destructor's) on each operation. I would be tempted to write benchmark
program, but feel too lazy. Still, sometimes code might be shared across different template-types.
E.g. std::vector<int > could share much of its code with
std::vector<uns igned>.
And in
Java one Collections library works OK with any object. If you do not use Java generics you basically end up with runtime type
checks. This is not nice.

Even in Java with generics I am almost sure there is only one compiled
library for all (Object) types.
/Peter

Apr 29 '06 #219
peter koch wrote:
Mishagam skrev:
Noah Roberts wrote:

[snip]
Third...COM is not C++, it is a MS specific standard of coding a set of
functionality in ANY language that can be used from ANY language
capable of interacting with COM. I do believe Java can be counted
among them but of course any such program instantly looses any platform
independance.

I programmed on COM on C/C++, and all COM procedures use HRESULT as
error code. Other often used COM Language is VB, where error codes
apparently are somehow hidden - I don't know VB very well. Java cannot
directly use COM, probably there exist JNI Libraries allowing
communications Java <-> COM through native calls.

This is absurd. If you program against a COM interface you use a
HRESULT. This is so in ANY language - even Java. Unless Java does not
support COM programming, of course.

What is absurd? I suspect you don't know what you are talking about. Are
you sure VB programmers use HRESULT? I cite "You, as the programmer,
never see the HRESULT; Visual Basic hides its existence to make your
code more manageable. " from
http://support.microsoft.com/kb/q189134/How To Raise an Error in Visual
Basic From Your C DLL
Does in mean VB doesn't support COM? Now that is absurd. VB is one of
main users of COM objects.
Even on C++ Microsoft likes to hide COM objects behind special kind of
smart pointers that convert HRESULT to exceptions.
Java, on the other side, doesn't support COM, but it is possible to
write library to communicate between Java and COM (as I wrote).
Finally, if you don't know then your doubts are meaningless.


/Peter

Apr 29 '06 #220

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
9867
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
9709
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
10609
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
10669
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
10308
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
7853
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
7028
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();...
1
4498
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
4086
muto222
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.