473,889 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

On Java and C++

Java programmers seem to always be whining about how confusing and
overly complex C++ appears to them. I would like to introduce an
explanation for this. Is it possible that Java programmers simply
aren't smart enough to understand C++?

This is not merely a whimsical hypothesis. Given my experience with
Java programmers --- the code they write and the conversations they
have --- Occam's Razor points to this explanation. For example,

"Oooh I'm confused about the difference between pointers, references,
and objects! How confusing!"

"Oooh operator overloading confuses me! The expression x + y is so
confusing, who knows what's happening with that? If x and y are
complex numbers, what the hell could x + y mean?"

"Oooh multiple inheritance is so confusing! Though I am both a father
and a programmer, I still find it so confusing how the same object can
be two different things! How confusing!"

"Oooh and virtual bases are so bizarre! I am a student --- myself
'the father' is the same student as myself 'the programmer' --- but
nonetheless the idea of virtual bases is absolutely confounding and
confusing to me!"

Again, Occam's Razor is a valuable tool here. In deciding among
competing hypotheses, choose the simplest one. To impartial observers
of indoctrinated Java programmers, the explanation is simple indeed.

Apr 26 '06
458 21637

"Walter Bright" <wa****@digital mars-nospamm.com> schrieb im
Newsbeitrag news:Xt******** *************** *******@comcast .com...
Gernot Frisch wrote:
The so called "ugly" features is what makes C++ so powerfull.


I don't agree with the fatalistic idea that a feature must be ugly
in order to be powerful. The warts in C++ are not due to its power,
but to its desire to integrate new features in while retaining
source compatibility with 30 years of past decisions, good and bad.

If you're willing to give up legacy compatibility, it's possible to
design a language with similar and even greater power, but in a much
simpler and straightforward package. Such is the D programming
language, www.digitalmars.com/d/

For an example of how an "ugly" power feature like templates can be
made easier (and even more powerful), see
www.digitalmars.com/d/templates-revisited.html .


OK. True, the D language has cleaned up old C inheritances C++ suffers
from. However, I doubt anyone would switch to D unless you provide a
large class library for almost everything. That's the only true
benefit of Java, the large std library.

I hope to see D grow and be _the_ (C++)++ one day, though.
Apr 27 '06 #21
>
OK. True, the D language has cleaned up old C inheritances C++ suffers
from. However, I doubt anyone would switch to D unless you provide a
large class library for almost everything. That's the only true
benefit of Java, the large std library.

Yes, large standard library helps. However Perl, Python, C# have
something close.
I would give additional benefits (for me).
a) You don't have to think should you include fields of have variables
as objects or references or pointers. It is decided for you usually
close to optimal way (closest to references).
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.
c) You don't have to decide about programming style. Sun provided
standard Java style.
d) You don't have to decide about naming of files and classes - they are
the same.
e) Logical package directory structure is forced on you.
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.
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.
Dropping all these choices first - makes programming easier, you have
less things to bother about, second - makes language smaller and more
easy to understand. Of course such approach could lead to very bad
language - but Java luckily has good design. And I thing C++ standard
committee just made bad design - introducing complexities which doesn't
add enough benefits to justify them.
Apr 27 '06 #22
a) You don't have to think should you include fields of have
variables
as objects or references or pointers. It is decided for you usually
close to optimal way (closest to references).
What about pointer to a pointer? A pointer is a pointer, a reference
is a reference, a variable is a variable. Period.
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$

c) You don't have to decide about programming style. Sun provided
standard Java style.
Juck!
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.
e) Logical package directory structure is forced on you.
What about freedom of choice?
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_!
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.
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.
That's a real feature of java and D! Include files totally suck!
Internal functions are a great benefit as well. Though I'd not want to
loose the preprocessor.
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.
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.




Apr 27 '06 #23
REH

Luc The Perverse wrote:
Java is simpler, cleaner - but programming is programming.


Yeah, and that's why I write real-time systems in Perl. Languages are
tools. Use the right one for the right job. No language has yet
filled the "one-size-fits-all" catagory.

REH

Apr 27 '06 #24
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"? 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.
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.
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
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++?
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.
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.

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.
Apr 27 '06 #25

"Bent C Dalager" <bc*@pvv.ntnu.n o> wrote in message
news:e2******** **@orkan.itea.n tnu.no...
In article <44************ ***********@new s.optusnet.com. au>,
benben <be******@yahoo .com.au> wrote:
Learning C++ is marginally more difficult than learning Java.


I hate feeding trolls but it is just unfair for C++...

I learned Javascript before C++. My impression is even though C++ is
noticeably more complex, it is not more difficult to learn than
Javascript.


That may say more about Javascript than it does about C++ though :-)


