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 1 of 3 [1] 2 3 Next page →
| From | Silvio <silvio@moc.com> |
|---|---|
| Date | 2011-02-05 18:04 +0100 |
| Subject | Re: Java vs C++ |
| Message-ID | <4d4d8322$0$41117$e4fe514c@news.xs4all.nl> |
On 02/05/2011 03:38 PM, Arne Vajhøj wrote: > On 05-02-2011 09:02, Silvio wrote: >> On 02/05/2011 12:15 PM, Lawrence D'Oliveiro wrote: >>> Most of that complexity seems to be caused by the addition of >>> generics to >>> Java. This was something that C++ had from the beginning. It was one >>> of the >>> unnecessary complications that Java left out to start with. But now >>> they’ve >>> changed their minds, and put it back in. But since they need to be >>> backward- >>> compatible with existing code, they’ve had to add extra complications >>> that >>> C++ never had to deal with. >>> >>> Bjarne Stroustroup must be chuckling over his hot cocoa... >> >> C++ did not have generics from the beginning. It was added afterwards >> and initially without any proper specification of (separate) compilation >> and linkage aspects. > > Not from the very beginning. > > But it was added to cfront pretty early. > > Arne > That just depends on what you call early. I used C-with-classes before it was named C++ and my cfront did not know of templates... The first "The C++ programming language" book Stroustrup published made no mention of templates. Stroustrup described templates in his Design and Evolution of C++ book and later in his second edition of TCPPPL. And Lew is correct: templates and genercis are completely different beasts.
[toc] | [next] | [standalone]
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
|---|---|
| Date | 2011-02-07 16:21 +0800 |
| Message-ID | <6a6dndmK8PM_NtLQnZ2dnUVZ_rOdnZ2d@posted.palinacquisition> |
| In reply to | #25530 |
On 2/7/11 3:54 PM, Peter Duniho wrote: > [...] > A long time ago, I worked on a project that used a form of interpreted > byte code in which the linker did exactly that. In that situation, the > reason we were using the byte code in the first place was for > compression, to help the program fit in memory (it was a relatively > large program, running on Mac and Windows computers without virtual > memory). So the "quoting" feature was important enough to make it worth > doing. > > In fact, that feature did not rely on C++ templates at all. We were > coding in plain C, and it detected any code that was essentially > copy/paste or nearly so. I guess I should also mention that the interpreter itself supported the quoting feature, so it was a lot simpler to rewrite any code that needed to be shared: just remove the actual code and replace with the "quote" instruction referring to the quoted code. There also was no multi-threading for the code back in those days. It'd be a bit more complicated for a linker to accomplish a similar feature, but it's not like it's an intractable problem. I think turning the quote into a function call would solve most issues, if not everything, and of course if you quote an entire function, that's even easier. Pete
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 12:28 +1300 |
| Message-ID | <iinara$2up$4@lust.ihug.co.nz> |
| In reply to | #25530 |
In message <iil9uk$b6m$1@news.eternal-september.org>, Joshua Cranmer wrote: > Try, for example, implementing both List<String> and List<Character> in > the same class. Java will tell you that you cannot do it. C++, on the > other hand, wouldn't bat an eye. Why does Java impose such a pointless restriction?
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-08 09:22 +1300 |
| Message-ID | <iipkav$d4o$8@lust.ihug.co.nz> |
| In reply to | #25530 |
In message <iiotfv$2i3$1@news.belwue.de>, Thomas Richter wrote: > 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 ... Really??
[toc] | [prev] | [next] | [standalone]
| From | Joshua Cranmer <Pidgeot18@verizon.invalid> |
|---|---|
| Date | 2011-02-07 17:25 -0500 |
| Message-ID | <iiprgj$1h4$1@news.eternal-september.org> |
| In reply to | #25597 |
On 02/07/2011 03:22 PM, Lawrence D'Oliveiro wrote: > In message<iiotfv$2i3$1@news.belwue.de>, Thomas Richter wrote: > >> 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 ... > > Really?? You trimmed the part where he elaborated on what that phrase meant. -- 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-08 16:08 +1300 |
| Message-ID | <iiqc2q$qt4$3@lust.ihug.co.nz> |
| In reply to | #25612 |
In message <iiprgj$1h4$1@news.eternal-september.org>, Joshua Cranmer wrote: > On 02/07/2011 03:22 PM, Lawrence D'Oliveiro wrote: > >> In message<iiotfv$2i3$1@news.belwue.de>, Thomas Richter wrote: >> >>> 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 ... >> >> Really?? > > You trimmed the part where he elaborated on what that phrase meant. You mean, where he explained “generate” didn’t mean “generate”, or “source code” didn’t mean “source code”? Black is white. Let me alaborate on that: no it isn’t.
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 12:24 +1300 |
| Message-ID | <iinaj7$2up$2@lust.ihug.co.nz> |
| In reply to | #25530 |
In message <4d4f042b$0$23753$14726298@news.sunsite.dk>, Arne Vajhøj wrote: > On 05-02-2011 23:13, Lawrence D'Oliveiro wrote: > >> In message<iil5ed$10m$1@news.eternal-september.org>, 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: >>>>> ... 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.
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 15:03 +1300 |
| Message-ID | <iinjsv$7j3$11@lust.ihug.co.nz> |
| In reply to | #25600 |
In message <4d4f47bb$0$23760$14726298@news.sunsite.dk>, Arne Vajhøj wrote: > On 06-02-2011 18:24, Lawrence D'Oliveiro wrote: > >> In message<4d4f042b$0$23753$14726298@news.sunsite.dk>, Arne Vajhøj wrote: >> >>> On 05-02-2011 23:13, Lawrence D'Oliveiro wrote: >>> >>>> In message<iil5ed$10m$1@news.eternal-september.org>, 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: >>>>>> >>>>>>> ... 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) See, it’s clear you’re hung up on specifics of particular implementations, not on how the language feature is defined at all.
[toc] | [prev] | [next] | [standalone]
| From | Joshua Cranmer <Pidgeot18@verizon.invalid> |
|---|---|
| Date | 2011-02-06 21:18 -0500 |
| Message-ID | <iinkpv$tbg$1@news.eternal-september.org> |
| In reply to | #25717 |
On 02/06/2011 09:03 PM, Lawrence D'Oliveiro wrote: > In message<4d4f47bb$0$23760$14726298@news.sunsite.dk>, Arne Vajhøj wrote: >> 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) > > See, it’s clear you’re hung up on specifics of particular implementations, > not on how the language feature is defined at all. No, it's in the definition of C++ templates. And I quote §14, clause 1: A template defines a family of classes, functions, or concept maps, or an alias for a family of types. As far as the standard is concerned, Foo<int> and Foo<long> would be very distinct types. It might be that the compiler makes them one single entity, but it can only do that under §1.9, clause 1: The semantic descriptions in this International Standard define a parameterized nondeterministic abstract machine. This International Standard places no requirement on the structure of conforming implementations. In particular, they need not copy or emulate the structure of the abstract machine. Rather, conforming implementations are required to emulate (only) the observable behavior of the abstract machine as explained below. i.e., "you don't have to actually implement this specification so long as a valid program can't tell that you aren't." See, it's clear you really haven't read the specs you're trying to language lawyer with us on. -- 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 21:26 -0500 |
| Message-ID | <4d4f584a$0$23758$14726298@news.sunsite.dk> |
| In reply to | #25717 |
On 06-02-2011 21:03, Lawrence D'Oliveiro wrote: > In message<4d4f47bb$0$23760$14726298@news.sunsite.dk>, Arne Vajhøj wrote: >> On 06-02-2011 18:24, Lawrence D'Oliveiro wrote: >>> In message<4d4f042b$0$23753$14726298@news.sunsite.dk>, Arne Vajhøj wrote: >>>> On 05-02-2011 23:13, Lawrence D'Oliveiro wrote: >>>>> In message<iil5ed$10m$1@news.eternal-september.org>, 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: >>>>>>> >>>>>>>> ... 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) > > See, it’s clear you’re hung up on specifics of particular implementations, > not on how the language feature is defined at all. The language feature is what allows it. That behavior would not be allowed in Java. Arne
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-02-06 20:15 -0500 |
| Message-ID | <4d4f47bb$0$23760$14726298@news.sunsite.dk> |
| In reply to | #25600 |
On 06-02-2011 18:24, Lawrence D'Oliveiro wrote: > In message<4d4f042b$0$23753$14726298@news.sunsite.dk>, Arne Vajhøj wrote: >> On 05-02-2011 23:13, Lawrence D'Oliveiro wrote: >>> In message<iil5ed$10m$1@news.eternal-september.org>, 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: >>>>>> ... 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
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 15:55 +1300 |
| Message-ID | <iinmud$9er$8@lust.ihug.co.nz> |
| In reply to | #25530 |
In message <iinkf4$qmm$1@news.eternal-september.org>, Joshua Cranmer wrote: > 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). List<String> is a type, not an instance of a type. > If you're having this much problems understanding me ... Use the terms as they are defined in the Java Language Spec, and we can all get along fine.
[toc] | [prev] | [next] | [standalone]
| From | "javax.swing.JSnarker" <gharriman@boojum.mit.edu> |
|---|---|
| Date | 2011-02-06 19:54 -0500 |
| Message-ID | <iinft1$95e$1@speranza.aioe.org> |
| In reply to | #25530 |
On 06/02/2011 7:32 PM, Lawrence D'Oliveiro wrote: > 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? dynamic_cast<foo>(bar) can throw this if bar is not really a foo. But C++ lets you use the unsafe old (foo)bar cast from C, and if bar is not really a foo, welcome to undefined behaviorville. Java doesn't let that happen: the cast syntax is (Foo)bar but the semantics is that of dynamic_cast: bar is a Foo or an exception gets thrown. The only way to come close to C's unsafe cast with Java is to muck about with serialization, to alter a serialized representation of a Bar to claim to be of class Foo instead and then deserialize it. Most likely you get a broken Foo and exceptions thrown, but not a VM crash. The main reason you'd try that is to try to break some existing Java program -- hack it, crack it, virus someone's VM. There's never any use for that in normal programming that I am aware of. -- In <iijn58$ccs$1@news.albasani.net>, Lew admitted: > The JLS is obfuscatory in parts
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-02-06 20:50 -0500 |
| Message-ID | <4d4f4fc2$0$23755$14726298@news.sunsite.dk> |
| In reply to | #25530 |
On 06-02-2011 10:45, Thomas Richter wrote: > Joshua Cranmer wrote: >> On 02/05/2011 11:13 PM, Lawrence D'Oliveiro wrote: >>> The only time they become the >>> same thing is in “erasures” and “raw types”, which are backward- >>> compatibility mechanisms introduced to avoid breaking existing code that >>> doesn’t know about generics. >> >> I think Java would likely have gone with much the same syntax even if >> generics had been introduced in the beginning. > > 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
[toc] | [prev] | [next] | [standalone]
| From | Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> |
|---|---|
| Date | 2011-02-07 15:54 +0800 |
| Message-ID | <L4-dnfBCMbOqONLQnZ2dnUVZ_rWdnZ2d@posted.palinacquisition> |
| In reply to | #25530 |
On 2/7/11 2:52 PM, Mike Schilling wrote: > [...] >>> Possible. But if two template usages are compiled separatetly, >>> then it is not possible. >> >> Exercise for the reader: explain why Arne Vajhøj is wrong. For extra >> credit, >> list the implicit preconceptions that might have led to such a wrong >> conclusion. > > Arne is assuming that compilation and linking are separate phases. This > was one of the original design goals of C++, as you might recall from > Stroustrup's _Design and Evolution of C++_: that the C++ compiler > produce object code that the standard system linker could process. . > It's no longer true in many C++ development systems, precisely because > templates make that impossible to achieve with any efficiency. I agree with Arne's statement from a practical point of view. However, note that there's not really any theoretical reason a linker could not inspect the object files for redundant code and optimize template usages where possible. A long time ago, I worked on a project that used a form of interpreted byte code in which the linker did exactly that. In that situation, the reason we were using the byte code in the first place was for compression, to help the program fit in memory (it was a relatively large program, running on Mac and Windows computers without virtual memory). So the "quoting" feature was important enough to make it worth doing. In fact, that feature did not rely on C++ templates at all. We were coding in plain C, and it detected any code that was essentially copy/paste or nearly so. Pete
[toc] | [prev] | [next] | [standalone]
| From | Thomas Richter <thor@math.tu-berlin.de> |
|---|---|
| Date | 2011-02-07 01:04 +0100 |
| Message-ID | <iincuv$ot9$1@news.belwue.de> |
| In reply to | #25530 |
Arne Vajhøj 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. >> >> They are different things in Java as well. > > No. Same code. I don't know in how far "same code" makes sense in Java in first place. 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. 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. Thus, I don't really see how that type of argument applies. >>> 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. >> >> Same sort of thing in C++. Not really. Generics are run-time checked, templates are compile-time checked. There is no "ClassCastException" in C++. If the class doesn't fit, the compiler will tell at compile time. Otherwise, the code will crash at run time - there is no additional check inserted as it is in java which tests whether the type-erased instance is of the proper type. Greetings, Thomas
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2011-02-06 20:26 -0500 |
| Message-ID | <4d4f4a54$0$23753$14726298@news.sunsite.dk> |
| In reply to | #25654 |
On 06-02-2011 19:04, Thomas Richter wrote: > Arne Vajhøj 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. >>> >>> They are different things in Java as well. >> >> No. Same code. > > 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
[toc] | [prev] | [next] | [standalone]
| From | Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> |
|---|---|
| Date | 2011-02-07 19:09 +1300 |
| Message-ID | <iio2be$g2f$3@lust.ihug.co.nz> |
| In reply to | #25775 |
In message <4d4f4a54$0$23753$14726298@news.sunsite.dk>, Arne Vajhøj wrote: > On 06-02-2011 19:04, Thomas Richter wrote: > >> 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. Exercise for the reader: explain why Arne Vajhøj is wrong. For extra credit, list the implicit preconceptions that might have led to such a wrong conclusion.
[toc] | [prev] | [next] | [standalone]
| From | Lew <noone@lewscanon.com> |
|---|---|
| Date | 2011-02-07 07:29 -0500 |
| Message-ID | <iiooiu$h9l$1@news.albasani.net> |
| In reply to | #25895 |
"Lawrence D'Oliveiro" spat: >> Exercise for the reader: explain why Arne Vajhøj is wrong. For extra credit, >> list the implicit preconceptions that might have led to such a wrong >> conclusion. "Exercise for the reader" because the writer couldn't come up with any logical or reasoned arguments, so he waves his hands and exercises trollishness instead. What a maroon! -- Lew Ceci n'est pas une fenêtre. .___________. |###] | [###| |##/ | *\##| |#/ * | \#| |#----|----#| || | * || |o * | o| |_____|_____| |===========|
[toc] | [prev] | [next] | [standalone]
| From | "Mike Schilling" <mscottschilling@hotmail.com> |
|---|---|
| Date | 2011-02-06 22:52 -0800 |
| Message-ID | <iio4q9$eer$1@news.eternal-september.org> |
| In reply to | #25895 |
"Lawrence D'Oliveiro" <ldo@geek-central.gen.new_zealand> wrote in message news:iio2be$g2f$3@lust.ihug.co.nz... > In message <4d4f4a54$0$23753$14726298@news.sunsite.dk>, Arne Vajhøj wrote: > >> On 06-02-2011 19:04, Thomas Richter wrote: >> >>> 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. > > Exercise for the reader: explain why Arne Vajhøj is wrong. For extra > credit, > list the implicit preconceptions that might have led to such a wrong > conclusion. Arne is assuming that compilation and linking are separate phases. This was one of the original design goals of C++, as you might recall from Stroustrup's _Design and Evolution of C++_: that the C++ compiler produce object code that the standard system linker could process. . It's no longer true in many C++ development systems, precisely because templates make that impossible to achieve with any efficiency.
[toc] | [prev] | [next] | [standalone]
Page 1 of 3 [1] 2 3 Next page →
Back to top | Article view | comp.lang.java.programmer
csiph-web