C#,Java和C ++中的泛型 [英] Generics in C#, Java, and C++

查看:67
本文介绍了C#,Java和C ++中的泛型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是引导C#架构师。试图质疑C ++模板

(页面底部)。

http://www.artima.com/intv/generics2.html (页面底部)

(全文开头于 http://www.artima.com/intv/generics.html


我认为Micrsoft的每位员工都必须参加

FUD营销课程。在与公司外的任何人交谈之前。我认为这个术语是以金钱为导向的编程。适合这里。

Here is the "lead C# architect" attempting to impugn C++ templates
(bottom of the page).

http://www.artima.com/intv/generics2.html (bottom of the page)
(Full article begins at http://www.artima.com/intv/generics.html)

I think every employee at Micrsoft must be required to take a class in
"FUD marketing" before speaking with anyone outside the company. I
think the term "money oriented programming" is suitable here.

推荐答案

哇,这真是令人震惊。令人遗憾的是编程语言

不能起诉诽谤。


卢克

Wow, that''s truly appalling. It''s a shame that a programming language
can''t sue for libel.

Luke



at******@gmail.com 写道:
这是引导C#架构师。试图质疑C ++模板
(页面底部)。

http://www.artima.com/intv/generics2.html (页面底部)
(全文开头于 http://www.artima.com/intv/generics.html

我认为必须要求Micrsoft的每位员工参加FUD营销课程。在与公司外的任何人交谈之前。我认为金钱导向编程这个术语适合这里。
Here is the "lead C# architect" attempting to impugn C++ templates
(bottom of the page).

http://www.artima.com/intv/generics2.html (bottom of the page)
(Full article begins at http://www.artima.com/intv/generics.html)

I think every employee at Micrsoft must be required to take a class in
"FUD marketing" before speaking with anyone outside the company. I
think the term "money oriented programming" is suitable here.




嗯,面试对于C ++来说似乎既不是不准确也不是一点点贬义

;因此,很难看出C ++是如何被语言所支持的。


C ++中的模板通常可以取代C宏(看起来很简单)在std :: min和

std :: max)。但是当然这样做才有意义,如果模板

比宏更好,当然,它们也是如此。


Greg



Um, the interview seems neither inaccurate nor the least bit derogatory
toward C++; so it''s hard to see how C++ the language is being
"impugned."

Templates in C++ can often replace C macros (look at std::min and
std::max). But of course doing so would only make sense if templates
were better than macros, which of course, they are.

Greg


Greg写道:
嗯,面试对C ++来说既不是不准确也不是一点点贬义;所以很难看出C ++语言是如何受到侮辱的。


好​​的,我会详细介绍。

C ++中的模板通常可以替换C宏(查看std :: min和
std :: max)。但是当然这样做才有意义,如果模板
比宏更好,当然,它们是。
Um, the interview seems neither inaccurate nor the least bit derogatory
toward C++; so it''s hard to see how C++ the language is being
"impugned."
Okay, I''ll go into more detail.
Templates in C++ can often replace C macros (look at std::min and
std::max). But of course doing so would only make sense if templates
were better than macros, which of course, they are.




对,这就是确切的关键点。模板更具表现力

并且比宏有用,所以当文章声明:


C ++模板真的就像宏一样,除了它们看起来像

班级。


这简直是不真实的。此后不久,他显然与自己相互矛盾:


(1)C#在运行时进行实例化

(2 )C#在编译泛型类型时执行强类型检查


他在这里指的是类实例化,而不是对象实例化。

I不知道如何在没有实例化通用的情况下进行强类型检查。也许它的某些部分留待运行

时间,但他的整个上下文是关于类型检查,所以这是'

只有'非常相关。


无论如何,他用这个作为基础来指出,由于这个

强类型检查在编译时,只有有效的操作

类型在运行时可用。嗯,是的,很明显 - 否则,它将导致编译时类型检查失败。所以,我再也看不出他是如何声称这是运行时实例化的。也许他对模板实例化或其他什么感到困惑

多态性?


然后他继续使用不同的措辞来描述C ++的事实
也在编译时进行强类型检查,但不知何故决定

两种语言在这方面完全相反:


"在C ++中,你可以在一个

类型参数类型的变量上做任何你该死的事。但是一旦你实例化它,它可能无法工作,

你会得到一些神秘的错误信息......所以从某种意义上说,C ++

模板实际上是无类型或松散类型。而C#泛型

是强类型的。


这是一个有效的批评,有时候C ++模板错误消息是

冗长和困难,但那是一个红色的鲱鱼(此外,在类似的复杂情况下,C#

错误信息如何比较?)。 C ++和C#

都提供模板的编译时类型检查。如果有错误,

编译器将报告它。他在这里做的是在每种情况下完全不同地解释这个

的行为。对于C#,他所做的只是

谈论这次检查所提供的美妙保证,完全说明了当然,C#还必须产生错误
如果类型检查失败,则$>
消息。对于C ++,他将确切的行为解释为与失败相同的行为,完全缺乏类型系统。

错误消息完全是你如何获得强大的类型检查!这是

最早可能的机会,缺少IDE集成,检查

对参数化类型执行的操作是否有效。如果您的代码中有类型错误,

编译器将不允许您继续

- 这是强类型检查!他缺乏对他正在使用的

条款的理解,进一步用短语在某种意义上表示。 - 确实

强类型的定义突然变得主观?从某个角度来看,这与明显具有欺骗性的b $ b相同。排序

的推理。


这是荒谬的,它是假的,它是错误的,它是FUD。吸引你的大脑

并阅读它直到你意识到这一点。


Luke



Right, that''s exactly the point. Templates are vastly more expressive
and useful than macros, so when the article states:

"C++ templates are really just like macros, except they look like
classes."

it''s simply untrue. Shortly thereafter, he apparently contradicts
himself:

(1) "C# does the instantiation at runtime"
(2) "C# does strong type checking when you compile the generic type"

He''s referring here to class instantiation, not object instantiation.
I don''t see how you can claim to do strong type checking without
instantiating the generic. Maybe some parts of it are left for run
time, but his whole context here is about type-checking, so that''s the
only part that''s really relevant.

Anyway, he uses this as a basis for pointing out that, due to this
strong type checking at compile time, only valid operations for that
type are available at runtime. Well, yes, obviously -- otherwise, it
would fail the compile-time type checking. So again, I don''t see how
he can claim that this is runtime instantiation. Maybe he''s confusing
polymorphism with template instantiation or something?

He then goes on to use different wording to describe the fact that C++
also does strong type checking at compile time, but somehow decides
that the two languages are completely opposite in this regard:

"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... So in a sense, C++
templates are actually untyped, or loosely typed. Whereas C# generics
are strongly typed."

It''s a valid criticism that C++ template error messages are sometimes
verbose and difficult, but that''s a red herring (besides, how do C#
error messages compare in similarly complex cases?). Both C++ and C#
provide compile-time type-checking of templates. If there is an error,
the compiler will report it. What he''s doing here is interpreting this
behavior completely differently in each case. For C#, all he does is
talk up the wonderful guarantees provided by this checking, completely
glossing over the fact that, of course, C# must also generate error
messages if the type checking fails. For C++, he interprets the exact
same behavior as a failure, a complete lack of a type system. The
error messages are EXACTLY how you get strong type-checking! It''s the
earliest possible opportunity, short of IDE integration, to check that
the operations performed on a parameterized type are valid. The
compiler will not let you proceed if you have type errors in your code
-- that IS strong type checking! His lack of understanding of the
terms he''s using is further indicated by the phrase "in a sense" -- did
the definition of "strongly typed" suddenly become subjective? It''s
the same as the obviously deceptive "from a certain point of view" sort
of reasoning.

It''s absurd, it''s false, it''s misinformed, it''s FUD. Engage your brain
and read it until you realize this.

Luke


这篇关于C#,Java和C ++中的泛型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