We're all aware Javascript is completely unrelated to Java right?
Apr 27 '06 #26

"Luc The Perverse" <sl************ ***********@cc. usu.edu> wrote in message
news:92******** ****@loki.cmear s.id.au...
"al pacino" <si************ *@gmail.com> wrote in message
news:11******** *************@g 10g2000cwb.goog legroups.com...
i am a student,
and i have seen many of my friends 'switch' over to java cos they shy
away from learning much involved language c++
and also they seem to like things like easy GUI interfacing than actual
programming (like practising data structures ..b trees et al.)


Learning C++ is marginally more difficult than learning Java.

I used to be a die hard C++ advocate - but the added complexity doesn't
really add a great deal of usability; but it is great for obscuring the
meaning of the code.

Java is simpler, cleaner - but programming is programming. Java is
designed to be able to more easily make integrated GUI apps. This might,
in turn, make the code of two programmers with otherwise equal talent, one
in C++ and one in Java, differ and their end results differ. In C++ you
have to reinvent the wheel all the time. Except, it's not like you're
rediscovering, just annoyingly doing the same thing repetitively to take
up more time. In Java you implement one of the provided algorithms, and
you are good to go, with an exponentially smaller possibility that the
underlying algorithm code is in some way flawed. (With as many Java users
as are out there, a bug should pop up pretty quick.) GUIs are easier, in
general, so the java programmer can use that time to make their GUI
better. Web examples (sample code) tend to work, unlike C++ where if you
download something, there is only a miniscule chance that it will compile
after 20-30 minutes of fiddling.

Blah - I'm just blabbering. My point is that coding in Java saves times,
and lessens bugs. It will make the end result better. All the bad
things I thought of Java are pretty much gone.

The reason I am replying is you just seem to have contempt. "Actual
Programming" problems will arise, they will just be less mundane.

I think you might be confusing Java with VB.

Trust me though - you can practice algorithms and data structures in
Java - I do so at least 3 times a week on topcoder.

--
LTP

:)


Well said. "Actual programmers" shouldnt spend a large chunk of dev time on
things like standard data structures, memory managment and well known
algorithms.
Apr 27 '06 #27
In comp.lang.java. advocacy, we***********@y ahoo.com
<we***********@ yahoo.com>
wrote
on 26 Apr 2006 15:05:15 -0700
<11************ **********@y43g 2000cwc.googleg roups.com>:
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!"


[rest snipped]

First rule of software: know thy tools. This includes
the computer, the compiler, and the environment.

Both Java and C++ aim for a niche: the specification of
instructions to a modern computer. There are, of course,
many differences.

[1] Java hides pointers. This can be a good or a bad
thing; it's good in that Java has the option of playing
garbage collect (built in). It's a bad thing when Java
developers forget and leave an object to moulder in
a global collection map and then wonder why there's a
"memory leak".

[2] Java does not have operator overloading. C++ does.
In C++, this can be a convenience but it also can lead to
some hairy expressions.

[3] Java does not have a C preprocessor. C++ does. And
one thought operator overloading was bad. The Obfuscated
C process is testimony to some of the abuses of a useful
construct; fortunately those are for humorous purposes.

[4] C++ doesn't have packaging. Java does. While there
are some quirks in the implementation of packaging in Java,
it's a very nice way to organize one's code.

[5] Java doesn't have explicit deletes. The garbage
collection is expected to take care of things. (There are
some exceptions; a FileOutputStrea m for example will be
left open indefinitely, even if the reference is lost.)

There's a fair number of others but these will do for a start.

In any event, many programmers, myself included, migrated
from C++ to Java. To call us stupid invites ridicule, if
not worse.

As for operator overloading -- I'll admit, I occasionally
miss it. Matrix operations in particular would benefit
somewhat from a shortening of the notation; one could write
P = M * N instead of P = M.multiplyBy(N) . But operator
overloading does complicate the language, requiring the
compiler to sort out whether an operator is overloaded or
not (and operator precedence issues). In Java it would
be especially bad as the operator may require a run-time
lookup.

If one assumes that an operator can be declared by the pseudo-code
(which looks suspiciously like C++, of course :-) )

String operator+ (String x, String y)
{
StringBuffer z = new StringBuffer();
z.append(x);
z.append(y);
return z.toString();
}

Integer operator+ (Integer x, Integer y)
{
return new Integer(x.intVa lue() + y.intValue());
}

and then have a code sequence

Object a;
Object b;
Object c = a + b;

what operator should be executed, and when should this be determined?
C++ doesn't have this problem, as all routines are determined at
compile time except for virtual methods.

