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

Home Posts Topics Members FAQ

On Java and C++

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

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

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

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

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

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

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

Apr 26 '06
458 21637
In comp.lang.java. advocacy, Remon van Vliet
<re***@exmachin a.nl>
wrote
on Thu, 27 Apr 2006 20:44:11 +0200
<44************ ***********@new s.xs4all.nl>:

"Walter Bright" <wa****@digital mars-nospamm.com> wrote in message
news:Dc******** *************** *******@comcast .com...
Noah Roberts wrote:
Roedy Green wrote:
On Thu, 27 Apr 2006 15:06:53 +0200, "Gernot Frisch" <Me@Privacy.net >
wrote, quoted or indirectly quoted someone who said :

Mixing exception handling and memory management boggles the human
mind.

Only one incapable of learning very simple techniques to make it a
non-issue.

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


There's another way to do it - scope guard. Here's an article on it:
http://www.digitalmars.com/d/exception-safe.html

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


What point am i missing if i mention the "finally" block in Java?


"finally" is to RAII as manual transmission is to
automatic, from the looks of things.

--
#191, ew****@earthlin k.net
Windows Vista. Because it's time to refresh your hardware. Trust us.
Apr 27 '06 #61
Remon van Vliet <re***@exmachin a.nl> wrote:
Have you ever used Java and actually ran into an issue that requires
RAII?


Of course no one has. There are no issues that require RAII. That's
irrelevant to the question of whether it is useful. Certainly,
try/finally gets cumbersome sometimes.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Apr 27 '06 #62
> 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.
Exception handling and memory management IS tricky in C++. So is the
relationship between function overloading, implicit type conversions,
and templates.

RAII is a different matter. It's a nice feature to have; but it doesn't
make the language any easier to understand.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Apr 27 '06 #63

Chris Smith wrote:
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.
Exception handling and memory management IS tricky in C++. So is the
relationship between function overloading, implicit type conversions,
and templates.


Lots of silly statements but no backing. "X is hard." Meaningless.
RAII is a different matter. It's a nice feature to have; but it doesn't
make the language any easier to understand.


Actually, RAII is at the HEART of this matter as it is a commonly used
technique to deal with the issue put forth. It is a very simple
concept and it works not only for memory management but also any other
resource that needs to be aquired and released.

Apr 27 '06 #64
Remon van Vliet wrote:
"Walter Bright" <wa****@digital mars-nospamm.com> wrote in message
news:Dc******** *************** *******@comcast .com...
Noah Roberts wrote:
Only one incapable of learning very simple techniques to make it a
non-issue.

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

There's another way to do it - scope guard. Here's an article on it:
http://www.digitalmars.com/d/exception-safe.html

What point am i missing if i mention the "finally" block in Java?


'finally' works fine for one level of undo. It doesn't work so well (and
neither does RAII) if there are multiple operations that must all
succeed or none have happened. For example, if a transaction consists of
transactions A, B, and C, and A and B succeed but C fails, one must
unwind B and C. The article goes into more depth with this including
examples.

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

Apr 27 '06 #65
Noah Roberts wrote:
Also, you could read that article above which shows some shortcommings
of both RAII and finally. However, the "scope guard" appears to be a D
language particular construct so is rather moot in this discussion.


There's a link at the end of the article with Andrei Alexandrescu's
technique for doing a limited form of scope guard in C++.

http://www.digitalmars.com/d/exception-safe.html

-Walter Bright
www.digitalmars.com C, C++, D programming language compilers
Apr 27 '06 #66
In article <44************ ***********@new s.xs4all.nl>,
Remon van Vliet <re***@exmachin a.nl> wrote:

We're all aware Javascript is completely unrelated to Java right?


Well, "completely unrelated" may be going a bit too far (it's more
like the wayward half brother that comes around to borrow money from
you every now and then, who you don't like to talk about in polite
company) but it is definately a different language.

Cheers
Bent D
--
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
Apr 27 '06 #67
Remon van Vliet wrote:
Have you ever used Java
No
and actually ran into an issue that requires RAII?


Require is a strong word. You can always do without RAII. You just have
a greater chance of losing precious time trying to figure out where
exactly have you forgotten to release that mutex...

Garbage collector may be good when it comes to releasing memory, but
memory is not the only resource you use. How about files, network
streams, database connections, synchronization primitives, etc?

A reply from "The Ghost In The Machine" has mentioned try..finally.
Whenever you use that construct to safely dispose of a resource, you're
better off using RAII.

Btw, I'm not really sure, but is the finally block executed, when you do
'return' from inside the try block?

--
Martin
Apr 27 '06 #68
In article <e2**********@s olaris.cc.vt.ed u>, Ben <be******@vt.ed u> wrote:

I've programmed both in JAVA and C++

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


This is easily possible (and reasonably common) on smart card chips,
many of which support Java bytecode natively.

Java-based CPUs for desktops have been tried I think, but it didn't
take off.

Cheers
Bent D
--
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
Apr 27 '06 #69
* Walter Bright:
Noah Roberts wrote:
Also, you could read that article above which shows some shortcommings
of both RAII and finally. However, the "scope guard" appears to be a D
language particular construct so is rather moot in this discussion.


There's a link at the end of the article with Andrei Alexandrescu's
technique for doing a limited form of scope guard in C++.

http://www.digitalmars.com/d/exception-safe.html


I think you should get the attributions right (sorry, how could I put
this in a more gentle way?): ScopeGuard was Petri Marginean's invention,
and he co-authored the CUJ article with Andrei.

--
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 #70

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
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9805
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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...
0
10785
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
10887
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10439
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
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
6025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.