473,889 Members | 1,394 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 21629
Phlip wrote:
- impersonates the worst of C++ - typecasts
for simple containers, two different kinds
of type to store a stupid Integer, multiple
String classes, What are you talking about?
and last but least generics! - arrays aren't really arrays. But they really
are. Kinda.
- static typing, to flatter Pascal with a vain
impersonation that, instead, forces you to
break typesafety just to get anything done. Types are checked on each casting, but in run-time. You begin whining
about absence of dynamic typing few lines lower. - 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 What 'interface' means is much more clear than what 'virtual' means.
Nobody is interested much in what hardware actually do. - provides whole new categories of bugs, based
on zombie objects, non-deterministic
destructors, redundant finally blocks, all
under the excuse we are saving you from all
the C++ memory errors that a good standard
library implementation will save you from
anyway Call me when memory errors will disappear from C++. STL and templates
are so complex, I bet they actually increase number of errors.
- why the >F---< does Netbeans ask me where
the _same_ JAR files are, _each_ time I
launch it??? It feels the sucker ;) - a marketing campaign that teaches newbies
that a language is good if only smart
people can figure out how to use it
- GUIs require block closures and dynamic
typing. But what language does your boss
tell you to write the GUI in???

Apr 29 '06 #221

Mishagam wrote:
Noah Roberts wrote:
Mishagam wrote:
And of course one of main items:
j: In Java you generally don't have to think how to report error - you
throw Exception. In C++ you have different conventions for different
systems changing over time. Some programs return NULL or 0 or -1 or
SIGNALS ..., Microsoft COM programs returned HRESULT, lately C++ started
using exceptions, but I am sure it is still only one of choices. I don't
know, but doubt that C++ exceptions are as convenient as in Java. Of
course this result of Java being designed later when exceptions already
were well known .


Where to start...

First, are you really making the statement that Java supports no other
error reporting facility? That is blatantly false but let's assume for
the moment that is true and ask ourselves if that is actually a good
thing...

You can of course return 0 or null or false or something on error, but
most programmers and libraries use Exceptions. Exceptions in Java are
very convenient, there is usually no sense not to use them.


No different than C++ there then. The only thing that could apply is
there are people who insist on using the old C ways for everything and
pretend not to use exceptions. Usually they come up with some make
believe argument about performance but they are usually arguing from
ignorance with small nuggets of fact from something some expert said 20
years ago.

Frankly, unless you do everything with the old C functions and don't
use a single class out of the std lib you ARE using exceptions in
C++...some people just don't get it though.

At any rate, the languages have little difference in this area from
what I can tell. Slightly different approaches but in effect the same
idea.

Apr 29 '06 #222

Mishagam wrote:
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).


Going off on a bit of a tanget here now. The real point wrt to COM is
that COM is a red herring. We could discuss the various ways in which
some API's hide the facts of COM from the programmer but what bearing
does it have on the conversation? None that I can see.

COM is an MS creation meant for use on their systems, with their
languages, and their toolsets. Any other use is asking for
unpleasantries. VB and the .NET languages make COM easy because they
are both creations of the same company with the same target platforms;
in these languages a COM object looks like any other object. I doubt
Java has a very nice COM interface and I know working with it in C++ is
less than ideal.

At any rate, COM is unimportant. It's use in this argument was
fallacy. We should move on.

Apr 29 '06 #223

Mishagam wrote:
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.


That comparison is quite a stretch. GC is, as far as I know and as far
as Java implements it, totally unaccessable to the programmer. Can you
force the GC to delete anything? There may be certain times when you
can expect the GC to do some cleanup but you cannot guarantee it nor
can you control it. On the other hand, refrence counting using smart
pointers is 100% programmer controlled. You _can_ force something to
get deleted and you know for certain that the object will get deleted
the instant the last reference to it leaves scope or is destroyed.
This is a totally dependable action that is 100% guaranteed. With the
GC you can have no references to an object but it hangs out until who
knows when and then gets destroyed sometime after the last reference to
it leaves scope or is destroyed..../sometime/ after.

Does that mean it works if the programmer doesn't work? No. But it
means that RAII _can_ be depended on to perform the actions it has been
described so long as the programmer does their job. Requiring correct
code is not unreasonable and in reality RAII is quite effective at
keeping a lot of bugs out of code so long as it is followed.
STL is value-based and rightly so in my opinion.

Doesn't moving around full objects instead of just pointers to them feel
wasteful?


As is said, you can store pointers. They don't have to be smart but
then you do have to be. If you use smart pointers you can be dumb and
get away with much more.
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).