It is possible Java could implement a C++-like solution (and complain
in the above case as I've not defined operator+(Objec t,Object)) but
someone will probably be unhappy with whatever solution is finally
implemented.

One can also compare Java to C#. I lack expertise in C# beyond what
I've seen in the press but know that C# has the interesting property of
converting an assignment:

a.b = c.d;

into a sequence of function calls:

a.setB(c.getD() );

by a declaration within the classes somehow.

This can get arbitrarily tricky. I'm not sure if I like this property
or not. As I understand it, interactions with [] further complicate
things.

Java avoids all this; except for an issue that one can have variable
lengths in each array row in an Object[][] variable (which is easy
to resolve with some care), one can be sure that

a.b = c.d;

means

a.b = c.d;

:-)

--
#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
Apr 27 '06 #28
Ben
REH wrote:
Luc The Perverse wrote:
Java is simpler, cleaner - but programming is programming.

Yeah, and that's why I write real-time systems in Perl. Languages are
tools. Use the right one for the right job. No language has yet
filled the "one-size-fits-all" catagory.

REH


I've programmed both in JAVA and C++

Try writing a OS in JAVA...wait is that even possible?

or try writing web based programs in C++, get ready for a headache...
Apr 27 '06 #29
>
c) You don't have to decide about programming style. Sun provided
standard Java style.
Juck!


You don't like Sun Style? I find it not worse than any other, and it has
advantage that most Java programmers use it. In C, for example, Linux
core uses one style, and Gnu uses other, incompatible style, and
Microsoft, of course, uses third.
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.


Of course everything I wrote here (style is exception) is enforced by
compiler. That's what compiler is for.
e) Logical package directory structure is forced on you.
What about freedom of choice?


My main idea in my post was that freedom of choice is often Bad. Anyway,
I don't insist on this as a law, only as my personal preference. May be
you value freedom of choice in programming more. Then C++ obviously has
advantages for you.
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_!


I benchmarked strings long time ago. My impression - C strings are much
faster, STL/CStrings have about the same speed (I don't remember
exactly) as Java strings. But C strings created their own (apparently
very big) category of security breaches. Bottom line - you don't lose
much, if anything, by sticking to Java strings.
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.


And I am a little bit sick of casting size_t to int. Or remembering what
to use: long long or _int64.

Well, if you knew C++ as good as Java, you wouldn't say so I guess.

I suspect it is not my fault that I better know Java than C++. I spend
10 years programming mostly on C++ and only 5 years mostly on Java. It
is just more easy to learn Java.
Apr 27 '06 #30

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
6823
by: Ravi Tallury | last post by:
Hi We are having issues with our application, certain portions of it stop responding while the rest of the application is fine. I am attaching the Java Core dump. If someone can let me know what the issue is. Thanks Ravi
1
6927
by: ptaz | last post by:
Hi I'm trying to run a web page but I get the following error. Ca anyone please tell me a solution to this. Thanks Ptaz HTTP Status 500 - type Exception report
11
9298
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
0
5664
by: mailkhurana | last post by:
Hii , I am trying to use a type 2 driver to connect to DB2 0n AIX 5 I have a small java test to class to establish a conneciton with the db .. I am NOT using WAS or any appserver When I try to connect to the DB I get the following exception at java.lang.ClassLoader$NativeLibrary.load(Native Method) at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2120)
1
9675
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej and I was wondering if anyone here would be able to give me some tips for young players such as myself, for learning the language. Is this the best Newsgroup for support with JAVA?
12
5939
by: Mark Fink | last post by:
I wrote a Jython class that inherits from a Java class and (thats the plan) overrides one method. Everything should stay the same. If I run this nothing happens whereas if I run the Java class it says: usage: java fit.FitServer host port socketTicket -v verbose I think this is because I do not understand the jython mechanism for inheritance (yet).
0
3295
by: jaywak | last post by:
Just tried running some code on Linux (2.4.21-32.0.1.EL and Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05)) and Windows XPSP2 (with Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)) and in both cases, get the following list returned from calling getDeclaredFields() on java.lang.ClassLoader via this code snippet: Field fields = loaderClass.getDeclaredFields(); for (int i = 0; i <...
1
4314
by: jaimemartin | last post by:
hello, I want to validate an xml by means of a schema (xsd). To do that first of all Im using a SchemaFactory. The problem is that if I run the code in Windows all works fine, but If I run it in Linux there is an error. The code that fails is the following: SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Im sure that code is ok. In fact, Ive found that in several...
0
3304
oll3i
by: oll3i | last post by:
package library.common; import java.sql.ResultSet; public interface LibraryInterface { public ResultSet getBookByAuthor(String author); public ResultSet getBookByName(String name);
0
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
11188
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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...
1
7991
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
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...
1
4644
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
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.