473,842 Members | 1,837 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 21557
Phlip wrote:
They /both/ suck.


go Ruby ..Go Ruby...Go Ruby

“I always knew one day Smalltalk would replace Java. I just didn’t know
it would be called Ruby." -- Kent Beck
Apr 27 '06 #81

The Ghost In The Machine skrev:

[snip]
"finally" is to RAII as manual transmission is to
automatic, from the looks of things.
Not at all. RAII is to finally what a printing machine is to a pen.
RAII simplifies a nontrivial and tedious task. Or do you always check
for your objects being of the IDisposable type before deciding if you
can leave their destruction to the garbage collector or if you will
have to destroy them manually?
If not - how will your program cope with classes that change?
Also - how do you write generic code if you do not know if you will
have to destroy your objects - except than by using run-time
information?

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


Apr 27 '06 #82

Oliver Wong skrev:
"Noah Roberts" <ro**********@g mail.com> wrote in message
news:11******** ************@u7 2g2000cwu.googl egroups.com...

Roedy Green wrote:
The other huge benefit is platform independence. Java has everything
removed that would temp you to write platform dependent code.
Well, that is one area where Java *can't* be used then isn't it.

Another can't. Where is the can?


I think it's a bit silly to complain that you *can't* write platform
dependent code in Java.

If you goal is to intentionally write platform dependent code, maybe
Java isn't for you.


Which ironically precludes writing the Java library in Java.

/Peter
- Oliver


Apr 27 '06 #83
* Remon van Vliet:

Meanwhile, in the real world most recent garbage collectors
outperform manual memory managment in the vast majority of applications, and
as a bonus you get the complete lack of memory leaks and such.


All three of those assertions are incorrect.

(1) the explicit assertion of guaranteed performance is incorrect, (2)
the explicit assertion of no memory leaks is incorrect, and (3) the
implicit assertion of no automatic garbage collection in C++, as if it
was a non-C++ only technique, is incorrect.

Such incorrect, emotionally based beliefs help create bad software.

I think perhaps the easiest for you to see the incorrectness of, is (2),
the belief that no memory leaks occur. A simple way to create a memory
leak in Java is to install an object in some global list of objects to
be called back on (event handling), then forget to remove it.

In short, what you wrote is rubbish, and dangerous rubbish.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Apr 27 '06 #84
In article <11************ **********@j33g 2000cwa.googleg roups.com>,
peter koch <pe************ ***@gmail.com> wrote:

Oliver Wong skrev:

If you goal is to intentionally write platform dependent code, maybe
Java isn't for you.


Which ironically precludes writing the Java library in Java.


Not any more so than for any other non-assembly language.

At some point, C++ also needs to fall back to assembly code to
implement its basic functions - even if that means bootstrapping a
compiler chain up from a simple assembly-based C compiler.

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 :-)

(No, it's not an important point.)

Cheers
Bent D
--
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
Apr 27 '06 #85

Chris Smith skrev:
Roedy Green wrote:
Mixing exception handling and memory management boggles the human
mind.

Noah Roberts <ro**********@g mail.com> wrote:
Only one incapable of learning very simple techniques to make it a
non-issue.

http://www.hackcraft.net/raii/


There are two questions being considered simultaneously here. One is
what is required to produce useful software in a language. The other
matter is what is required to understand that language. I side with the
position that a language that's hard to understand has a weakness in
this even if it remains possible to write software using that language.


I agree here. Readability matters a lot. And here C++ is a clear
winner, due to its more advanced features such as templates, operator
overloading and RAII,
Exception handling and memory management IS tricky in C++. I must disagree. Exception handling is far easier in C++, due primarily
to RAII. Consider:

// C++
func()
{
class_with_poss ible_ressource cwpr;
dosomethingwith (cwpr);
}

// Java

func()
{
class_with_poss ible_ressource cwpr = new
class_with_poss ible_ressource ;
if (cwpr->did_initialise _properly())
{
try
{
dosomethingwith (cwpr);
}
finally
{
try
{
idisp = (IDisposable)cw pr;
idisp->Dispose();
}
catch (...)
{
}
}
}
}
Four simple lines of C++ becomes 21 lines of complex and convoluted
Java-code.
If you know that the class contains a ressource you save four lines -
and if you know that the class does not contain a ressource (and you
dare betting your program that it newer will) you go down to seven
lines - almost the double of C++.

[snip] RAII is a different matter. It's a nice feature to have; but it doesn't
make the language any easier to understand.
So the Java func above is as easy to understand as the C++-one?? Come
on - you do not really mean that. Also you have a huge problem writing
generic code in Java .... those ugly and presumably costly runtime
checks have to be made all the time.

/Peter
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


Apr 27 '06 #86

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 :-)


Yeah, and that is a valid comparison...

Hey, my CPU will run C++ byte code natively but there are no CPU's that
run Java source code...guess Java sucks then.

Do I hear a vacuum?

Apr 27 '06 #87
Noah Roberts schrieb:
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 :-)


Yeah, and that is a valid comparison...

Hey, my CPU will run C++ byte code natively but there are no CPU's that
run Java source code...guess Java sucks then.

Are you sure that you know what byte code is?
Timo
Apr 27 '06 #88

Remon van Vliet skrev:
I normally dont get involved with pissing contests, but there's only so much
bs in a single post i can take without replying...

<snip>
b) You don't have to bother to use auto_pointer (not working with
collections) or new delete or automatic destructor. It is decided for you
to use something like auto_ptr but much better.
I like new/delete. Makes me feel I'm in charge. Just my .02$


