简体   繁体   English

业务线应用:F#会让我的生活更轻松吗?

[英]Line of business applications: Will F# make my life easy?

I develop mainly line of business applications.No scientific operations. 我主要开发业务应用程序。没有科学运作。 No complex calculations. 没有复杂的计算。 Just tie User Interface to database. 只需将用户界面绑定到数据库。 The only reason I use threading is to do some work in background and still keep UI responding. 我使用线程的唯一原因是在后台做一些工作并仍然保持UI响应。

This may not be the best approach but this is what I follow 这可能不是最好的方法,但这就是我所遵循的

1.Create an working application first(without threads) and give it to end user to play for the sake of feedback. 1.首先创建一个工作应用程序(没有线程)并将其提供给最终用户以便进行反馈。
2.Once all requirements are locked, I try to use threads wherever it makes sense to improve performance. 2.一旦所有需求都被锁定,我尝试在有意义的地方使用线程来提高性能。

The code for steps 1 & 2 is overwhelmingly different and threading code dominates the actual code. 步骤1和2的代码绝对不同,并且线程代码在实际代码中占主导地位。

1.Will F# make my life easier in case of Line of Business applications? 1.对于业务线应用程序,F#会让我的生活更轻松吗?
2.Are there any particular UI technologies that will fit best with F#? 2.是否有任何特定的UI技术最适合F#? I mainly work on ASP.NET & Silverlight. 我主要研究ASP.NET和Silverlight。 WPF now & then. WPF现在然后。
3.Are there any good examples of Line of business applications/demos with F#? 3.有哪些业务应用/演示与F#的好例子?

I am not asking whether it is possible to develop Line of Business application in F#. 我不是在询问是否有可能在F#中开发业务线应用程序。 I am asking whether F# will make my life easier to develop Line of Business applications when compared to C#? 我在问,与C#相比,F#是否会让我的生活更容易开发业务线应用程序? My main concern will be threading & UI synchronization. 我主要担心的是线程和UI同步。

I'm in the same boat as you, doing lots and lots of line-of-business type apps, nothing "fun" like games or compilers or search engines. 我和你在同一条船上,做了很多很多业务类型的应用程序,没有像游戏或编译器或搜索引擎那样“有趣”。

Your mileage will vary, but at least in my own experience a lot of dev teams are reluctant to jump right into F# because no one else on the team knows or has even heard of it. 你的里程有所不同,但至少根据我自己的经验,许多开发团队都不愿意直接进入F#,因为团队中没有其他人知道或者甚至没有听说过。 And right off the bat, you have to fight those questions like "what does it do differently from C#?" 不管怎样,你必须解决这些问题,比如“它与C#有什么不同?” If you can convince your boss to let you write a few demo apps with it, go for it! 如果你可以说服你的老板让你用它写一些演示应用程序,那就去吧!

So with that being said, I find that C# isn't very good at business rules, but it handles GUIs like a champ; 所以说到这一点,我发现C#在业务规则方面并不是很擅长,但它处理的GUI就像一个冠军; F#'s immutability makes GUI development awkward, but business rules and workflows feel natural. F#的不变性使GUI开发变得尴尬,但业务规则和工作流程感觉很自然。 So the two languages have their own strengths and compliments one another's weaknesses. 因此,这两种语言各有所长,并互相恭维。

In my own LOB apps, F# runs circles around C# in a few areas: 在我自己的LOB应用程序中,F#在几个方面围绕C#运行:

  • F#'s async workflows and mailbox processors orders of magnitude easier to work with than native threads and even task parallel library. 幅度的 F#的异步工作流程和邮箱处理器订单容易的工作比原生线程,甚至是任务并行库。 Since using mailbox processors for interthread communication, I don't even remember the last time I've had to lock or thread.join() anything for syncronization at all. 由于使用邮箱处理器进行线程间通信,我甚至不记得上次我必须锁定或thread.join()任何事情进行同步。

  • Defining business rules engines and DSLs with unions FTW! 使用工会FTW定义业务规则引擎和DSL! Every non-trivial LOB app I've ever worked on has its own half-baked rules language and interpreter, and its almost always based on recursively switching on an enum to drill through the rules and find a match. 我曾经工作的每个非平凡的LOB应用程序都有自己的半生不熟的规则语言和解释器,它几乎总是基于递归地切换枚举来钻取规则并找到匹配。 Current project I have now contains 1300+ public classes, 900 or so are simple container classes to represent a rule. 我现在的项目现在包含1300多个公共类,大约900个是表示规则的简单容器类。 I think representing the rules as an F# union would substantially reduce the code bloat and make for a better engine. 我认为将规则表示为F#union会大大减少代码膨胀并使其成为更好的引擎。

  • Immutable code just works better -- if you get a new object with an invalid state, you don't have to search far to find the offending line of code, everything you need to know is on the call stack. 不可变代码只是效果更好 - 如果你得到一个状态无效的新对象,你不必搜索远来找到有问题的代码行,你需要知道的一切都在调用堆栈上。 If you have a mutable object with an invalid state, sometimes you have to spend a lot of time tracking it down. 如果您有一个状态无效的可变对象,有时您需要花费大量时间来跟踪它。 You can write immutable code in C#, but its really hard not to fall back on mutability, especially when you're modifying an object in a loop. 可以在C#中编写不可变代码,但实际上很难不依赖于可变性,尤其是当您在循环中修改对象时。

  • I hate nulls. 讨厌空。 I can't give an exact estimate, but it feels like half the bugs we get in production are null reference exceptions -- an object is improperly initialized and you don't know about it until you're 30 stack frames deep in code. 我不能给出一个确切的估计,但感觉就像我们在生产中获得的一半错误是空引用异常 - 一个对象未​​正确初始化,直到您在代码深度为30个堆栈帧时才知道它。 I think F# would help us write more bug free code the first time around. 我认为F#会帮助我们第一次编写更多无错误的代码。

