4 ms·
F# is fantastic, and the team behind it is super solid, having delivered generics for the CLR. What this post leaves out is some of the tooling you lose when y
by MichaelGG 14y ago
F# is fantastic, and the team behind it is super solid, having delivered generics for the CLR.
What this post leaves out is some of the tooling you lose when you move to F#. For what I assume are political reasons, F# keeps being marketed as a niche "scientific" product, when in reality, pretty much any C# code is better off being written in F#, even if you aren't writing idiomatic F#. I did one small test where I rewrote a C# program in non-idiomatic F#, and it required 1/20th the type annotations. C#'s just verbose - why use it?
Even WebSharper requires a "C# web site" to actually get Visual Studio to kick up IIS and make things run. There's no real C# code, but so much in the .NET/VS environment assumes C# (or VB).
In fact the worst times I've had with F# were due to other libraries depending on how the C# compiler is implemented, and failing when reflection/expression trees didn't look exactly the same. Fortunately the major use case (LINQ) seems to have been addressed quite solidly with F# 3.0.
- kevingadd 14y agoDoesn't F# still perform worse than C# in various scenarios? IIRC the functional glue adds some overhead and F# uses classes instead of structs in some cases.
- plorkyeran 14y agoJust straight up writing F# as if it was C# gives you similar runtime results, with sometimes shockingly less code due to how much more concise the syntax is. C# and F# interop is also pretty painless if you do run into something that simply can't be done performantly enough in F#.
- MichaelGG 14y agoI have not found that to be the case. Yes, sometimes certain idiomatic things in F# might be slower, but in that case, just write them like you would in C# and you'll get the same performance. So, at worst, you end up with the same code, with more concise syntax. There are a few exceptions, but in general, F# can emit anything C# can. In fact, with F#'s "inline" ability, you have more flexibility than you do in C# - the CLR does vastly better when handed a big IL function, versus expecting it to get inlining right. The F# compiler does more advanced optimizations, too.
- profquail 14y agoThere are some cases where the F# compiler emits slightly less-efficient code than the C# compiler. However, in my experience I've found that I'm able to implement algorithms much more efficiently in F# than C#, which more than makes up for any compiler inefficiencies.
- dkhenry 14y agoThis is essentially the same thing you find with Java and Scala. There are still a few benefits to using the base language, but for the most part you can get the same results in much less code with comparable performance. The only difference is that if I remember correctly F# has a _faster_ compiler then C# and limits where you can put code in your files while Scala has a slower compiler and lets you put your code any where you choose.
- kvb 14y agoThe biggest difference is that C#'s design is way better than Java's, so there's not nearly as much motivation to move to another language targeting .NET.
- gnuvince 14y agoAccording to an article linked in this article, there is.
- kvb 14y agoI love F# (I'm currently a contractor with the F# team in Microsoft Research), and I'm delighted to see people advocating its use. I prefer F# to C# by a wide margin. But C# is still a really well designed language, which makes it much harder for F# to gain wider traction than if it were competing primarily against a weaker language like Java.
- MichaelGG 14y agoNo, the C# compiler is wickedly fast. There's a story that the first internal version printed nothing on success, so the PM reported that it wasn't doing anything, when in fact it had compiled the source so quickly he thought it was just exiting. F#'s compiler is OK - it's doing a lot more work. But it's not instantaneous like C#.
- teyc 14y agoWhat's your development workflow like? Do you try out bits in the REPL then paste into source? What about incremental compilation, is this done at all or does the F# interpreter recompile everything at runtime?
- MichaelGG 14y agoHaving the REPL (F# Interactive) available always from inside Visual Studio is one of the biggest changes to my workflow, ever. It saves so much time, allows me to play with things, and on occasion, I've even used it for live debugging where a debugger wasn't possible (paste parts of the source into the REPL on production box, then interactively play with it). With C#, it was common to always have some project somewhere that was just a playground to run a few lines of code to test out a library, make sure I got a format string correct, etc. The F# REPL in VS eliminates that. If the F# team had more resources, and could make it fully integrated, it'd be unbelievable. F# doesn't have an interpreter, it's compiled. The REPL is taking your lines and compiling modules and whatnot on the fly, then loading and running them pretty much as normal. So when you build, you get a binary, and you're all set - no runtime overhead. Meanwhile, C# is supposed to have a REPL, Mono has an implementation, but it seems like C# is sort of abandoned and now the primary folks are working on yet another "almost-JavaScript-to-JavaScript" compiler.
- teyc 14y agoAre your F# projects web-based or desktop ones? I'd imagine hand coding UIs to be rather cumbersome. I had a look around the web, and I couldn't find any sample open source F# applications that one can take apart.
- coldtea 14y ago>F# is fantastic, and the team behind it is super solid, having delivered generics for the CLR. So the CLR generics team build F# (an Haskell like language) and the Java generic team build Scala (an Haskell like language). Hmm...
- jeremyjh 14y agoAlso, "the CLR generics team" has built a lot of Haskell. The Microsoft Research program in Cambridge has been developing the GHC for years. The F# project led to a number of improvements in the CLR. F# really started as "Haskell for .NET" according to Don Syme.