So, your entire reasoning behind preferring manual memory managment over
garbage collection is that "you feel in charge"?


The problem is not as simple as that. The fact is that garbage
collection is useful for one resource only: memory. All other resources
must be handled explicitly in Java. Depending on your application, this
might be a small or a large problem, but the fact is that RAII in C++
gives you a way to cope with all resources in a uniform way.
You should give assembly
language a go. Meanwhile, in the real world most recent garbage collectors
outperform manual memory managment in the vast majority of applications, and
as a bonus you get the complete lack of memory leaks and such. What do you mean with "and such"? I believe C++ is in the best position
to guarantee the whole thing. Java gives you protection wrt
memory-leaks and C++ gives you protection regardless of the resource.
Also, most C++ programs can use garbage collection if they want to - if
only they do not hide their pointers. This is old knowledge, so I
assume that you are aware of this?
Last but not least, the advantage of garbage collection over manual
memory management is not so evident as you seem to imply. If you look
at the newest, better performing collectors you should also compare
this to the newest and smartest allocators. Also remember that C++
gives you choices - e.g. to use a specialised allocator or to simply
use stackbased variables.
c) You don't have to decide about programming style. Sun provided
standard Java style.
Juck!


I'll grant you that it's a matter of taste, but no self respecting developer
will consider standards a bad thing. If you do, draw your conclusions.


Well - there are plenty of standards around. You should use the
standard that fits your purpose, thats what they are there for. Javas
straight-jacket is not an advantage in my eyes. E.g. I do not
understand why each class MUST have its own file (unless you make that
class a secondary citizen).
d) You don't have to decide about naming of files and classes - they are
the same.
no, they _have to be_ the same. Otherwise the compiler pukes.


And the ability to stick tons of classes in a single file with a non-related
name would be a good thing because....? Again, standards -> good


Bad programming is far more than that. I do not see any correlation
here.
e) Logical package directory structure is forced on you.
What about freedom of choice?


Can you think of a single instance where having an illogical directory
structure is preferred over a logical one?
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.


Yeah, and a lot slower in some cases. User std::string where you need
dynamic strings, use char[] where you need static strings. You don't have
to - but you _can_!


When was the last time you benchmarked Java strings vs. C++?


There are three kinds of lies. Lies, statistics and benchmarks.... or
so I've heard. The nice thing about C++ strings is that the number of
characters in a string is a O(1) operation. In Java, you would have to
check the number of surrogates making it a O(n) operation. Also C++
strings are more powerful than Java strings. All in all I believe I'd
prefer using C++ strings, switching to some specialised class in the
unlikely case string-handling did turn up to take a significand part of
my programs execution time.
g) you don't have to choose between long int, unsigned int, WORD, DWORD,
size_t .... - close to optimal choice if forced on you.
Just a question of style. I use the built-in tpyes for everything.


It's freedom that doesnt add anything but confusion and hurts readability.


Javas type system is not freedom but rather a jail. It has prevented
porting of Java to several platforms, it gives cumbersome Unicode
support and it forces Java to stick with inefficient 32-bit integers in
a world that is soon turning to 64 bits.
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.
?? I don't understand that. You can't define operators in Java, can you?
Defining operators is one of the most important things for OOP IMHO.

He's not claiming you can, he simply says the exact same functionality can
be achieved albeit more verbose (i.e. .add rather than +). There are
certainly instances where operator overloading provides more readable code,
but at the same time it can also be the cause of rather unpredictable code.
On this point my stance is that if used with care operator overloading is a
pretty neat thing.
And I thing C++ standard committee just made bad design - introducing
complexities which doesn't add enough benefits to justify them.


Well, if you knew C++ as good as Java, you wouldn't say so I guess.
Anyway - I don't give a **** about what others use to write stuff, so this
is all just blahblah about nothing. There's no point making one language
better than the other. You will pick what suits you best or what your boss
indoctrinates on you.


Ofcourse there's a point in making languages "better" or at least different
than others. Sometimes a language is simply outdated, sometimes it's just
not a viable option for certain applications (people generally dont write
web-based application in C++ for example, just as you wont find many
commercial games or OSs written in Java). As for bosses, people usually get
a job based on their language skills and preferences, not the other way
around.


I fully agree here.
Anyway. there's room for both, but most of your arguments in the post above
are flawed or outdated in my opinion, as i feel you're considering rather
obvious weaknesses of C++ to be benefits. And to the OP, anyone claiming C++
programmers are somehow better than Java programmers is a tool. 90% of
skills related to being a "good developer" is completely unrelated to the
language you're using.

And here too. Sort of at least! ;-)

/Peter

Apr 27 '06 #89
On Fri, 28 Apr 2006 00:01:48 +0200, "Alf P. Steinbach"
<al***@start.no > wrote, quoted or indirectly quoted someone who said :
I think perhaps the easiest for you to see the incorrectness of, is (2),
the belief that no memory leaks occur. A simple way to create a memory
leak in Java is to install an object in some global list of objects to
be called back on (event handling), then forget to remove it.


see http://mindprod.com/jgloss/packratting.html

I think you are quibbling over terminology. A leak would be an object
nothing pointed to continuing to tie up ram. Packratting is holding
on to objects you will never need again. Unless you ran a program
twice and studied the history, there is no way you could have the ESP
to determine that even in theory.
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
Apr 27 '06 #90

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
9870
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
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,...
0
10610
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
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...
0
9451
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...
1
7854
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
7030
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
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
4087
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.