一流的编程构造是什么? [英] What is a first class programming construct?

查看:75
本文介绍了一流的编程构造是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当试图在C#中做相当高级的事情时(例如某种hack),提出了一流的概念。



例如,一种方法是一流的编程构造,因为您可以使用它执行xyz(xyz不是该方法执行的操作,而是一般方法所提供的功能,我不记得现在的xyz是什么),但是在.NET 1.1中,委托不是之所以能够传递给方法,是因为它们不是一流的编程构造(我读过类似的话)。



一流的编程构造究竟是什么?

>

谢谢

解决方案

我怀疑您找不到正式的定义 显然JörgW Mittag找到了一个:)



<鉴于这个正式定义,我剩下的答案仅仅是我当时对它的理解。当然,使用一流构造一词的每个人是否都表示完全相同是一回事。



确定某物是否为第一件的方法类是不是要问自己这样的事情?


是否支持该功能并将
与其他功能完全集成
是一种语言,还是有很多
不必要的限制使
产生了这样的印象,即只是 bounded on
可能只解决
$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

如您所见,这是一个明确的灰色区域:)



C#中的代表是很好的例子,实际上。在C#1中,您可以 将委托传递给方法,并且有很多方法可以将它们 很好地集成到语言中(诸如可以进行转换,事件处理, =和-=转换为Delegate.Combine / Remove)。我会说他们是第一流的构造。但是,这与使用匿名方法,隐式方法组转换,lambda表达式和协方差从C#2和3中获得巨大代表的事实并不矛盾。可以说,它们现在是一流构造的 more ……尽管我会说它们在C#1中是一流,但我可以理解为什么有人会不同意。



对于 IEnumerable 可能也有类似的情况。在C#1.0中, foreach 支持它,但是 foreach 循环不会处理 IEnumerator 结尾。此部分已在C#1.2中修复,但仍仅对 consumption IEnumerable s提供语言支持,
不会创建它们。 C#2.0提供了迭代器块,这使得实现 IEnumerable (及其通用等效项)非常简单。这是否意味着可重复序列的概念在C#1.0中不是一流的构造?值得商basically的,基本上...


When trying to do something fairly advanced in C# (like some sort of hack), the concept of "first class" is raised.

For example, a method is a first class programming construct because you can do xyz with it (xyz is not what the method does, but what a method in general gives you, I can't remember what xyz was now), but in .NET 1.1 delegates were not able to be passed into methods because they were not first class programming constructs (I read something along these lines).

What exactly is a first class programming construct?

Thanks

解决方案

I suspect you won't find a formal definition Apparently Jörg W Mittag found one :)

Given that formal definition, the rest of my answer is merely my understanding of it at the time. Whether everyone who uses the term "first-class construct" means exactly the same thing is a different matter, of course.

The way to determine whether something is a "first class" construct or not is to ask yourself something like this:

Is the feature supported and thoroughly integrated with the rest of the language, or are there a lot of unnecessary restrictions which give the impression that it's just been "bolted on" possibly to tackle just one particular use case without consideration for other areas where the construct could be really useful if it had been more fully "part of the language"?

As you can see, it's a definite grey area :)

Delegates in C# are a good example, actually. In C# 1 you could pass delegates into methods, and there were plenty of ways in which they were well integrated into the language (things like conversions being available, event handling, += and -= translating to Delegate.Combine/Remove). I'd say they were first class constructs. However, that doesn't contradict the fact that delegates have gained tremendously from C# 2 and 3, with anonymous methods, implicit method group conversions, lambda expressions and covariance. They're arguably more of a first class construct now... and even though I would say they were "first class" in C# 1 I could see why someone might disagree.

A similar case might be made for IEnumerable. In C# 1.0, it was supported by foreach but the foreach loop wouldn't dispose of the IEnumerator at the end. This part was fixed in C# 1.2, but there was still only language support for consuming IEnumerables, not creating them. C# 2.0 provided iterator blocks, which make it trivial to implement IEnumerable (and its generic equivalent). Does that mean the concept of an iterable sequence wasn't a "first class" construct in C# 1.0? Debatable, basically...

这篇关于一流的编程构造是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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