Live data from Hacker News

Get Started with F# as a C# developer

blogs.msdn.microsoft.com

41–50 of 60 posts

Re: Get Started with F# as a C# developer

#41
post #7

Ask HN: I've toyed around with F# and I kinda like it but I've never dug deep enough into it to answer the question: can I use this for 'real life' code as part of an existing C# desktop application for instance, e.g. build some F# into an assembly which is callable from C#? Without tons of hassle? What are good samples of real life application code in F#?

Absolutely Here's some nice slices

Starting with front-end since it's a bit easier to jump into

Back-End C#, front-end SPA in F#

Check out Fable-Elmish (and Fable-Elmish with React (Elm-style model-update-view for React)) https://github.com/fable-elmish/elmish

WPF Desktop -> Elmish.WPF (Elm-style model-update-view for WPF) Check-out https://github.com/Prolucid/Elmish.WPF

Back-End Slices for lambda-architecture-style systems

Web,Front-end in whatever, streaming with Storm and F# via FsShelter (and FsCassy for Cassandra, FsBunny for RabbitMQ)

Streaming, front-end in whatever, Web Layer with Freya

Also: Some tips Install VS Code with all the ionide plugins. Also grab Forge to create new fsharp projects if you're not doing net core development. Use Expecto for tests. Then from the editor you can build,run, debug, paket install, and run test(s)

Re: Get Started with F# as a C# developer

#42

Can anyone suggest any F# tutorials in the style of Michael Hartl's Rails Tutorial? F# suffers from an overabundance of "getting started" tutorials that focus only on the language and syntax. I get that F# is likely to be a lot of peoples' first introduction to a functional language, so that makes sense, but this one doesn't even tell you how to run the code it's showing you. The hardest part about learning any new l…

I think there is nothing better than the book: Expert F# https://www.amazon.de/Expert-F-4-0-Don-Syme/dp/1484207416/re...

I'm making my way through it now, but it doesn't have quite what I'm looking for.

I just found http://fsprojects.github.io/ProjectScaffold/structure.html, which is a good example of the kind of thing I'm interested in (ProjectScaffold in general, but that page in particular, which actually explains what everything in the project structure is for).

Re: Get Started with F# as a C# developer

#43
post #27

I'll take MS's commitment to F# seriously when they stop treating it like a 2nd class citizen. .NET Core 1.0 has been out for over a year, .NET Core 2.0 is in preview and there is ZERO support for F# with .NET Core in Visual Studio 2017. Yes you can use VSCode, but VSCode is no Visual Studio - it's a text editor on steroids, not a proper IDE that most C# developers have come to expect.

I agree, it's been a nightmare. I've dropped support for F# from my FOSS project because I can't get the .NET Core build working alongside the C# projects (and packed in a nu-get package, and deployed all in one process). I know that if I try to use it alongside any C# projects I will almost certainly lose many hours of time and it probably will fail to work at all. I don't know how much of this is the F# team's faul…

F# the 'eco-system' feels like it's going backwards at the moment.

As in physics, it's all relative. .NET has been moving so quickly lately that the F# team (from my outside-looking-in view) does not have the resources to keep up. You can see that by how stretched thin they are on GitHub issues. I'd imagine things will eventually stabilize once .NET Core settles in, but that'll be a few years.

But you are right, the tradeoff always seems to be "do I want to struggle and learn" or "do I just want to get things done."

Re: Get Started with F# as a C# developer

#44
post #7

Ask HN: I've toyed around with F# and I kinda like it but I've never dug deep enough into it to answer the question: can I use this for 'real life' code as part of an existing C# desktop application for instance, e.g. build some F# into an assembly which is callable from C#? Without tons of hassle? What are good samples of real life application code in F#?

I'm not gonna say thanks to each post individually, so: thanks for all replies! Really informative.

Re: Get Started with F# as a C# developer

#45
post #37

I need to know why to use F#, not how. C# is a business programming language. F# doesn't appear to be obviously useful in that regard.

Scott Wlaschin's talk does a pretty good job of demonstrating how F# is pretty great for BLOBAs (Boring Line of Business applications).

You can find it here: https://fsharpforfunandprofit.com/ddd/

Re: Get Started with F# as a C# developer

#46

Earlier quoted context omitted.

The first sentence in that post. "One of our previous posts, Why You Should Use F#, listed a few reasons why F# is worth trying out today" I would argue F# is a much better business programming language than C#. Admittedly, I am not very good at it, and have barely done more than a few toy programs in it, but F# (like most FP languages) allows you to bake in a lot of the rules into the Types themselves, and immutabil…

The link didn't copy over: https://blogs.msdn.microsoft.com/dotnet/2017/05/31/why-you-s...

I'd rather read an article than watch a keynote.

Re: Get Started with F# as a C# developer

#47
post #31
post #26

