像 MVC 这样的函数式语言和编程模型只是下一个流行趋势吗?

发布于 2024-07-11 16:29:02 字数 523 浏览 8 评论 0原文

最近,我听到了许多关于函数式编程语言(例如 F#)的好消息。 另外[与此无关],我还注意到 MVC 开始获得大量曝光——也许是自从 Silverlight/WPF 推出以来。

我从来不会在没有先做研究的情况下就跟风而行——事实上,我花了一段时间才转向.NET。 有人刚刚在我之前的一个问题中评论了有关早期采用新技术的问题,这让我停下来思考。

我一直在努力寻找时间学习 WPF,但现在开始怀疑这是否是正确的选择。 F# 等语言和 MVC 编程模型会继续存在还是只是下一个时尚? 或者人们真的认为它们会成为 C#/VB 和 OOP 的潜在替代品吗?

我的大部分开发都是在内部应用程序上进行的,要么以丰富的 Web 应用程序的形式部署在 Intranet 上,要么以 winforms 实用程序应用程序的形式分布在各个计算机上。 到目前为止,我选择的技术非常标准 - T-SQL/PL*SQL、C#/VB、JavaScript/AJAX、CSS。

我想我正在努力确定的是,在不久的将来,这些技术的哪种组合将是我的工具箱中最高效/最有用的?

Of late, I've been hearing many good things about functional programming languages such as F#. Additionally [and unrelated], I'm also noticing MVC is starting to get a lot of exposure - perhaps since the introduction of Silverlight/WPF.

I've never been one for jumping on a bandwagon without first doing my research - in fact it took me a little while to make the leap to .NET. Someone just commented in one of my previous questions about early adoption of new technologies and it made me stop and think.

I have been fighting to find time to learn WPF but am now starting to wonder if that's the way to go. Are languages such as F#, and the MVC programming model here to stay or are they just the next fad? Or do people really see these as becoming a potential replacement for C#/VB and OOP?

Most of my development is on in house applications either in the form of rich web applications for deployment on the intranet or winforms utility applications for distribution on individual machines. My technologies of choice this far have been pretty standard - T-SQL/PL*SQL, C#/VB, JavaScript/AJAX, CSS.

I guess what I'm struggling to determine is what blend of these technologies would be the most productive/useful to have in my toolbox in the near future?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

埖埖迣鎅 2024-07-18 16:29:03

至于 MVC,它是在 1979 年引入的。我记得在 1988/89 年期间,我在 Aldus Persuasion for Windows(Powerpoint 的一度竞争对手)中第一次实现了我的职业生涯。 MVC 框架在 RIA 应用程序中非常流行,例如基于 Adob​​e Flex 的 Web 编程(Cairngorm、Mate、PureMVC 等)。

在我的公司中,我们的第一个 Flex 应用程序并不是作为 MVC 完成的,但我们对模型有多个视图。 事情一定很混乱。 我们重构为 MVC,开发人员的生活变得更好了。

据我所知,只有那些尝试通过各种 Web 框架在服务器端实现 MVC 的人才会抱怨 MVC。 分布式计算的谬论会告诉他们,在 MVC 中使用 MVC 是一个坏主意。呈现渲染层被网络连接的鸿沟隔开。 分布式 MVC 和分布式对象一样糟糕。

对于 RIA Web 应用程序(例如基于 Flex 的应用程序),MVC 完全在客户端完成 - 正如 79 年在 Smalltalk 图形工作站中引入的那样。 然后,RIA 客户端仅使用异步服务调用和/或消息传递来与服务器端进行通信。

对于一个除了抛出单个 CRUD 表单之外什么都不做的应用程序来说,MVC 可能有点大材小用了。 但对于具有相当复杂性的丰富 GUI 应用程序来说,MVC 仍然是一种非常明智的采用模式。

As to MVC, it was introduced in 1979. I remember implementing it for the first time in my career in Aldus Persuasion for Windows (a one-time competitor to Powerpoint) in the 1988/89 time frame. MVC frameworks are all the rage in RIA applications such as Adobe Flex-based web programming (Cairngorm, Mate, PureMVC, etc.).

In my company our first Flex app was not done as MVC, yet we had multiple views into the model. It got to be a mess. We refactored to MVC and life got way better for the developers.

As far as I can tell it's only the folks that try to implement MVC on the server-side via any of the various web frameworks, that are the ones the complain about MVC. The Fallacies of Distributed Computing would have informed them that it was a bad idea to do MVC where the presentation rendering layer is separated by the gulf of a network connection. Distributed MVC is just as bad as distributed objects.

With RIA web apps, such as those based on Flex, MVC is done purely on the client side - just as it was introduced in Smalltalk graphical workstations back in '79. RIA clients then only use async service calls and/or messaging to communicate with the server-side.

For an app that did nothing but throw up a single CRUD form, then yeah, MVC might be overkill. But for rich GUI apps that have a fair amount of complexity going on, MVC can remain a very sensible pattern to adopt.

冷心人i 2024-07-18 16:29:03

函数式语言在开发代码中的实际使用完全取决于您正在编码的领域。 正如其他答案中所述,对于经典的“业务线”应用程序,如果您已经了解 C#,那么您不太可能很快切换到 F#。

但是:

  • 在开发代码中不使用它并不意味着它在其他地方没有用处(例如分析数据,或者在不陷入 OO 噪音的情况下对算法进行原型设计)
  • 学习函数式语言将教会您另一种思考编码的方式,这可能对你的 C# 有益
  • 学习函数式语言也能让你更深入地了解 C# 的函数方面
  • 完成我的列表 - 尽管这已经在 SO 的其他地方重复了一遍 - 没有人建议 F# 将取代 C# ,它只是盒子里的另一个工具。 如果您现在不需要该工具,那么“购买”该工具可能会太昂贵,但至少,您应该尝试了解它的用途,以备将来您当前的工具集无法满足需要时使用。

The practical use of functional languages in development code depends entirely on what domain you are coding for. As stated in other answers, for classic 'line of business' apps, if you already know C#, you're not likely to be switching to F# any time soon.

HOWEVER:

  • Not using it in development code doesn't mean that it can't be useful elsewhere (analysing data for example, or prototyping algorithms without getting bogged down in OO noise)
  • Learning a functional language will teach you another way to think about coding, which will probably be beneficial to your C#
  • Learning a functional language will also give you greater insight into the functional aspects of C#
  • To complete my list - even though this has been repeated and repeated elsewhere in SO - nobody is suggesting that F# will replace C#, it's just another tool in the box. 'Buying' that tool may be too expensive if you don't need it right now, but at the least, you should try to understand what it does, for the day when your current toolset doesn't suffice.
天赋异禀 2024-07-18 16:29:03

不,它们不是时尚。 不,人们并不认为它们会成为 C#/VB 和 OOP 的潜在替代品。 如果可以节省时间或金钱,人们就会使用它们。

我认为你必须跟上潮流,看看其他聪明人对什么感到兴奋,或者闭上眼睛,希望风暴在几年内过去。 有些技术会坚持下去,而另一些则不会。 MVC 与 OO 和 函数式编程与编程一样古老。

No, they are not fads. And no, people do not see these as becoming a potential replacement for C#/VB and OOP. People will use them if it saves them time or money.

I think you have to make the call of hopping on the bandwagon and see what other smart guys are excited about, or close your eyes and hope the storm passes in a few years. Some technology will stick while others don't. MVC is as old as OO and functional programming is as old as programming, though.

天涯沦落人 2024-07-18 16:29:03

一点也不。

函数式编程语言已经存在数十年了。

作为“MVC”的编程模型实际上是一种设计模式,并且现在有许多框架在使用它。

也许这里唯一的新事物就是你的观点。 在它们来到 MS 世界之前,您并不知道它们的存在,也不知道它们的使用如此广泛。

我的第一份工作是使用 2000 年 Apple comp 的 WebObjects Framework。开发起来非常容易用它。

Not at all.

Functional programming languages have been here for decades.

Programming models as "MVC" that is actually a design pattern and there are many frameworks using it by some years now.

Probably the only new thing here is your perspective. You didn't knew they existed or they were so wide spread used until they came to the MS world.

My first job was using WebObjects Framework from Apple comp back in 2000. It is very easy to develop with it.

蒲公英的约定 2024-07-18 16:29:03

函数式编程作为范例具有许多优点:
它提供了许多与面向对象设计在较小团队中工作时相同的优点(数据封装、多态性、代码可移植性......)
由于数据的不变性和无状态性,它不太容易出现错误。
穿线更容易。

Functional programming has a who host of advantages as a paradigm:
It offers many of the same advantages that object oriented design does when working in smaller teams (data encapsulation, polymorphism, code portability...)
It is less prone to bugs due to the immutability of data, and stateless nature.
It is easier to thread.

那请放手 2024-07-18 16:29:03

我不会谈论 MVC Web 应用程序的可行性……对于我们这些开发框架的人来说,这些框架已经概述了清晰的模式 - 这只是剥皮的另一种方式。 我从来没有对 ASP.NET 的总体情况感到困惑,因此认为 MVC 在某种程度上使其变得更简单通常是用词不当。 它可能对一种方法有用,但不适用于所有方法 - 因此落入工具箱中的另一个工具。

我们真的需要另一种工具吗?

I won't speak on the viability in web apps for MVC... for those of us developing frameworks which have outlined clear patterns - it is just another way to skin the same cat. I have never struggled on the overall picture of ASP.NET, so to think MVC somehow makes it simpler is often a misnomer. It may be useful for one approach but not all approaches - thus falling to yet another tool in the toolbox.

Is what we need really another tool?

菩提树下叶撕阳。 2024-07-18 16:29:03

我确信 C# 和 VB 将永远存在……但也会有很多人进入新技术的前沿。 他们将能够用更少的代码做更多的事情,而您将能够用已有的代码做更多的事情。 所以不用担心,这将是一场公平的战斗。

即使...学习更多的东西可以让你更好的编程,所以...这取决于你!

我想说的是,关于学习更多语言如何更好地了解每种语言的能力,然后使用所有这些信息来编写更好的代码,存在很多模糊之处。 但如果你花同样的时间来主宰一门语言,你就会没事的。

Im sure C# and VB will be there forever... but there will also be a lot of people going in the edge with new technologies. They will be able to do more with less code and you will be able to do more with the code you already have. So dont worry it will be a fair fight.

Even tho... learning more stuff makes you better programming so... its up to you!

what im saying is that theres a lot of fuzz on how learning more languages is great to know what each language is capable of and then use all that information to make better code. But if you spend that same time dominating a language, your gona be fine.

时光沙漏 2024-07-18 16:29:03

从我对函数式语言的(极其)基础知识来看,它们可能在我们作为开发人员的未来中占有很高的地位。 许多聪明人都评论过这样一个事实:由于处理器没有变得更快,因此需要使用更多的内核。 因此并行编程将变得更加主流。 函数式语言适合并行任务,因为它们不维护状态(有效地消除了与并行编程/线程相关的大多数常见问题,例如锁等)。

有关这一点的更多信息,我想引导您访问 这篇文章讨论了可变/不可变数据,并比较了 c# 和 f# 代码片段。

From the (extremely) basic knowledge I have of functional languages - they MAY have a high place in our future as developers. Many smart people have commented on the fact that since processers aren't getting quicker, more cores will need to be used. Thus parallel programming will become more mainstream. Functional languages are suited to parallel tasks as they do not maintain state (effectively eliminating most of the common problems associated with parallel programing/threads, such as locks etc).

For more information on this particular point I'd like to direct you to this article which discusses mutable/immutable data, and compares c# and f# code snippets.

新雨望断虹 2024-07-18 16:29:02

两者都不是一种时尚,也不会很快消失,但实际上我只希望看到大多数 .NET 开发人员经常使用这两者中的一个...

F# 和 ASP.NET MVC 之间有很大的区别; F# 是一种函数式语言 - 在某些情况下具有许多优势,但对于大多数业务线编程,通用语言(例如 C#)通常更有用。 然而,了解编程的函数式风格(特别是重不变性)可以获得很多好处。 我研究了 F#,即使我从未在 F# 中编写过任何生产代码,我也希望它能改进我的 C#。 幸运的是,得益于委托和 lambda,C# 可以以函数式方式使用,即使它不是正式的 FP。

然而,ASP.NET MVC 是一个非常不同的野兽。 MVC(更一般地说)是一种已知的、已建立的和值得信赖的模式,它:

  • 极大地提高了表示层的可测试性
  • 在 UI 层上实现关注点的逻辑分离
  • 提供对页面底层 html
  • 和许多其他内容的更 直接的访问(模型绑定等)

或者另一种方式:对于很多人来说,它使 ASP.NET 终于有意义; 我完全希望在来年能够大量使用 ASP.NET MVC。

Neither is a fad, and neither is going away any time soon, but in reality I only expect to see one of those two in regular usage by most .NET devs...

There's a big difference between F# and ASP.NET MVC; F# is a functional language - this has a number of advantages in a few scenarios, but for most line of business programming a general purpose language such as C# is generally more usable. There is, however, lots to be gained from knowing about the functional style of programming (especially re immutability). I looked at F#, and I hope it improves my C# even if I never write any production code in F#. Fortunately, thanks to delegates and lambdas, C# can be used in a functional way, even if it isn't formally FP.

ASP.NET MVC, however, is a very different beast; MVC (more generally) is a known, established and trusted pattern that:

  • vastly improves the testability of the presentation tier
  • makes a logical separation of concerns at the UI tier
  • provides more direct access to the underlying html of the page
  • and a lot of other things (model binding, etc)

Or another way: to a lot of people, it makes ASP.NET finally make sense; I fully expect to make a lot of use of ASP.NET MVC in the coming year.

红尘作伴 2024-07-18 16:29:02

我觉得把函数式编程和 MVC 混为一谈是很奇怪的; 我发现他们没有任何关系,除了他们都超过 30 岁并且在各自的社区中地位很高。 因为我对函数式编程有所了解,所以我会谈谈它。

函数式编程已有近 50 年的历史,并且将继续存在,尽管尚不清楚它是否会成为主流。 显而易见的是,函数式语言充当了孵化器的角色,并为最终进入主流语言的功能提供了试验场。 一些例子:

  • 垃圾收集
  • 第一类函数闭包(1995 年添加到 Perl 中,此后出现在所有脚本语言中;出现在 Smalltalk-80 中;在 Java 和 C# 中以各种方式模拟)
  • 参数多态性(C++ 中的模板)

从长远来看在你的工具箱中拥有函数式技术将使你成为一个更好的程序员。 或者正如 Eric Raymond 所说,学习 Lisp。 (Lisp 和 Haskell 都充满了强大的新想法,这些想法将以不同的、无与伦比的但有用的方式让你的头脑爆炸。F# 更像是函数式语言中经过验证的最佳想法的整合,与 .NET 框架结合在一起。 2009 年初,它似乎最有可能成为主流。)

I find it very strange to lump functional programming and MVC in one question; I find them in no way related, other than that both are over 30 years old and very well established in their communities. Since I know something about functional programming I will speak to that.

Functional programming is almost 50 years old and is here to stay, although it is not clear if it will ever become mainstream. What is clear is that functional languages have acted as incubators and then proving grounds for features which eventually find their way into maintstream languages. Some examples:

  • Garbage collection
  • First-class function closures (added to Perl in 1995, in all scripting languages since then; present in Smalltalk-80; emulated in various ways in Java and C#)
  • Parametric polymorphism (templates in C++)

In the long run having functional techniques in your toolbox will make you a better programmer. Or as Eric Raymond says, learn Lisp. (Both Lisp and Haskell are loaded with powerful new ideas that will make your head explode in different, incomparable, but useful ways. F# is more of a consolidation of the very best proven ideas from functional languages, married to the .NET framework. In early 2009, it appears to have the best chance of becoming mainstream.)

じ违心 2024-07-18 16:29:02

这些天我在SO上看到了很多这样的事情。 (请参阅此处此处,以及此处提供了一些示例。)

根据维基百科,Lisp 是当今仍然普遍使用的第二古老的编程语言(被 Fortran 击败)。 函数式编程不再是一种时尚,就像晶体管、鼠标、计算机显示器、硬盘驱动器,或者实际上个人计算机的概念一样,这些在 1958 年 Lisp 诞生时都不存在。编程在典型的商业环境中可能不是特别有用,但它的受欢迎程度的盛衰并没有使其成为一种时尚,也没有使其成为一种玩具。 对计算科学有敏锐鉴赏力的程序员明白,函数式编程与其说是一项发明,不如说是一项发现——对计算基本性质的深刻洞察。

更重要的是,如果编程是您的日常工作(而不是真正的热情),那么 F# 是在浪费您的时间吗? 从某种意义上说,它可能是这样的,它不太可能变得流行到足以保证将其包含在您的简历中。 另外值得注意的是,如果您确实投入时间学习 F#,但您的同事都无法理解您的工作,那么您选择它作为开发工具可能弊大于利。 但这仍然没有使它成为一种“时尚”。 :)

至于 MVC,它已经存在很长时间了——可能有十多年了,但我一直没有跟踪。 它不是灵丹妙药,也不难掌握; 这只是另一种发展模式。 还值得注意的是,MVC 并不是一个标准,甚至不是一个非常明确的技术。 解释 MVC 的方法有很多种,我什至敢说正确的方法不止一种。

MVC 恰好对于 Web 开发特别有用,因为 Web 应用程序往往具有非常混乱的前端代码(支持所有这些不同的浏览器是一个巨大的痛苦),并且您最不想看到的就是让您的业务逻辑陷入前端-不必要地结束。 与 F# 不同,学习 MVC 并不是浪费时间,即使编程严格来说只是您的日常工作,因为如果您发现自己在开发 Web 应用程序,那么遵守 MVC(即使只是松散地遵守)可以节省您的时间来自职业尴尬。

I've been seeing a lot of this sort of thing on SO these days. (See here, here, and here for a few examples.)

According to Wikipedia, Lisp is the second oldest programming language still in common use today (beaten out by Fortran). Functional programming is no more a fad than the transistor, the mouse, the computer monitor, the hard drive, or, indeed, the very notion of a personal computer, none of which were present at Lisp's inception in 1958. It is true that functional programming may not be particularly useful in a typical business environment, but its waxing and waning levels of popularity do not make it a fad, nor do they make it a toy. Programmers with a keen appreciation of computing science understand that functional programming isn't so much an invention as it is a discovery--a deep insight into the fundamental nature of computation.

More to the point of your question, if programming is your day job (as opposed to a true passion), is F# a waste of your time? It probably is, in the sense that it is not likely to ever become popular enough to warrant including on your resume. It's also worth noting that if you do invest the time to learn F#, but none of your colleagues can understand your work, you may be doing more harm than good by choosing it as a development tool. That still doesn't make it a "fad." :)

As for MVC, that's been around for a long time now--probably over a decade, but I haven't been keeping track. It's not a silver bullet, nor is it difficult to grasp; it's just another development pattern. It's also worth paying attention to the fact that MVC is not a standard or even a very well specified tech. There are many different ways to interpret MVC, and I would even venture to say that there is more than one right way to do it.

MVC happens to be particularly useful for web development because web applications tend to have very messy front-end code (supporting all of those different browsers is a royal pain) and the last thing you want is to have your business logic mired in with the front-end unnecessarily. Unlike F#, learning MVC is not a waste of time even if programming is strictly just a day job for you, because if you ever find yourself working on a web application, adherence to MVC (even simply loose adherence to it) can save your ass from professional embarrassment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文