On Java and C++

T

TJW

Noah Roberts said:
You can come to any conclusion you want and provide whatever view you
wish people to see if you quote people out of context.
I can, and I often do. Seriously, I was not trying to insult you.
That was in reply to someone telling me I'm a fundamentalist religious
nut because my parents apparently are because my name is Noah. That is
an incredibly stupid statement to make
....
I totally agree, any such statement is inappropriate. I think my
specific response to reading that statement was tempered however
because I thought that the poster was joking.
Everything in my reply fit, including the admision that the reply
itself was a personal attack that was not on topic...something you
neatly snipped from my post.
This is my error and was unintentional. I apologize, but this is
not totally my point. My point was simply that the set of
statements:
{
Statement 0: Ad-Hominem arguments are irrelevant and meaningless.
Statements 1..n: Ad-Hominem argument (i)
}
is inconsistent. I saw a series of statements in this thread that
match that pattern (qualified by the poster or not) which I found
humorous. Nothing against you personally, just a comment on what
the discussion had become.
Your post is no more informed,
About the previous discussion on the costs/benefits of Java
vs. C++, you are 100% correct. I never claimed to be qualified to
engage in such a discussion. My comment however was on the thread
itself, which was informed as I quoted numerous references for the
single point I wanted to make.
balanced,
Honestly, I'm not sure how this requirement applies in general to
a group that discusses the use of a programming language, but if
your referring to my omitted quote, again, I apologize.
or interesting than the person's to whom that above quote replies
to.
Matter of opinion. I happen to disagree.

I am way too new here to continue defending a mediocre joke, so I
will make this my last post in this thread.

Peace,
-TJW
 
M

Mishagam

peter said:
Mishagam skrev:
This is correct - and it should not work in such cases.
I do not know that statement.
I mean here you pass pointer or C++ reference to your object, this
pointer is saved somewhere, and then you destruct you object. Then
pointer in pointing to basically random position. I name such pointer
dangling. I thought it is standard name for such pointers.
Replace references with pointers here and I agree.
You can work with C++ pointers or references. Both of them can have
problem of pointing to no longer existing objects.
(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.
STL is value-based and rightly so in my opinion.
Doesn't moving around full objects instead of just pointers to them feel
wasteful?
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). I suspect it is another hole, not
"simply store a smart pointer".
This is partly true. By having different code generated for each type
you get far better runtime performance so this is a good thing. As an
example, the sort in C++ is three times faster than the C qsort for
double. This is primarily a result of having code inlined.
Yes, if in C you call custom function for every comparison of doubles it
should be slower. I bet if you sort array of structures C++ speed up
will disappear. Actually in Java they wrote separate sort procedures for
native types - because there are only about 8 native types it is
manageable. But all objects are sorted by the same procedure. And they
don't have to copy objects (with calling copy constructor and
destructor's) on each operation. I would be tempted to write benchmark
program, but feel too lazy.
Still, sometimes code might be shared across different template-types.

If you do not use Java generics you basically end up with runtime type
checks. This is not nice.
Even in Java with generics I am almost sure there is only one compiled
library for all (Object) types.
 
M

Mishagam

peter said:
Mishagam skrev:
Noah Roberts wrote:
[snip]
Third...COM is not C++, it is a MS specific standard of coding a set of
functionality in ANY language that can be used from ANY language
capable of interacting with COM. I do believe Java can be counted
among them but of course any such program instantly looses any platform
independance.
I programmed on COM on C/C++, and all COM procedures use HRESULT as
error code. Other often used COM Language is VB, where error codes
apparently are somehow hidden - I don't know VB very well. Java cannot
directly use COM, probably there exist JNI Libraries allowing
communications Java <-> COM through native calls.
This is absurd. If you program against a COM interface you use a
HRESULT. This is so in ANY language - even Java. Unless Java does not
support COM programming, of course.
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).
 
M

Mishagam

Phlip said:
- 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.
 
N

Noah Roberts

Mishagam said:
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.
 
N

Noah Roberts

Mishagam said:
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.
 
N

Noah Roberts

Mishagam said:
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.
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
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....choice 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.
 
C

Chris Uppal

Phlip said:
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
 
A

Andrew McDonagh

Ian said:
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.....
 
L

Luc The Perverse

Larry Barowski said:
Noah Roberts said:
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
 
L

Larry Barowski

Noah Roberts said:
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.
 
A

Andrew McDonagh

James said:
Production work I did in VB2.0 when it was new, is still in production.
I think that code might be nearly old enough to vote.

and your point is?

longevity of use is no indicator of a 'good' language - its simply that
the application does what it was supposed to OR the company is unwilling
to rewrite for some reason if it isn't doing as its supposed to.
 
T

Tor Iver Wilhelmsen

Phlip said:
- 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?
 
M

Mishagam

Noah said:
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?
You can call something like System.gc(). But if you want to be 100% sure
that something happen you don't rely on gc, you use finally blocks.
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, reference counting using smart
pointers is 100% programmer controlled.
If you have valuable resources other that memory, with reference
counting they get called only when all pointers to it in all parts of
program are explicitly closed. You have no help here from RAII, smart
pointers or anything.
You have help from C++ only with one reference in one place in program
(and in RAII object). Then you don't need reference at all you can use
value object. Otherwise there is no help, it becomes worse than finally
block.
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.
You can close object in finally block and be 100% sure that non-memory
resources are freed. Then you can be 100% sure that GC will do it's best
to provide you with memory. You also can be sure (not so in C++) that
this memory isn't pointing to other active objects. (of course last part
happen in C++ only if programmer made some error somewhere in program).
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.


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.
Ok, Java has references, which resemble C++ pointers, but are better.
Java doesn't need smart pointers because references provide most of
advantages of smart pointers.
A smart pointer is nothing else but an RAII wrapper around a gatherable
resource that must be released.
If you have several pointers (you insist on pointers, however C++ HAS
references which are almost the same as pointers from this point of
view) to the same object/resource, you cannot speak about RAII. Logic of
releasing resource when going out of block doesn't work.
I can imagine you can hope that if you made all pointers to your object
smart, and if you didn't pointed to your object from non RAII objects.
Then you can be sure than when you stop your program (and went out of
all blocks) you released all objects. If you had only one thread . But
OS will release all your resources anyway.
If you have only one pointer you can just as well use value object.
Most of the time we are speaking of
 
B

benben

You made me think you code directly in binary machine instructions. At
least that's your favorite language.

As for me, I'd dream to program in English, but someone is yet to invent
an English compiler for me.

Regards,
Ben
 
T

Timo Stamm

Andrey said:
you should try Opera.
While Firefox needs up to 5 second for applet on my page
(http://reader.imagero.com),
with Opera it starts immediately!

Some browsers handle the initialisation better than others. But for most
users, applets just take a long time to appear. Flash is generally much
quicker, regardless of platform or browser.


Timo
 
A

Andrew McDonagh

benben said:
You made me think you code directly in binary machine instructions. At
least that's your favorite language.

As for me, I'd dream to program in English, but someone is yet to invent
an English compiler for me.

Regards,
Ben

already done - google Domain Specific languages
 
A

Alex Buell

and your point is?

longevity of use is no indicator of a 'good' language - its simply
that the application does what it was supposed to OR the company is
unwilling to rewrite for some reason if it isn't doing as its
supposed to.

And besides, VB 2.0 was released in 1992, so it's just a 14 year old
grumpy and grouchy teenager.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,083
Members
48,773
Latest member
Kaybee

Latest Threads

Top