Earlier quoted context omitted.

Were your fellow developers interested in F#? I have found most people simply don't care and don't want to learn it. And there is the famous line "Functional programming? We did functions 30 years ago. No big deal".

> Were your fellow developers interested in F#? I was sole developer on that project. But here's a thought for you: you can only achieve mediocrity if all choices require 100% buy-in from all interested parties. > I have found most people simply don't care and don't want to learn it. No one likes to have their cheese moved. But cheese moves nevertheless. > We did functions 30 years ago. Most people saying that probab…

'But here's a thought for you: you can only achieve mediocrity if all choices require 100% buy-in from all interested parties."

Exactly! Unfortunately this is the reality in a lot of corporations. Pretty sad.

Re: Get Started with F# as a C# developer

#48
post #38
post #12

Are there any simple projects like HTTP server in F# for CoreCLR somewhere? With a Dockerfile if possible. Last time I tried to build something like that for PoC the amount of struggles I had with various versions of CoreCLR was overwhelming.

Giraffe is a fantastic little project that is a thin layer on top of ASP.NET Core. Works out of the box with the provided template, test locally, deploy to Azure, etc. https://github.com/dustinmoris/Giraffe

Thanks but I'm looking for something simple like returning plain text in 200 HTTP response using only built-in API. Completely minimal example. Using framework for me now would be like learning JavaScript by writing SPA in React.

Re: Get Started with F# as a C# developer

#49
post #43
post #27

Earlier quoted context omitted.

I agree, it's been a nightmare. I've dropped support for F# from my FOSS project because I can't get the .NET Core build working alongside the C# projects (and packed in a nu-get package, and deployed all in one process). I know that if I try to use it alongside any C# projects I will almost certainly lose many hours of time and it probably will fail to work at all. I don't know how much of this is the F# team's faul…

F# the 'eco-system' feels like it's going backwards at the moment. As in physics, it's all relative. .NET has been moving so quickly lately that the F# team (from my outside-looking-in view) does not have the resources to keep up. You can see that by how stretched thin they are on GitHub issues. I'd imagine things will eventually stabilize once .NET Core settles in, but that'll be a few years. But you are right, the…

If you want to get things done in .NET Core, use C#. If you want to learn functional programming then sure, use F# and the full .NET Framework...but good luck finding help when you need it because compared to the number of people Elixir, Scala, etc - hardly anyone is using F#.

I started learning F#, but ultimately I decided I'd rather learn either Scala or Elixir because they are more "mainstream" functional programming options. If anyone doubts this, compare the number of F# repos to Elixir/Scala on Github.

I've voiced my frustration on several Github issues about the fact that F# is understaffed at MS, that F# is a 2nd class citizen to C#, etc - to no avail. It's fine, management at MS makes those calls...but then they shouldn't be surprised that there's no uptake on F#'s usage.

Re: Get Started with F# as a C# developer

#50
post #37

I need to know why to use F#, not how. C# is a business programming language. F# doesn't appear to be obviously useful in that regard.

I would argue that F# is a better business programming language for a lot of reasons.

First, the type system is great when it comes to modeling the problem and communicating that model with non-technical project managers because writing good data models often means you write clear code that's idiosyncratic to the language. My experience is non-technical people understand clear data models and pipelines and those are two areas where F# code reads very clearly.

If OOP is your thing, I can argue it's a much better OOP language than C#. From a SOLID and Design Patterns perspective, the language has been streamlined to encourage a good OOP style by default. Design Patterns are simpler (Factory, Builder, Decorator, Adaptor, etc). Dependency Injection is very natural and implementing fluent APIs is a lot simpler.

The biggest benefits come from maintaining good hygiene. You're a lot less likely to have null reference exceptions or introduce invalid states. Race conditions are harder when most things are immutable by default. You're also less likely to encode things poorly because your type system sucks. You'll think more carefully about how you write loops, ifs and switch statements because the compiler catches and prevents you from doing boneheaded things. It's also has features that prevent you from accidentally adding cyclomatic complexity. For example, lower-level modules are not allowed to refer to higher-level modules. It's also harder to accidentally make functions recursive because it requires a special "rec" keyword.

I realize people dismiss hygiene, but this stuff really goes a long way to help manage complexity when it comes to growing and maintaining applications over long periods of time.

I'm not going to claim it's great at everything. It's a wonderful back-end and business language, and it's fantastic at modeling business objects and records. However, the tooling isn't there for doing WPF applications. Also, sometimes you come across issues with libraries that work well with C# defaults but not F# defaults. For example, F# properties tend to be read-only by default, so libraries that hydrate objects with data don't work unless you explicitly make those properties writable.

Nevertheless, if nothing else was an issue (buy in, training, etc), I'd opt to write the business logic in F# 9 times out of 10 times and save C# for the front-end (tooling).

Post reply on HN