Java vs C++

  • Thread starter Lawrence D'Oliveiro
  • Start date
A

Arne Vajhøj

Strange that Java never copied the C++ operator names "andâ€, “or†and “notâ€.

????

Java uses &&, &, ||, |, ! like C++.

(Java does not allow defining them for own types, but that
is another story)

Arne
 
L

Lew

Thomas said:
Who said this, and where? I did not mean to say this implication. Java often
took the path of providing a more accessible language than C++, maybe for good
reasons since C++ has quite some complexity. But templates are not generics,
and I'm not aware that you can use them for metaprogramming. Whether you
*want* to use metaprogramming, well, that's a different question.

When I say, "this entire thread", I'm referring to this entire thread, "Java
vs C++", as set up by the OP, not you. Nor was I replying to one of your
posts. I fail to see why you think I have an issue with anything you said.

--
Lew
Ceci n'est pas une fenêtre.
..___________.
|###] | [###|
|##/ | *\##|
|#/ * | \#|
|#----|----#|
|| | * ||
|o * | o|
|_____|_____|
|===========|
 
A

Arne Vajhøj

Funny, I did the same thing for Python, just for comparison
<http://docs.python.org/py3k/reference/>. The figure I came up with for that
Language Reference was 92 pages. To be fair, I suppose you should include
the first 6 chapters of rhe Library Reference
<http://docs.python.org/py3k/library/>, which is another 69 pages, for a
total of 161.

Either Python is a simple language or the language reference is not
very detailed.
For comparison, I have a couple of draft C99 specs floating around. They
total 550 pages, until you realize most of that is section 7, the standard
library. Leave that out, and you end up with 163 pages.

I am not sure that comparing a language reference with a standard
spec gives much meaning.

And the C spec leaves a lot of things to implementations.

Arne
 
A

Arne Vajhøj

In message<[email protected]>, Joshua Cranmer
wrote:
On 02/05/2011 10:38 PM, Lawrence D'Oliveiro wrote:
... templates and gener[ic]s are completely different beasts.

“Completely†as in “having nothing in common� Or is this some usage of
“completely†that I wasn’t aware of?

Please explain.

Templates in C++ are basically advanced macros--each invocation of a
template type regenerates the class, so a Foo<int> and a Foo<double>
are two completely different things.

They are different things in Java as well.

No. Same code.

Same code in C++ too, then.

No.

C++ will generate two classes with two sets of code.

(at least that is what common compilers do - I don't know if
the standard actually requires it to)

Arne
 
A

Arne Vajhøj

I don't know in how far "same code" makes sense in Java in first place.

It does.

Only one copy of the byte code.
The code that is created depends entirely on the JIT, and it may or may
not generate the same code depending on how often it is called. For
example, if it the JIT "sees" that the code is called with one specific
type most of the time, it could create separate code just for this
purpose and hence omit the type checks.

JIT compilers can do what they want as long as they keep semantics.

But it is not even required that a JIT compiler will be used.
And in C++, a compiler can also
merge template instances because they are identical, i.e. function
alike, i.e. for example they all operate on pointers.

Possible. But if two template usages are compiled separatetly,
then it is not possible.
Thus, I don't really see how that type of argument applies.

In Java it is as starting point one code and in C++ it is as
starting point two codes. The optimizers may do some funny things.

But I consider them different, because what optimizers may
do is not suffcient to make them identical.

Arne
 
A

Arne Vajhøj

Well, I didn't mean to say something else (see, I wrote "mostly", not
"only"), but nevertheless, could you provide an example?

public static <T extends Comparable<? super T>> T Max(T a, T b) {
if (a == null) return b;
if (b == null) return a;
if (a.compareTo(b) >= 0)
return a;
else return b;
}
This was at least worded in a very misleading way.

How can specific syntax be misleading?

Arne
 
A

Arne Vajhøj

I was trying to make sense of where you were coming from with your
predictions, and then I realized—you’re primarily talking about corporate
development. Because that’s just about the only place languages like Java
and C#/Dotnet get much use. Very few mass-market or open-source apps are
written in those languages, for example.

Which is just plain wrong.

Java and C# are both very popular for open source projects.

Sometimes statistics are done for SF projects.

The last I can find for December 2007 has Java as #1 and
C# as #7 and VB.NET as #14.

So Java and .NET are very much used for open source.

Desktop market is still dominated by native apps. It may
change someday if MS starts to rewrite MFC stuff in .NET.

Arne
 
J

Joshua Cranmer

Strange that Java never copied the C++ operator names "andâ€, “or†and “notâ€.

Why should it have? They're just aliases for other objects. By your
reasoning, Java should also have copied the C trigraphs or the other
tokens in the "Alternative tokens". You know, for the three people in
the world who do not have { on their keyboard.
 
A

Arne Vajhøj

Which is just plain wrong.

Java and C# are both very popular for open source projects.

Sometimes statistics are done for SF projects.

The last I can find for December 2007 has Java as #1 and
C# as #7 and VB.NET as #14.

So Java and .NET are very much used for open source.

Desktop market is still dominated by native apps. It may
change someday if MS starts to rewrite MFC stuff in .NET.

And in case somebody wants to check the list:
http://www.c2.com/cgi/wiki?ProgrammingLanguagePopularity

Arne
 
A

Arne Vajhøj

That's really a speculation. One could also speculate that if java would
have used or required generics from the beginning, they would be closer
to C++ templates and would not use type erasure; instead, they would be
parametrized classes as they are in C++. It's really speculation.

Given how C#/.NET got generics and the discussions about
changes to generics for future Java versions, then it seems
to be a bit more than just speculation to say that if Java had
had generics from start:
- they would not use type erasure
- but they would not be like C++

Arne
 
A

Arne Vajhøj

I think Java would likely have gone with much the same syntax even if
generics had been introduced in the beginning.

I think so too.

But I believe that type erasure would have been dropped in that case.

Arne
 
L

Lawrence D'Oliveiro

I would venture a guess that most C or C++ code isn't as easily portable
to 64-bit platforms as you would think ...

Most of the C/C++ code I deal with is open-source, and essentially all of
that is portable between 32-bit and 64-bit nowadays. As well as across non-
x86 architectures, for that matter.

Ironic, isn’t it, that the early Java slogan was "write once, run
everywhereâ€...
 
L

Lawrence D'Oliveiro

Oh, I remember how well C++ and its undefined sizes of things served us
when we had to port heaps of code from 16-bit to 32-bit.

By “16-bit†I take it you specifically mean “Windows/Intel 16-bitâ€, i.e. the
segmented 80286 architecture (spit). That was the only major 16-bit
architecture I’m aware of that made portability difficult.
 
L

Lawrence D'Oliveiro

It's a macro generator that understands types and is heavily integrated
with the syntax of C++, but it is basically a way to automatically
generate code.

You seem to be confusing one particular way of implementing
generics/templates with the way the language feature is specified. Java
generics could be implemented by a preprocessor that spat out first-edition
Java code, for that matter. In fact, it effectively does, since the JVM
seems to know nothing about generics. Would you then say that third-edition
Java is nothing more than a “macro generator�
 

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

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top