Live data from Hacker News

A whirlwind tour of object-oriented code in F# (2012)

fsharpforfunandprofit.com

51–60 of 130 posts

Re: A whirlwind tour of object-oriented code in F# (2012)

#51
post #20

Earlier quoted context omitted.

Node has its place, i wouldn’t call F# an alternative to it. The node community is absolutely fantastic. F# is also an amazingly powerful language and im happy using it on the back end

What is Node's place?

The first stepping stone the front-end folks take into server side programming. :D

Re: A whirlwind tour of object-oriented code in F# (2012)

#52
post #44

Earlier quoted context omitted.

That sounds exactly the same as F# (except there might be more jobs in scala). F# is on .NET CLR and you can use all the .NET libraries, and it lets you fall back to an imperative style if you need to!

Try to use EF, WCF, UWP, WPF from F#.

[deleted]

Re: A whirlwind tour of object-oriented code in F# (2012)

#53
post #42

OO in F#. there goes the language...

OOP is not idiomatic F#. It is mostly for interop with C#.

I would not say that, sometimes it's quite powerful to combine these paradigms. I think they would not design a language for CLR only to force them to create a huge interop subsystem.

You are right, however, that OOP should not be the default way to write things in F#.

Re: A whirlwind tour of object-oriented code in F# (2012)

#54

Earlier quoted context omitted.

C# was usable in VS Code even 3 years ago

How is it these days? Is it “usable” or actually something you want to and enjoy using? Will I be left wanting Visual Studio? I mean I really enjoy IntelliJ, it makes programming Java like slicing butter. But I do want to try F#, people talk so highly of it.

Intellisense was working 100%, but I stopped using it after that because I switched platforms. I don't believe it's worse today, VS Code as an editor is a joy to use (I use it with TypeScript).

Re: A whirlwind tour of object-oriented code in F# (2012)

#55
post #4

F# is a joy to use. After a certain time, many C# developers find themselves writing in a functional style. F# makes this the default, but lets you continue using all of your existing code. Better yet, Linux and macOS support via .Net Core is excellent. F# on .Net Core is now a powerful alternative to Node.js.

> After a certain time, many C# developers find themselves writing in a functional style

If you can't move to F# or find its tooling abysmal and slow then I have a library [1] that makes the inertia flow positively in the functional direction in C#

https://github.com/louthy/language-ext/

Re: A whirlwind tour of object-oriented code in F# (2012)

#56
post #48

Earlier quoted context omitted.

It's almost to the point where the deciding factors in choosing between (C#-style) OOP and (F#-style) FP are: - Do you want your data types in one line or 20? - Pattern matching, or large concretions of if-statements? - Race conditions: Quality problem, or fun puzzle?

C# has most of the same pattern matching functionality at this point

There's no compiler warning for incomplete matches, and without discriminated unions it's pretty verbose to write pattern-match friendly types

C# has support for most F# features, they're just often awkward to use

Re: A whirlwind tour of object-oriented code in F# (2012)

#57
post #50

I think several interesting points were brought up in this thread regarding the assumption of functional aspects presented in F# by C#. LINQ being the most popular example. I am currently lead to believe that a purely functional application development domain is potentially an overreach of theory in terms of building things that can interact with the real world in very complex and 'functionally-leaky' ways. My biased…

I really encourage you to use F#, as someone who's done C# for a long time I find F# (while not perfect) does strike near to that ideal balance of FP / imperative you speak of. Writing functional code naturally is a breeze, while the language isn't going to punish you or feel awkward if you need to drop in some mutable state or OO programming

Re: A whirlwind tour of object-oriented code in F# (2012)

#58

I just bought Scott's book on Railway Oriented Domain Driven Design. So far so good. I am the domain expert though, so no revelation there. The modeling of state machines using types and functions is pretty revolutionary to me for where I'm currently at development skill wise. Everything just seems so clean and elegant.

The book is "Domain Modeling Made Functional"

https://fsharpforfunandprofit.com/books/

Re: A whirlwind tour of object-oriented code in F# (2012)

#59
post #20

Earlier quoted context omitted.

What is Node's place?

The first stepping stone the front-end folks take into server side programming. :D

What would you choose instead if you needed to write a simple web server?

Re: A whirlwind tour of object-oriented code in F# (2012)

#60
post #15

I used to be a big Haskell programmer. While I still love the language, I've really come around to the idea that strictly evaluated functional languages like F# or OCaml are the best for programming in. You get the nice functional features but don't have the straightjacket of laziness forcing you into certain design decisions. It's really nice sometimes to be able to mix in impure, side effectful code without having…

I use F# daily, and to get around this limitation I use hacky custom code generation an F# script (fsx) to generated specific types.

Additionally, on cases where you’re not specifying the data of the type itself, you can use static type constraints on members. This doesn’t give you a default implementation like Haskell but you can always provide one as a function.

Btw the monadic threading is still very useful, especially when mixing impure code and mutation (when appropriate). The async and result monads, in F# computation expression form, are particularly useful.

For a good example of async + impure code, check out MailboxProcessor, which is part of the standard F# lib. Works similar to CSP/goroutine + channels/actor models; makes parallelized concurrency and message passing easy. You can also make pure mailboxes easily by recursively passing data forward, but sometimes you don’t want to for memory / gc & alloc reasons.

Post reply on HN