Article View: pl.comp.objects
Article #15418Jeszcze o generics...
From: A.L.
Date: Tue, 05 Sep 2006 21:56
Date: Tue, 05 Sep 2006 21:56
43 lines
2643 bytes
2643 bytes
Generics in C#, Java, and C++ A Conversation with Anders Hejlsberg, Part VII by Bill Venners with Bruce Eckel January 26, 2004 http://www.artima.com/intv/generics.html "Comparing C# Generics to C++ Templates Bruce Eckel: How do C# generics compare with C++ templates? Anders Hejlsberg: To me the best way to understand the distinction between C# generics and C++ templates is this: C# generics are really just like classes, except they have a type parameter. C++ templates are really just like macros, except they look like classes. The big difference between C# generics and C++ templates shows up in when the type checking occurs and how the instantiation occurs. First of all, C# does the instantiation at runtime. C++ does it at compile time, or perhaps at link time. But regardless, the instantiation happens in C++ before the program runs. That's difference number one. Difference number two is C# does strong type checking when you compile the generic type. For an unconstrained type parameter, like List<T>, the only methods available on values of type T are those that are found on type Object, because those are the only methods we can generally guarantee will exist. So in C# generics, we guarantee that any operation you do on a type parameter will succeed. C++ is the opposite. In C++, you can do anything you damn well please on a variable of a type parameter type. But then once you instantiate it, it may not work, and you'll get some cryptic error messages. For example, if you have a type parameter T, and variables x and y of type T, and you say x + y, well you had better have an operator+ defined for + of two Ts, or you'll get some cryptic error message. So in a sense, C++ templates are actually untyped, or loosely typed. Whereas C# generics are strongly typed...." Oczywiscie, zeby upzredic ewentualne komantarze, zgadzam sie ze autorzy sa niekompetentni i niechetnei nastawieni do C++. C++ jest po prostu dla nich za trudny. Zwlaszcza "Modern C++" A.L.
Technical Details
Message-ID:
<5esrf2dej8h4pqp19oclvde89r4coefn32@4ax.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!sn-xt-sjc-05!sn-xt-sjc-08!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!sn-xt-sjc-05!sn-xt-sjc-08!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mail From: A.L. <alewando@fala2005.com> Newsgroups: pl.comp.objects Subject: Jeszcze o generics... Date: Tue, 05 Sep 2006 16:56:52 -0500 Organization: Posted via Supernews, http://www.supernews.com Message-ID: <5esrf2dej8h4pqp19oclvde89r4coefn32@4ax.com> X-Newsreader: Forte Agent 3.1/32.783 MIME-Version: 1.0 X-Complaints-To: abuse@supernews.com Lines: 44 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit