Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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.
2.Once all requirements are locked, I try to use threads wherever it makes sense to improve performance.

The code for steps 1 & 2 is overwhelmingly different and threading code dominates the actual code.

1.Will F# make my life easier in case of Line of Business applications?
2.Are there any particular UI technologies that will fit best with F#? I mainly work on ASP.NET & Silverlight. WPF now & then.
3.Are there any good examples of Line of business applications/demos with F#?

I am not asking whether it is possible to develop Line of Business application in F#. I am asking whether F# will make my life easier to develop Line of Business applications when compared to C#? My main concern will be threading & UI synchronization.

like image 573
funwithcoding Avatar asked Feb 23 '10 16:02

funwithcoding


People also ask

What are line of business applications?

Line of business applications are software applications which are used to facilitate the unique requirements of a team, department, company, or industry. In contrast to productivity applications, such as spreadsheets, which are common to most organisations, LOB applications are specific to the needs of a smaller group.

What are lines in business?

Line of business (LOB) is a general term which refers to a product or a set of related products that serve a particular customer transaction or business need. In some industry sectors, like insurance, "line of business" also has a regulatory and accounting definition to meet a statutory set of insurance policies.

Who are line of business users?

Line of business in banking The bank can define their LOBs based on the clients they serve, i.e., individuals, small & medium businesses, investors, etc. For example, personal (or retail) banking provides deposit, mortgage, consumer loan, and investment products to individuals.


4 Answers

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. And right off the bat, you have to fight those questions like "what does it do differently from 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; F#'s immutability makes GUI development awkward, but business rules and workflows feel natural. 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:

  • F#'s async workflows and mailbox processors orders of magnitude easier to work with than native threads and even task parallel library. 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.

  • Defining business rules engines and DSLs with unions FTW! 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. Current project I have now contains 1300+ public classes, 900 or so are simple container classes to represent a rule. I think representing the rules as an F# union would substantially reduce the code bloat and make for a better engine.

  • 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.

  • 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. I think F# would help us write more bug free code the first time around.

C# usually works well when:

  • You're writing GUI code or working with inherently mutable systems.

  • Exposing a DLL or web service to many different clients.

  • 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.

like image 100
Juliet Avatar answered Sep 26 '22 05:09

Juliet


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.

On the plus side, dealing with threading should be relatively painless - F# async workflows are a huge benefit. Also, F# Interactive makes rapidly iterating and exploring code very easy. To me, this is a huge benefit over C#, since I can test out minor code changes without going through a full build.

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. 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.

like image 33
kvb Avatar answered Sep 26 '22 05:09

kvb


@Juliet and @kvb have good answers, I just want to reiterate how useful F# is for making threading easy. In my blog post "An RSS Dashboard in F#, part six (putting it all together with a WPF GUI)", I say

...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. This is one way that F# async just blows the doors off everything else.

...

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. 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. Awesome. ...

but that blog post is an example of using F# to hand-code the entire UI. That implies trading away all of the great GUI tooling you get with C# or VB. 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.)

like image 7
Brian Avatar answered Sep 30 '22 05:09

Brian


Something you might like to see:

The First Substantial Line of Business Application in F#

A big LOB app in F#.

like image 2
Onorio Catenacci Avatar answered Sep 29 '22 05:09

Onorio Catenacci