Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #25530 > unrolled thread
| Started by | Silvio <silvio@moc.com> |
|---|---|
| First post | 2011-02-05 18:04 +0100 |
| Last post | 2011-02-06 20:51 -0500 |
| Articles | 20 on this page of 44 — 10 participants |
Back to article view | Back to comp.lang.java.programmer
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Java vs C++ Silvio <silvio@moc.com> - 2011-02-05 18:04 +0100
Re: Java vs C++ Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-02-07 16:21 +0800
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 12:28 +1300
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-08 09:22 +1300
Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-07 17:25 -0500
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-08 16:08 +1300
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 12:24 +1300
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:03 +1300
Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 21:18 -0500
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 21:26 -0500
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:15 -0500
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:55 +1300
Re: Java vs C++ "javax.swing.JSnarker" <gharriman@boojum.mit.edu> - 2011-02-06 19:54 -0500
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:50 -0500
Re: Java vs C++ Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-02-07 15:54 +0800
Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 01:04 +0100
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:26 -0500
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 19:09 +1300
Re: Java vs C++ Lew <noone@lewscanon.com> - 2011-02-07 07:29 -0500
Re: Java vs C++ "Mike Schilling" <mscottschilling@hotmail.com> - 2011-02-06 22:52 -0800
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 13:32 +1300
Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-06 16:35 +0100
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:51 +1300
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 22:06 -0500
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:01 +1300
Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 14:53 +0100
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-07 19:52 -0500
Re: Java vs C++ Lew <noone@lewscanon.com> - 2011-02-06 13:09 -0500
Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 00:55 +0100
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:00 +1300
Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 21:20 -0500
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:52 +1300
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 21:25 -0500
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:29 -0500
Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-07 00:57 +0100
Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 12:57 -0500
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 15:22 -0500
Re: Java vs C++ "Mike Schilling" <mscottschilling@hotmail.com> - 2011-02-06 08:11 -0800
Re: Java vs C++ Ken Wesson <kwesson@gmail.com> - 2011-02-07 04:41 +0100
Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 21:12 -0500
Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 12:26 +1300
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 15:27 -0500
Re: Java vs C++ Thomas Richter <thor@math.tu-berlin.de> - 2011-02-06 16:45 +0100
Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 20:51 -0500
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 13:32 +1300 |
| Message-ID | <iineik$3tp$10@lust.ihug.co.nz> |
| In reply to | #25654 |
In message <iincuv$ot9$1@news.belwue.de>, Thomas Richter wrote: > There is no "ClassCastException" in C++. Yes there is. It’s called “bad_cast”. Where do you think Java got the idea from?
[toc] | [prev] | [next] | [standalone]
| From | Thomas Richter <thor@math.tu-berlin.de> |
|---|---|
| Date | 2011-02-06 16:35 +0100 |
| Message-ID | <iimf47$soo$1@news.belwue.de> |
| In reply to | #25530 |
Joshua Cranmer wrote: > On 02/05/2011 10:38 PM, Lawrence D'Oliveiro wrote: >> In message<4d4d8322$0$41117$e4fe514c@news.xs4all.nl>, Silvio wrote: >> >>> And Lew is correct: templates and genercis 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. That's much more than a macro could do. Templates are a language of its own, include syntax checks, etc. Quite unlike macros, they do not substitute text patterns. Templates allow meta-programming, i.e. you can use the compiler to generate code. And, of course, templates are quite complex - very unlike the simple-minded preprocessor. > Generics in Java are basically compile-time syntactic sugar to ensure > type-safety of container types at compile time instead of waiting until > you hit the code at runtime to get that dreaded ClassCastException. Well, java had to take the route of type-erasure to allow generic progamming plus type checks because it wasn't part of the language to begin with, so it was "hacked" into the specs more or less. Generics are considerably less powerful, but also considerably easier than C++ templates. There's no metaprogramming with generics, and generics are mostly limited to containers which does not hold for C++ templates. They are quite different. > About the only thing they share in common is the syntax, and even then, > C++ didn't allow A<B<C>> until C++0x (which, according to Bjarne > Stroustroup, took a bit of work to convince compiler vendors to accept). I beg your pardon? C++ allows nested templates since C++99 and before. The only issue here is a notational one, namely that you had to write A<B<C> > (note the space behind B<C>) to avoid >> being parsed as a token (shifting, namely). That is the only thing that got fixed in C++0x, not nesting templates which is part of the language since C++99.
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 15:51 +1300 |
| Message-ID | <iinmn0$9er$5@lust.ihug.co.nz> |
| In reply to | #25711 |
In message <4d4f5813$0$23758$14726298@news.sunsite.dk>, Arne Vajhøj wrote: > On 06-02-2011 21:00, Lawrence D'Oliveiro wrote: > >> In message<iimnes$dh2$1@news.eternal-september.org>, Joshua Cranmer >> wrote: >>> >>> 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. > > Java generics could have been defined that way. > > But they were not. See, you cannot even distinguish between “defined” and “implemented”.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-02-06 22:06 -0500 |
| Message-ID | <4d4f61af$0$23756$14726298@news.sunsite.dk> |
| In reply to | #25715 |
On 06-02-2011 21:51, Lawrence D'Oliveiro wrote: > In message<4d4f5813$0$23758$14726298@news.sunsite.dk>, Arne Vajhøj wrote: >> On 06-02-2011 21:00, Lawrence D'Oliveiro wrote: >>> In message<iimnes$dh2$1@news.eternal-september.org>, Joshua Cranmer >>> wrote: >>>> 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. >> >> Java generics could have been defined that way. >> >> But they were not. > > See, you cannot even distinguish between “defined” and “implemented”. You does not seem to have understood how Java generics are defined. Such an implementation would not have been compliant. In fact I think it would have been useless. Arne
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 15:01 +1300 |
| Message-ID | <iinjpm$7j3$9@lust.ihug.co.nz> |
| In reply to | #25711 |
In message <iimf47$soo$1@news.belwue.de>, Thomas Richter wrote: > Templates allow meta-programming, i.e. you can use the compiler to > generate code. Why, what do compilers normally do?
[toc] | [prev] | [next] | [standalone]
| From | Thomas Richter <thor@math.tu-berlin.de> |
|---|---|
| Date | 2011-02-07 14:53 +0100 |
| Message-ID | <iiotfv$2i3$1@news.belwue.de> |
| In reply to | #25773 |
Lawrence D'Oliveiro wrote: > In message <iimf47$soo$1@news.belwue.de>, Thomas Richter wrote: > >> Templates allow meta-programming, i.e. you can use the compiler to >> generate code. > > Why, what do compilers normally do? Generate source code, or rather, evaluate expressions at compile time rather than run time. Compilers usually take the source code and create executable code from that, but the C++ template system allows you to instruct the compiler to do parts of this evaluation while compiling. So long, Thomas
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-02-07 19:52 -0500 |
| Message-ID | <4d5093d7$0$23755$14726298@news.sunsite.dk> |
| In reply to | #25711 |
On 06-02-2011 10:35, Thomas Richter wrote: > Joshua Cranmer wrote: >> 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. > > That's much more than a macro could do. Templates are a language of its > own, include syntax checks, etc. Quite unlike macros, they do not > substitute text patterns. Templates allow meta-programming, i.e. you can > use the compiler to generate code. And, of course, templates are quite > complex - very unlike the simple-minded preprocessor. C++ templates are like many other C++ features very powerful. You can create some very elegant solution or make a big hole in your foot with it. Arne
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2011-02-06 13:09 -0500 |
| Message-ID | <iimo4c$pla$1@news.albasani.net> |
| In reply to | #25711 |
We could end this entire thread right now by conceding that, yes, C++ is clearly the superior language over Java, just like Esperanto is over English, unless, of course, you actually want to accomplish something, but all analogies break down somewhere, right? Anyway, just tell the OP that he's right, C++ is wonderful and Java is crap, and all those thousands more Java jobs out there can go to those of us impurists. C++ invented everything and Java is a poor stepchild, and if imitation is the sincerest form of flattery then Java just gave C++ the finger. He's right, we're wrong - he need learn nothing new and we praise him with angels' song and rose petals. C++ rules, Java drools! Can we stop talking about C++ now? You know it only makes us poor stepchildren embarrassed and to feel clumsy, contemplating how much worse our language of choice is than the One True Way, so stop rubbing our noses in it, please. Let's just talk about Java as Java so we may be shielded from the blinding light of knowledge of our insignificance compared to those of the C++ world. Leave us benighted souls to our dark Java Hades and burn us not with the C++ Sun! Again, C++ rules, Java drools! Done. QED. You win. Move on. -- Lew Ceci n'est pas une fenêtre. .___________. |###] | [###| |##/ | *\##| |#/ * | \#| |#----|----#| || | * || |o * | o| |_____|_____| |===========|
[toc] | [prev] | [next] | [standalone]
| From | Thomas Richter <thor@math.tu-berlin.de> |
|---|---|
| Date | 2011-02-07 00:55 +0100 |
| Message-ID | <iinccr$o1o$1@news.belwue.de> |
| In reply to | #25794 |
Lew wrote: > We could end this entire thread right now by conceding that, yes, C++ is > clearly the superior language over Java, just like Esperanto is over > English, unless, of course, you actually want to accomplish something, > but all analogies break down somewhere, right? 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. So long, Thomas
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 15:00 +1300 |
| Message-ID | <iinjod$7j3$8@lust.ihug.co.nz> |
| In reply to | #25711 |
In message <iimnes$dh2$1@news.eternal-september.org>, Joshua Cranmer wrote: > 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”?
[toc] | [prev] | [next] | [standalone]
| From | Joshua Cranmer <Pidgeot18@verizon.invalid> |
|---|---|
| Date | 2011-02-06 21:20 -0500 |
| Message-ID | <iinku4$tbg$2@news.eternal-september.org> |
| In reply to | #25815 |
On 02/06/2011 09:00 PM, Lawrence D'Oliveiro wrote: > In message<iimnes$dh2$1@news.eternal-september.org>, Joshua Cranmer wrote: > >> 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”? I make a minor distinction between syntactic sugar--a language feature which is designed to replace specific syntax features for ease of coding (e.g., for-each loops)--and macro processing, which is generally unrestricted code or text generation. Generics are syntactic sugar, in that it only generates code in a "few" select places as opposed to wholesale code production. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 15:52 +1300 |
| Message-ID | <iinmol$9er$6@lust.ihug.co.nz> |
| In reply to | #26051 |
In message <iinku4$tbg$2@news.eternal-september.org>, Joshua Cranmer wrote: > On 02/06/2011 09:00 PM, Lawrence D'Oliveiro wrote: > >> In message<iimnes$dh2$1@news.eternal-september.org>, Joshua Cranmer >> wrote: >> >>> 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”? > > I make a minor distinction between syntactic sugar--a language feature > which is designed to replace specific syntax features for ease of coding > (e.g., for-each loops)--and macro processing, which is generally > unrestricted code or text generation. In that case, C++ templates are most certainly not macros.
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-02-06 21:25 -0500 |
| Message-ID | <4d4f5813$0$23758$14726298@news.sunsite.dk> |
| In reply to | #25815 |
On 06-02-2011 21:00, Lawrence D'Oliveiro wrote: > In message<iimnes$dh2$1@news.eternal-september.org>, Joshua Cranmer wrote: >> 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. Java generics could have been defined that way. But they were not. A generic Java class get compiled to a single set of byte code. Arne
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-02-06 20:29 -0500 |
| Message-ID | <4d4f4b0d$0$23753$14726298@news.sunsite.dk> |
| In reply to | #25711 |
On 06-02-2011 18:57, Thomas Richter wrote:
> Arne Vajhøj wrote:
>
>>> Well, java had to take the route of type-erasure to allow generic
>>> progamming plus type checks because it wasn't part of the language to
>>> begin with, so it was "hacked" into the specs more or less. Generics are
>>> considerably less powerful, but also considerably easier than C++
>>> templates. There's no metaprogramming with generics, and generics are
>>> mostly limited to containers which does not hold for C++ templates. They
>>> are quite different.
>>
>> Java generics are useful for more than containers.
>>
>> It just get complex when used for more than containers.
>
> 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;
}
>>>> About the only thing they share in common is the syntax, and even
>>>> then, C++ didn't allow A<B<C>> until C++0x (which, according to Bjarne
>>>> Stroustroup, took a bit of work to convince compiler vendors to
>>>> accept).
>>>
>>> I beg your pardon? C++ allows nested templates since C++99 and before.
>>> The only issue here is a notational one, namely that you had to write
>>> A<B<C> > (note the space behind B<C>) to avoid >> being parsed as a
>>> token (shifting, namely). That is the only thing that got fixed in
>>> C++0x, not nesting templates which is part of the language since C++99.
>>
>> Joshua did not claim otherwise.
>
> This was at least worded in a very misleading way.
How can specific syntax be misleading?
Arne
[toc] | [prev] | [next] | [standalone]
| From | Thomas Richter <thor@math.tu-berlin.de> |
|---|---|
| Date | 2011-02-07 00:57 +0100 |
| Message-ID | <iinchp$o1o$2@news.belwue.de> |
| In reply to | #25711 |
Arne Vajhøj wrote: >> Well, java had to take the route of type-erasure to allow generic >> progamming plus type checks because it wasn't part of the language to >> begin with, so it was "hacked" into the specs more or less. Generics are >> considerably less powerful, but also considerably easier than C++ >> templates. There's no metaprogramming with generics, and generics are >> mostly limited to containers which does not hold for C++ templates. They >> are quite different. > > Java generics are useful for more than containers. > > It just get complex when used for more than containers. Well, I didn't mean to say something else (see, I wrote "mostly", not "only"), but nevertheless, could you provide an example? >>> About the only thing they share in common is the syntax, and even >>> then, C++ didn't allow A<B<C>> until C++0x (which, according to Bjarne >>> Stroustroup, took a bit of work to convince compiler vendors to accept). >> >> I beg your pardon? C++ allows nested templates since C++99 and before. >> The only issue here is a notational one, namely that you had to write >> A<B<C> > (note the space behind B<C>) to avoid >> being parsed as a >> token (shifting, namely). That is the only thing that got fixed in >> C++0x, not nesting templates which is part of the language since C++99. > > Joshua did not claim otherwise. This was at least worded in a very misleading way. So long, Thomas
[toc] | [prev] | [next] | [standalone]
| From | Joshua Cranmer <Pidgeot18@verizon.invalid> |
|---|---|
| Date | 2011-02-06 12:57 -0500 |
| Message-ID | <iimnes$dh2$1@news.eternal-september.org> |
| In reply to | #25711 |
On 02/06/2011 10:35 AM, Thomas Richter wrote: > Joshua Cranmer wrote: >> 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. > > That's much more than a macro could do. Templates are a language of its > own, include syntax checks, etc. Quite unlike macros, they do not > substitute text patterns. Templates allow meta-programming, i.e. you can > use the compiler to generate code. And, of course, templates are quite > complex - very unlike the simple-minded preprocessor. It is the code generation that I'm referring to as "an advanced macro". 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. > I beg your pardon? C++ allows nested templates since C++99 and before. > The only issue here is a notational one, namely that you had to write > A<B<C> > (note the space behind B<C>) to avoid >> being parsed as a > token (shifting, namely). That is the only thing that got fixed in > C++0x, not nesting templates which is part of the language since C++99. I was specifically referring to the ability to use >> instead of > >. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-02-06 15:22 -0500 |
| Message-ID | <4d4f0302$0$23753$14726298@news.sunsite.dk> |
| In reply to | #25711 |
On 06-02-2011 10:35, Thomas Richter wrote: > Joshua Cranmer wrote: >> Generics in Java are basically compile-time syntactic sugar to ensure >> type-safety of container types at compile time instead of waiting >> until you hit the code at runtime to get that dreaded ClassCastException. > > Well, java had to take the route of type-erasure to allow generic > progamming plus type checks because it wasn't part of the language to > begin with, so it was "hacked" into the specs more or less. Generics are > considerably less powerful, but also considerably easier than C++ > templates. There's no metaprogramming with generics, and generics are > mostly limited to containers which does not hold for C++ templates. They > are quite different. Java generics are useful for more than containers. It just get complex when used for more than containers. >> About the only thing they share in common is the syntax, and even >> then, C++ didn't allow A<B<C>> until C++0x (which, according to Bjarne >> Stroustroup, took a bit of work to convince compiler vendors to accept). > > I beg your pardon? C++ allows nested templates since C++99 and before. > The only issue here is a notational one, namely that you had to write > A<B<C> > (note the space behind B<C>) to avoid >> being parsed as a > token (shifting, namely). That is the only thing that got fixed in > C++0x, not nesting templates which is part of the language since C++99. Joshua did not claim otherwise. Arne
[toc] | [prev] | [next] | [standalone]
| From | "Mike Schilling" <mscottschilling@hotmail.com> |
|---|---|
| Date | 2011-02-06 08:11 -0800 |
| Message-ID | <iimh8f$hvv$1@news.eternal-september.org> |
| In reply to | #25711 |
"Thomas Richter" <thor@math.tu-berlin.de> wrote in message news:iimf47$soo$1@news.belwue.de... > > I beg your pardon? C++ allows nested templates since C++99 and before. The > only issue here is a notational one, namely that you had to write A<B<C> > > (note the space behind B<C>) to avoid >> being parsed as a token > (shifting, namely). That is the only thing that got fixed in C++0x, not > nesting templates which is part of the language since C++99. This surprises me. Given all the difficult parsing needed to make sense of C++, it seems like this small bit of lexical analysis should never have been a sticking point.
[toc] | [prev] | [next] | [standalone]
| From | Ken Wesson <kwesson@gmail.com> |
|---|---|
| Date | 2011-02-07 04:41 +0100 |
| Message-ID | <4d4f69fa@news.x-privat.org> |
| In reply to | #25711 |
On Sun, 06 Feb 2011 16:35:32 +0100, Thomas Richter wrote: > Joshua Cranmer wrote: >> On 02/05/2011 10:38 PM, Lawrence D'Oliveiro wrote: >>> In message<4d4d8322$0$41117$e4fe514c@news.xs4all.nl>, Silvio wrote: >>> >>>> And Lew is correct: templates and genercis 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. > > That's much more than a macro could do. Templates are a language of its > own, include syntax checks, etc. Quite unlike macros, they do not > substitute text patterns. Templates allow meta-programming, i.e. you can > use the compiler to generate code. And, of course, templates are quite > complex - very unlike the simple-minded preprocessor. I take it by "macros" you mean the simple-minded preprocessor macros of C and C++. Lisp has things it calls "macros" that are much more sophisticated, including syntax checks, etc., and are able to do everything C++ templates can do and then some. Common Lisp macros can generate templated CLOS classes, for instance.
[toc] | [prev] | [next] | [standalone]
| From | Joshua Cranmer <Pidgeot18@verizon.invalid> |
|---|---|
| Date | 2011-02-06 21:12 -0500 |
| Message-ID | <iinkf4$qmm$1@news.eternal-september.org> |
| In reply to | #25530 |
On 02/06/2011 06:26 PM, Lawrence D'Oliveiro wrote: > In message<iil9uk$b6m$1@news.eternal-september.org>, Joshua Cranmer wrote: >> It's not the same syntax. List<String> is the type of a specific >> instance, while the class still remains List. > > List<String> is a class, not an instance. In something like > > List<String> L; > > it is L that is the instance. L is an instance of a class. List<String> is an instance of a type, a type that is distinct from List (the raw type or the class type). If you're having this much problems understanding me, I'm sure you'll be having lots of fun when it comes to capture conversion. Just because two variables have type List<? extends Number> doesn't mean that they have the same type. ;-) > See, how can you try to tell me what the difference is between Java and C++, > when you don’t understand it yourself? I do very much understand it myself. My problem is that you have such a broken understanding of Java that the terminology I normally use to explain stuff is lost on you. Java is not C++, so don't come in with your preconceived notions of C++ and argue that they should apply to Java. -- Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
[toc] | [prev] | [next] | [standalone]
Page 2 of 3 — ← Prev page 1 [2] 3 Next page →
Back to top | Article view | comp.lang.java.programmer
csiph-web