您如何看待VB 10中的多行lambda [英] What do you think of multiline lambdas in VB 10

查看:112
本文介绍了您如何看待VB 10中的多行lambda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是在MSDN Channel 9上观看了一个视频,该视频可以在

I was just watching a video on MSDN Channel 9 which can be found here, about some of the new features in Visual Basic 10. Now I like most of the new features, some of which have been long awaited(auto properties and Collection Initializers), one that caught my eye was the multiline lambdas like in C#.

在视频中,他使用了以下示例:

In the video he used an example like this:

Dim scores = {10,20,30,40,50}
Dim thread as new Threading.Thread(Sub()
                                   For Each o in scores
                                     console.writeline(o)
                                     Next
                                   End Sub)

现在我很喜欢VB的冗长性,但是我有点担心编写sub ... end sub inline可能会有点混乱,当您仅使用C#编写C#时,我可以看到内联的一些优点使用c => {....}之类的东西,就可以减少很多代码.

Now I like VB in all it verbosity but I'm just a bit worried that writing sub...end sub inline could get a bit messy, I can see some merit in inlining when you are writing C# when you only have to use something like c => {....} and you can cut out a lot of code.

您在VB中使用多行lambda的经历是什么?

What are your throughts of multiline lambdas in VB?

您会发现它们有用吗?在哪里?

Would you find them useful and where?

推荐答案

我个人认为,VB的委托和lambda语法完全是伪造的.我的意思是,来吧,AddressOf!在VB6中很好.在VB.NET这样的语言中,应该应该被视为一等公民(当然,实际上不是),这在 .COM 语言中绝对不是很好.从方法组到委托的转换或多或少是透明的.

Personally, I think that VB's syntax for delegates and lambdas is completely bogus. I mean, come on, AddressOf! This was fine in VB6. It is definitely not fine in a language such as VB.NET where functions should be treated as first-class citizens (although they really aren't, of course) and where conversion from method groups to delegates is more or less transparent.

现在,内联函数的引入非常冗长.我实际上相信C#方法-x => f(x)在VB中效果很好,因为它准确地显示了它的作用.在当前状态下,我更喜欢C#进行任何函数式编程工作,这很遗憾,因为我通常偏爱VB.

Now the introduction of inline functions is horribly verbose. I actually believe that the C# approach – x => f(x) would fare very well in VB because it shows exactly what it does. At the current state, I prefer C# for any functional programming work, which is a pity because I generally favour VB.

现在,我真的很高兴VB最终获得了多行lambda和statement lambda,因为它们有时仍然有用(例如Parallel.For).但是语法混乱了.顺便说一句,迭代器也是如此(如果他们应该将其放入VB10中).

Now, I really rejoice that VB finally gets multiline lambdas and statement lambdas because they're still useful sometimes (take the case of Parallel.For). But the syntax is messed up. The same goes for iterators, by the way (if they should make it into VB10).

这篇关于您如何看待VB 10中的多行lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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