C# usually works well when: C#通常适用于:

  • You're writing GUI code or working with inherently mutable systems. 您正在编写GUI代码或使用固有的可变系统。

  • Exposing a DLL or web service to many different clients. 向许多不同的客户端公开DLL或Web服务。

  • Your boss won't let you use the tools you want ;) 你的老板不会让你使用你想要的工具;)

So if you can get over the "why would we want to use a new language hurdle", I think F# will indeed make your life easier. 因此,如果你能克服“我们为什么要使用新的语言障碍”,我认为F#确实会让你的生活更轻松。

That's a very hard question to answer - I think that F# would make some aspects of your life much easier and some a bit harder. 这是一个非常难以回答的问题 - 我认为F#会让你的生活中的某些方面变得更容易,而且有些困难。

On the plus side, dealing with threading should be relatively painless - F# async workflows are a huge benefit. 从好的方面来说,处理线程应该相对轻松--F#异步工作流程是一个巨大的好处。 Also, F# Interactive makes rapidly iterating and exploring code very easy. 此外,F#Interactive可以非常轻松地快速迭代和探索代码。 To me, this is a huge benefit over C#, since I can test out minor code changes without going through a full build. 对我而言,这是一个比C#更大的优势,因为我可以在不经过完整构建的情况下测试较小的代码更改。

On the down side, the tooling for F# isn't where it is for C#, which means that you won't have access to GUI-builders, refactoring tools, etc. It's hard to say how big of a productivity hit this would cause you without knowing more about your scenario. 另一方面,F#的工具不适用于C#,这意味着您将无法访问GUI构建器,重构工具等。很难说这会对生产力造成多大影响你不知道更多关于你的场景。 One workaround would be to create a multi-language solution which has a thin C# front-end, but again the complexity may not be worth the benefit. 一种解决方法是创建一个具有精简C#前端的多语言解决方案,但同样复杂性可能不值得获益。

@Juliet and @kvb have good answers, I just want to reiterate how useful F# is for making threading easy. @Juliet和@kvb有很好的答案,我只想重申F#对于简化线程有多大帮助。 In my blog post " An RSS Dashboard in F#, part six (putting it all together with a WPF GUI) ", I say 在我的博客文章“ F#中的RSS仪表板,第六部分(将它与WPF GUI结合在一起) ”,我说

...Note the nifty use of 'async' here – I use Async.StartImmediate, which means all the code runs on the UI thread (where the Click handler starts), but I can still do non-blocking sleeps that don't jam up the UI. ...请注意这里使用'async'的漂亮 - 我使用Async.StartImmediate,这意味着所有代码都在UI线程上运行(Click处理程序启动的地方),但我仍然可以执行非阻塞睡眠堵塞用户界面。 This is one way that F# async just blows the doors off everything else. 这是F#异步只是吹掉其他一切的一种方式。

... ...

Our “ago” information (“3 minutes ago”) will quickly get stale if we don't refresh it, so we start a loop that redraws every minute. 如果我们不刷新它们,我们的“前”信息(“3分钟前”)将很快变得陈旧,所以我们开始一个每分钟重绘一次的循环。 Once again, F# async kicks butt, as I can just write this as though it were a synchronous loop running on the UI thread, but the non-blocking sleep call ensures that the UI stays live. 再次,F#async踢了屁股,因为我可以写这个就好像它是在UI线程上运行的同步循环,但非阻塞睡眠调用确保UI保持活动。 Awesome. 真棒。 ... ...

but that blog post is an example of using F# to hand-code the entire UI. 但该博客文章是使用F#手动编码整个UI的示例。 That implies trading away all of the great GUI tooling you get with C# or VB. 这意味着将您使用C#或VB获得的所有优秀GUI工具交易掉。 I imagine that a hybrid approach can potentially net almost all of the benefits of both (with the cost of having two projects in the solution where you previous just had one), but I don't (yet) have direct experience of my own to share here. 我认为混合方法几乎可以带来两者的所有好处(在解决方案中有两个项目的成本,而你之前只有一个),但我(还)没有直接的经验。在这里分享。

(Is there a canonical "problem example" of a C# GUI app where you need to add threading to improve perf or keep the app live during some long operation? If so, I should check it out.) (C#GUI应用程序是否存在规范的 “问题示例”,您需要在长时间运行期间添加线程以提高性能或保持应用程序的正常运行?如果是这样,我应该检查它。)

Something you might like to see: 你可能想看到的东西:

The First Substantial Line of Business Application in F# F#中第一个重要的业务应用

A big LOB app in F#. F#中的一个大LOB应用程序。

To address this I posted some thoughts of mine in using F#, 为了解决这个问题,我发表了一些使用F#的想法,

http://fadsworld.wordpress.com/2011/04/13/f-in-the-enterprise-i/ http://fadsworld.wordpress.com/2011/04/17/fin-the-enterprise-ii-2/ http://fadsworld.wordpress.com/2011/04/13/f-in-the-enterprise-i/ http://fadsworld.wordpress.com/2011/04/17/fin-the-enterprise-ii- 2 /

I'm also planning to do a video tutorial to finish up the series and show how F# can contribute in UX programming. 我还计划做一个视频教程来完成这个系列,并展示F#如何在UX编程中做出贡献。

I'm only talking in context of F# here. 我只是在F#的背景下谈论。

-Fahad -Fahad

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM