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

Bent C Dalager wrote:
In article <MP************ ************@ne ws.sunsite.dk>,
Jerry Coffin <jc*****@taeus. com> wrote:

The primary advantage to encapsulating otherwise public data into
accessors that don't actually add anything is that access to this data
can later be easily changed to do something interesting.


Yes,

One can change the value (if later computation is required) without
changing the interface. Resolution requirements change come to mind.
All said, how about the client specifying what he want.
template <class T>
struct IfToData //Or model from MVC
{
virtual const T& get( boost::void_<T> ) = 0;
};

....now the one getting specifies what he wants - his data now could
become:
boost::weak_ptr <IfToData<int > > myDataModel_;

This also makes him independent of the client from whom he receives
data...

Regards,

W


It is a poor man's encapsulation, but it's still better than just
having public data fields.

Cheers
Bent D
--
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs


May 5 '06 #391
In article <e3**********@o rkan.itea.ntnu. no>,
bc*@pvv.ntnu.no says...
In article <MP************ ************@ne ws.sunsite.dk>,
Jerry Coffin <jc*****@taeus. com> wrote:

Or that your variables aren't really of the correct type
to start with. From what I've seen, the majority of
getters and setters don't really do anything, and are
exactly equivalent to public data with a really ugly
syntax.
The primary advantage to encapsulating otherwise public data into
accessors that don't actually add anything is that access to this data
can later be easily changed to do something interesting.


If you'd read what I posted (the code in particular)
you'd realize that the same is possible when you DO use
public variables.
It is a poor man's encapsulation, but it's still better than just
having public data fields.


No, it's really not.

--
Later,
Jerry.

The universe is a figment of its own imagination.
May 5 '06 #392
"Bent C Dalager" <bc*@pvv.ntnu.n o> wrote in message
news:e3******** **@orkan.itea.n tnu.no...
In article <MP************ ************@ne ws.sunsite.dk>,
Jerry Coffin <jc*****@taeus. com> wrote:

Or that your variables aren't really of the correct type
to start with. From what I've seen, the majority of
getters and setters don't really do anything, and are
exactly equivalent to public data with a really ugly
syntax.


The primary advantage to encapsulating otherwise public data into
accessors that don't actually add anything is that access to this data
can later be easily changed to do something interesting.

It is a poor man's encapsulation, but it's still better than just
having public data fields.


The code I'm working with has two classes that do almost the same thing,
because the code was built by merging two other programs together.

<Java>
class NodeToken {
public int beginColumn, endColumn;
}

class Token {
public int startColumn, endColumn;
}
</Java>

I'm trying to merge these two classes together. If they had used accessor
methods, I could have a methods setStartColumn( int) and setBeginColumn( int)
affect the same private field, so that the changes would be seen by either
interfaces. Unfortunately, they didn't use accessor methods, and instead
used public fields, so now I've got to start by adding the accessor methods
to each seperate classes, mark the fields as deprecated, check for all
access to those fields, change those to invoke the accessor methods, then
merge the class, then simplify the API.

- Oliver

May 5 '06 #393

Oliver Wong wrote:
"Bent C Dalager" <bc*@pvv.ntnu.n o> wrote in message
news:e3******** **@orkan.itea.n tnu.no...
In article <MP************ ************@ne ws.sunsite.dk>,
Jerry Coffin <jc*****@taeus. com> wrote:

Or that your variables aren't really of the correct type
to start with. From what I've seen, the majority of
getters and setters don't really do anything, and are
exactly equivalent to public data with a really ugly
syntax.


The primary advantage to encapsulating otherwise public data into
accessors that don't actually add anything is that access to this data
can later be easily changed to do something interesting.

It is a poor man's encapsulation, but it's still better than just
having public data fields.


The code I'm working with has two classes that do almost the same thing,
because the code was built by merging two other programs together.

<Java>
class NodeToken {
public int beginColumn, endColumn;
}

class Token {
public int startColumn, endColumn;
}
</Java>

I'm trying to merge these two classes together. If they had used accessor
methods, I could have a methods setStartColumn( int) and setBeginColumn( int)
affect the same private field, so that the changes would be seen by either
interfaces. Unfortunately, they didn't use accessor methods, and instead
used public fields, so now I've got to start by adding the accessor methods
to each seperate classes, mark the fields as deprecated, check for all
access to those fields, change those to invoke the accessor methods, then
merge the class, then simplify the API.


Interestingly one thing the Java camp never brought up was the tools
they have available to them to make them more productive. Among those
tools are much more sofisticated refactoring tools. The only one I
have been able to find for C++ has been Ref+ and though it does a lot
it is still missing a lot of refactors you get with just about every
version of Java or .Net refactor tool out there. I'm going to blame
this on parsing.

Encapsulate Member is a very common refactor and comes in most tools,
including Ref+, and makes the above process completely automatic. Pop
up a wizard, set a couple of values, and let it go do its thing. They
usually work quite well and I suspect the Java version to be even more
accurate. You use this refactor when you find a public variable that
needs to be encapsulated in a getter and/or setter so that you can
alter behavior or when you need to change the variable to some other
form and you use it even internally to your class.

May 5 '06 #394
In article <MP************ ************@ne ws.sunsite.dk>,
Jerry Coffin <jc*****@taeus. com> wrote:

If you'd read what I posted (the code in particular)
you'd realize that the same is possible when you DO use
public variables.


My comment was largely based on language neutrality. I would rephrase
it to only cover languages that do not have other means of
accomplishing the same effect.

Data encapsulation is the goal. Trivial getX/setX accessors are a
means to reach that goal, and quite defensible in languages that
provide no other (better) means of getting there.

I need to add that in the context of the original suggestion (that
being able to directly access another object's state is wrong in
itself), your operator-based approach would be equally wrong, only
with a nicer syntax. It remains a poor man's approach to
encapsulation: Any algorithms that need to alter an object's state
should be internal to that object itself, not external to it.

According to this philosophy, you would never write
employee.wage *= 1.1;
You would write
employee.raiseW agePercent(10);

Cheers
Bent D
--
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
May 5 '06 #395
In article <11************ **********@e56g 2000cwe.googleg roups.com>,
Noah Roberts <ro**********@g mail.com> wrote:

Interestingl y one thing the Java camp never brought up was the tools
they have available to them to make them more productive. Among those
tools are much more sofisticated refactoring tools. The only one I
have been able to find for C++ has been Ref+ and though it does a lot
it is still missing a lot of refactors you get with just about every
version of Java or .Net refactor tool out there. I'm going to blame
this on parsing.


xref-tech.com has XRefactory. I have only used it on C and Java but I
understand they now support C++.

It's quite expensive for hobby users though, and I blame _that_ on
parsing :-)

Cheers
Bent D
--
Bent Dalager - bc*@pvv.org - http://www.pvv.org/~bcd
powered by emacs
May 5 '06 #396
Walter Bright <wa****@digital mars-nospamm.com> wrote:
Mishagam wrote:
I think the fact that nobody uses D means suggests that it has not only
one stupid feature, but a lot of stupid features.


For a stupid language nobody uses, the D programming language is doing
remarkably well, having moved up to number 19 on
http://www.tiobe.com/tpci.htm


That means it's a language people mention on web pages, not that it's a
language people use.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
May 5 '06 #397
Oliver Wong <ow***@castorte ch.com> wrote:
For a stupid language nobody uses, the D programming language is doing
remarkably well, having moved up to number 19 on
http://www.tiobe.com/tpci.htm


(referring to http://www.tiobe.com/tiobe_index/images/tpci_trends.gif as
of May 2nd, 2006): I wonder what happened in 2004 that made Java drop
considerably, and everything else jump up a bit.


If you read the FAQ, they point out that it was a change in the way
Google indexed web pages. I won't speculate (though, clearly, I'm okay
with implying) about what it means when the single biggest point made by
this index turns out to just be an artifact of their methodology.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
May 5 '06 #398
peter koch <pe************ ***@gmail.com> wrote:
So e.g. Swing, JDBC and Vector are all implemented in Java? Without a
single JNI-call in the code? It seems my knowledge of Java needs an
update.


Considered in turn:

Swing: The major part of Swing is written in Java. There are some small
pieces (the only one that comes to mind is the FileSystemView class)
that are not. Of course, Swing depends on AWT, which is implemented
partly in other languages.

JDBC: The JDBC API is completely written in Java. It would have been
silly to use native code for something that is basically just a bunch of
glue. Whether JDBC drivers are written entirely in Java depends on the
driver. About 90% of them are, but a few are not. Oracle, for example,
provides both a pure Java driver and a driver that uses JNI, but I don't
know of anyone using the latter. The only driver that I've contributed
to and thus worked with closely was PostgreSQL, and that's certainly
100% Java.

Vector: Yes, it's all in Java. Again, it would be silly to implement
this in native code. The result would perform poorly and be harder to
maintain.

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

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
May 5 '06 #399

"Noah Roberts" <ro**********@g mail.com> wrote in message
news:11******** **************@ e56g2000cwe.goo glegroups.com.. .

Oliver Wong wrote:
"Bent C Dalager" <bc*@pvv.ntnu.n o> wrote in message
news:e3******** **@orkan.itea.n tnu.no...
> In article <MP************ ************@ne ws.sunsite.dk>,
> Jerry Coffin <jc*****@taeus. com> wrote:
>>
>>Or that your variables aren't really of the correct type
>>to start with. From what I've seen, the majority of
>>getters and setters don't really do anything, and are
>>exactly equivalent to public data with a really ugly
>>syntax.
>
> The primary advantage to encapsulating otherwise public data into
> accessors that don't actually add anything is that access to this data
> can later be easily changed to do something interesting.
>
> It is a poor man's encapsulation, but it's still better than just
> having public data fields.
The code I'm working with has two classes that do almost the same
thing,
because the code was built by merging two other programs together.

<Java>
class NodeToken {
public int beginColumn, endColumn;
}

class Token {
public int startColumn, endColumn;
}
</Java>

I'm trying to merge these two classes together. If they had used accessor
methods, I could have a methods setStartColumn( int) and
setBeginColumn( int)
affect the same private field, so that the changes would be seen by
either
interfaces. Unfortunately, they didn't use accessor methods, and instead
used public fields, so now I've got to start by adding the accessor
methods
to each seperate classes, mark the fields as deprecated, check for all
access to those fields, change those to invoke the accessor methods, then
merge the class, then simplify the API.


Interestingly one thing the Java camp never brought up was the tools
they have available to them to make them more productive. Among those
tools are much more sofisticated refactoring tools. The only one I
have been able to find for C++ has been Ref+ and though it does a lot
it is still missing a lot of refactors you get with just about every
version of Java or .Net refactor tool out there.


It might be that the Java camp assumes that this ease of refactoring is
completely natural, and that all developers have access to the technology.
As others have said, the people best suited to claim one language is
"better" than another, for some definition of "better", are those that have
actually used both languages.

Encapsulate Member is a very common refactor and comes in most tools,
including Ref+, and makes the above process completely automatic.


In my specific case, the code accessing the public field is generated
(I'm working with parser generators, and hence the "Token" class), so I'd
have to actually edit the code that generates the code that accesses these
fields. I think the automated wizards aren't smart enough to deal with that
yet.

- Oliver

May 5 '06 #400

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
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...
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
9449
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
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();...
0
5695
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
5882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3140
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.