On Java and C++

A

Andrew McDonagh

TJW said:
Hello,



As a purely outside observer to this thread, I found this
statement fairly amusing considering the following text that has
appeared in this thread.

snipped brilliantly researched response.

v cool TJW.
 
W

Walter Bright

Phlip said:
There's a better way to state that item, because otherwise C++ wouldn't
suck, and we all know that's not the case.

Newbie: Why can't I put template bodies in .cpp files?

Guru: Because the linker doesn't have a compiler in it.

You can put template bodies in separate .d files in the D programming
language, and it works with a standard linker.

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

Phlip

Walter said:
You can put template bodies in separate .d files in the D programming
language, and it works with a standard linker.

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

I'm not yet qualified to put your D on the Suck list, but rest assured I
will soon work to correct the situation. However...

....Can D treat classes as objects?

That's about the most complex and subtle programming concept that I
understand, so I tend to harp on it too much. ;-)
 
N

Noah Roberts

Phlip said:
I'm not yet qualified to put your D on the Suck list, but rest assured I
will soon work to correct the situation.

Common, just look at its name. Can't possibly be anything but suck
with a name like "D".
 
B

Bent C Dalager

I don't see any "C++ is not as good as Java because" in that paragraph.
I took it as an indictment of the silliness of bringing up this hardware
CPU/bytecode stuff in this conversation in the first place. Maybe I
misinterpreted something, but I really don't think so.

It was a bit of that, and also a bit of a stab at the language zealots
from both sides of the fence: this is the sort of uninteresting trivia
that seems to interest them a lot for some reason.

A bit trollish of me, perhaps, but then this _is_ a troll thread :)

Cheers
Bent D
 
A

Alex Buell

Common, just look at its name. Can't possibly be anything but suck
with a name like "D".

That name reminds me of being back at school, getting my prep graded on
a scale between A (good), to F (fail). Getting a D meant you made a very
poor effort... ;o)
 
I

Ian Collins

Walter said:
You can put template bodies in separate .d files in the D programming
language, and it works with a standard linker.
You can do the same with a number of C++ compilers, whether or not they
support the 'export' keyword.
 
M

Mishagam

Noah said:
Where to start...

First, are you really making the statement that Java supports no other
error reporting facility? That is blatantly false but let's assume for
the moment that is true and ask ourselves if that is actually a good
thing...
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.
Second...I'm not sure of you use of the term "program".

I made and error. I meant procedure, not program.

Are you really
claiming that a Java *program* can somehow report exceptions to the OS
or object running it in a way other than what the OS supports - signals
being one common facility? If this is in fact true it would be an
interesting CAN I am not aware of. C++ programs never "return NULL"
but do most commonly return an integer...0 meaning all is ok. AFAIK
Java must do this too as many operating systems depend on the behavior.

I was writing about how called procedure can inform calling procedure
about error or some condition, like broken network connection. All I
wrote about C was also about communicating errors to calling procedure.
I don't know exactly how JVM informs OS how program ended - (I thing it
is value in System.exit( code )) this is not what I was talking about
(and not most central part in programming, if you are not programming
mainly in Unix shell).
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
 
N

noone

C++ (deep breath):

makes me miss Fortran-4 and LSI-11 assembler even more so... :^(

Long live the PDP11 !

cause everybody knows that architectures should be based on octal values,
right?
 
M

Mishagam

Noah said:
Mishagam said:
Noah said:
Mishagam wrote:
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.
Actually, you are in err. Java also has char[] and there is nothing
stopping someone from using it or designing a new String. Therefor
Java suffers from the same "problem" as C++ here except there are no
Java functions and tools to work with char[]...you have to write them
from scratch.
Yes, you can use char[] (or byte[]), but as you said it has no support,
so nobody uses it (as opposed to String, which is more heavily supported
than any C/C++ strings version). It is VERY rare Java programmer who
would spend time deciding which string representation to use. Everybody
just uses String. And the beauty it - it is really very close to optimal
choice. (as opposed too, for example, original Pascal strings)

Interesting statement. Just how close, in quantifiable values, to
optimal is it then? Also, optimal in what way?
For strings main feature is convenience. You can easily define strings,
you can easily make operations, especially concatenations, with strings.
You don't bother about allocating pieces of string. You can use strings
as keys. You can easily convert other type to strings, and simple types
from strings. Strings should be efficient.
C char * strings are very fast, have decent support and great
improvement over Pascal strings (not to mention Fortran), especially
because of sprintf / sscanf functions, but you always have to bother
where to allocate strings, and C strings are not safe.
STL string and CString are slower than C, but safe. They have some
support, but Java strings are supported better. You also always have to
choose which string to use, and different programs and libraries use
different strings. For example, part of pain of COM programming on
Windows was very frequent need to convert strings from one format to
another.
So Java String look better than any C/C++ strings version. This is what
I call close to optimal.
Cleverness is subjective. IMHO a lot of choices in Java where rather
dumb.

"Very close to optimal"...that seems like a fluff statement to me but
if you can quantify it I'll place more value in it.

Not having any choices doesn't seem to me to be that great.

I'm still looking for the can. You listed all the thing Java *can't*
do but haven't come with anything it can. I don't see much advantage
in *can't*.
Generally you can do anything on any general purpose computer language.
I can say you can write safe programs on Java, you can do GC on Java.
There is also very long list of things that is more easy to do on Java
(almost everything). For example.
Connect to databases.
Use http connections, requests and responses.
Write string to clipboard.
Write servlet (comparing to use CGI programs or ISAPI module).
and so on.
 
P

Phlip

Ian said:
You can do the same with a number of C++ compilers, whether or not they
support the 'export' keyword.

Newbie: Why do I have to define classes twice?

Guru: You don't define them twice. You declare them in header
files, define them in header files, and define their methods
in implementation files.

Newbie: Why do I have to de...scribe classes three times?
 
M

Mishagam

Bent said:
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 :)
Because C++ is compiled language, and has no defined intemediate
language, it is very difficult to see what Computer that "support C++
instructions natively" should look like. For Java there is defined
bytecode and so you can make computer to run this bytecode directly.
This doesn't mean that Java is better, but it does mean that speed
advantage of C++ wouldn't exist (it if still exists with modern JIT JVM)
on such computers.
 
P

Phlip

Alex said:
That name reminds me of being back at school, getting my prep graded on
a scale between A (good), to F (fail). Getting a D meant you made a very
poor effort... ;o)

They already make that joke on their web page.

I tried its source on the train ride home, and d2html.d struck me as one
huge function, with absurdly deep nested blocks. Couldn't it have been a
table?
 
P

peter koch

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.
/Peter
 
M

Mishagam

Alex said:
OK, are there any stupid features in D? ;o)
It is not honest to ask about stupid feature of language nobody knows
much about.
Everybody knows about C++ stupid features, because it had it's period of
fame when everybody programmed on it. The same for Java.
I think the fact that nobody uses D means suggests that it has not only
one stupid feature, but a lot of stupid features.
 
I

Ian Collins

Phlip said:
Ian Collins wrote:




Newbie: Why do I have to define classes twice?

Guru: You don't define them twice. You declare them in header
files, define them in header files, and define their methods
in implementation files.

Newbie: Why do I have to de...scribe classes three times?
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.
 
P

peter koch

Mishagam skrev:

[snip]
I understand that RAII is basically use automatically called
destructor's to dispose resources?
That is correct. When the lifetime of an object, its destructor is
automatically called. I do not need to say that this is regardless of
whether an exception is thrown or not.
I agree it is useful where it can be
used.
It works if you work with objects as values, it doesn't work if you work
with pointers or references.
This is correct - and it should not work in such cases.
In such cases destructor can easily leave
dangling pointer. I do not know that statement.
If you work with references you are on your own, or
have to duplicate something like reference counting or Java GC.
Replace references with pointers here and I agree.
I don't
think you can work without using references in big program.
(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 think because of this STL mostly works (in examples) with value
elements, and this creates a lot of problems - you cannot place
descended class objects were you can place base objects, you have to
deal with constructors, destructor's, copy constructors called in
strange places, you waste memory and so on.
STL is value-based and rightly so in my opinion. 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.
Also, you have to have
different generated code for different objects and use templates.
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.
Still, sometimes code might be shared across different template-types.
E.g. std::vector said:
And in
Java one Collections library works OK with any object.
If you do not use Java generics you basically end up with runtime type
checks. This is not nice.

/Peter
 

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