Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #25981

Re: Java vs C++

From Joshua Cranmer <Pidgeot18@verizon.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Java vs C++
Date 2011-02-07 21:20 -0500
Organization A noiseless patient Spider
Message-ID <iiq9a1$ub7$1@news.eternal-september.org> (permalink)
References (10 earlier) <iink6l$87t$1@lust.ihug.co.nz> <4d4f56ac$0$23758$14726298@news.sunsite.dk> <iinmra$9er$7@lust.ihug.co.nz> <4d4f61fb$0$23756$14726298@news.sunsite.dk> <iio27n$g2f$2@lust.ihug.co.nz>

Show all headers | View raw


On 02/07/2011 01:07 AM, Lawrence D'Oliveiro wrote:
> The Java designers wanted everything that C++ templates offered. The only
> parts they omitted were the ones they couldn’t have.

No, it is very possible to have fully implemented C++ templates. As C++ 
templates are basically a semantically-aware macro processor whose code 
is created at instantiation as opposed to definition, you just have to 
generate the class files at template instantiation as opposed to class 
definition. That basically boils down to "twiddle a few bits in the 
class file", so it's no more invasive than generics was.

If you argue that wasn't an option because they didn't want to rewrite 
the collections API (which .NET decided to do), it's still possible to 
leverage roughly the same effect with more invasive modifications to the 
bytecode. You can get reified types by creating a new method info 
structure which captures the generic arguments passed into the method 
(for constructors, this would be the generic class passed in), which you 
could store in an appropriate synthetic variable. You could even get the 
duck typing nature of templates with invokedynamic (well, it wouldn't 
work for primitive types, but generics already through those out the 
window).

They could have had all of C++ templates. Clearly, they did not feel the 
benefits of full template support would be worth the cost of implementation.

-- 
Beware of bugs in the above code; I have only proved it correct, not 
tried it. -- Donald E. Knuth

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:08 +1300
  Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 21:19 -0500
    Re: Java vs C++ Peter Duniho <NpOeStPeAdM@NnOwSlPiAnMk.com> - 2011-02-09 01:07 +0800
    Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-07 19:44 -0500
    Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 15:53 +1300
      Re: Java vs C++ Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-02-08 10:25 +0000
        Re: Java vs C++ Lew <noone@lewscanon.com> - 2011-02-08 07:53 -0500
      Re: Java vs C++ Esmond Pitt <esmond.pitt@bigpond.com> - 2011-02-08 10:26 +1100
        Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-08 16:17 +1300
          Re: Java vs C++ Esmond Pitt <esmond.pitt@bigpond.com> - 2011-02-08 16:51 +1100
      Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-06 22:06 -0500
      Re: Java vs C++ "Mike Schilling" <mscottschilling@hotmail.com> - 2011-02-06 22:42 -0800
      Re: Java vs C++ Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-02-07 21:20 -0500
      Re: Java vs C++ Arne Vajhøj <arne@vajhoej.dk> - 2011-02-06 22:07 -0500
        Re: Java vs C++ Lawrence D'Oliveiro <ldo@geek-central.gen.new_zealand> - 2011-02-07 19:07 +1300

csiph-web