Java has no such choice. Java doesn't need smart pointers as it has no
pointers to begin with. Nor could it support a construct remotely
resembling a smart pointer. Half of the benefits of smart pointers are
the fact that they look like any other pointer and can be used anywhere
a normal pointer would be...this requires operator overloading.

A smart pointer is nothing else but an RAII wrapper around a gatherable
resource that must be released. Most of the time we are speaking of
memory and some dynamically allocated object. There are several types
because there are several targets. One pointer does not fit all
situations. For instance, should it check to be sure the object exists
before dereferencing it? Does it need some sort of shared process
locking mechanism? Not everyone wants these things....choic e is good
in this case as it allows one to choose the correct mechanism for their
needs. There is no "most optimal" choice here.

I can't parse the rest of the post.

Apr 29 '06 #224
Phlip wrote:
Ruby: [snipped]
Java: [snipped]
C++ (deep breath): [snipped -- reluctantly]


Good rant. Enjoyable. Thanks.

I'd pick different points to, um, pick on in all three languages, but -- what
the hell -- it's still just shooting fish in a barrel.

-- chris

Apr 29 '06 #225
Ian Collins wrote:
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.


This is very easily over come by using a decent IDE which shows all the
method signatures - all the time. eclipse, intellj, etc...

but then again some strange people still think vi is good.....

Apr 29 '06 #226

"Noah Roberts" <ro**********@g mail.com> wrote in message
news:11******** *************@y 43g2000cwc.goog legroups.com...

Phlip wrote:
[snip]

And the moral is....
We should all be using Objective-C.


That's a good one, but it's funnier this way:

And the moral is...
We should all be using Visual Basic.
Apr 29 '06 #227
"Larry Barowski" <MElarrybar-AT-eng_DOT_auburnA NOTHERDOTeduEND > wrote in
message news:n8******** *************** *******@comcast .com...

"Noah Roberts" <ro**********@g mail.com> wrote in message
news:11******** *************@y 43g2000cwc.goog legroups.com...

Phlip wrote:
[snip]

And the moral is....
We should all be using Objective-C.


That's a good one, but it's funnier this way:

And the moral is...
We should all be using Visual Basic.


Oh . . .was it a joke before?

I get it now

--
LTP

:)
Apr 29 '06 #228
On Sat, 29 Apr 2006 03:59:04 -0500 "Larry Barowski"
<MElarrybar-AT-eng_DOT_auburnA NOTHERDOTeduEND > waved a wand and this
message magically appeared:
We should all be using Visual Basic.


Death to all VB programmers and the buggers that dreamed up the
language!
NB: It's a JOKE!
--
http://www.munted.org.uk

Take a nap, it saves lives.
Apr 29 '06 #229
Phlip <ph*******@gmai l.com> writes:
- write once debug everywhere
Less of an issue now than back in the horrid days of applets.
- forgets everything on all its CLASSPATHs at
the drop of a hat
There's no such thing as CLASSPATHs in Java, only ClassLoaders, which
may or may not use something called CLASSPATH. I have luckily not run
into a case where a ClassLoader suddenly forgot all its classes.
- impersonates the worst of C++ - typecasts
for simple containers, two different kinds
of type to store a stupid Integer, multiple
String classes, and last but least generics!
Well the latter cancels out the first. Pick your poison I guess.
- arrays aren't really arrays. But they really
are. Kinda.
They are. But they're not C/C++ "syntactic sugar for pointers".
- pretends you broke something if your file
name differs from your class name. Figure
it out, stoopid!
You can have lots of classes in a source file that differ from the
file name, but none of them can be top-level public ones.
- when a smart editor like Eclipse can finish
every line for you, it makes you wonder
what the language is _there_ for!
Noone prevents you from using vi to write Java. Well, maybe the Emacs
tribalists do.
- 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
Language defines what is virtual or not. It's up to the (virtual)
hardware to comply.
- instead of providing a narrow and reasonable
implementation of multiple inheritance like
C++ (or an alternate "mixin" system like
Ruby) we instead get endless lectures,
endlessly repeated by newbies, about why
real programmers don't need multiple
inheritance of implementation
The syntax for multiple inheritance of implementation in Java is more
convoluted, but doable. (It involves delegate objects, nested member
classes if necessary etc.)
- at least C++ makes some of the benefits
of dynamic typing available. Java instead
enforces such a narrow view of static
typing that you can't even simulate
those benefits
Is that the "let's pretend this block of memory is something else"
stuff "inherited" from C's union and void*?
- GUIs require block closures and dynamic
typing.


Whatever for? I've written GUIs in Java, and the Swing MVC system is
decent enough to use. Where do you need either of those?
Apr 29 '06 #230

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
6926
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
5938
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
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
11187
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
10784
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
9602
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
6021
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
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
4248
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
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.