Live data from Hacker News

Why F#?

batsov.com

191–200 of 424 posts

Re: Why F#?

#191

Earlier quoted context omitted.

I'm sure it can be the better choice, but for me it was not. It seems there was some incompatibility between me and Scala. I find it such a complex language and I never managed to wrap my head around it. As I said F# was my last choice at the start of my evaluation, and Scala was high on the list due to the Java ecosystem. But in the end it didn't work out for me. F# on the JVM would be great though!

Is F# easier to learn than Scala? (I know a bit of Scala (in the old 2.x days) but have no knowledge of F#.)

It definitely was for me! The syntax is simple, it is functional first but is not pure. I started with zero experience with ml languages and got productive fast enough to enjoy it. Of course my early f# code could be improved, but it was working and while writing the code the language didn't feel like a barrier.

One caveat though: it seems FP matches my way of thinking. As an example, I always liked recursion, while some others saw it as complexifying things.

Try fsharp as fsx scripts to avoid boilerplate (see blog post linked in other comment) and you'll rapidly feel if you like it or not.

Re: Why F#?

#192
post #11

I have a few questions. Can it do GUIs well? How about mobile? And how does it compare to e.g. Scala?

It can do GUIs well, although it takes some finesse to manage user state in an immutable-first language. Check out Fable for building web apps: https://fable.io/ I don't have much experience with Scala, but I think the two languages are pretty comparable in their respective ecosystems. The biggest difference I'm aware of is that Scala has typeclasses and F# does not.

F# is not really that strong on immutability, though. Sure, variables and struct fields are immutable by default, but making them mutable is one keyword away. Similarly with classes - declaring readonly properties is more concise, but when you need a read/write one, it's readily available.

Re: Why F#?

#194
post #43

Earlier quoted context omitted.

You can write a vast majority of your C# codebase in a functional style if you prefer to. All the good stuff has been pirated from F# land by now: First-class functions, pattern matching, expression-bodied members, async functional composition, records, immutable collections, optional types, etc.

I wouldn't say "all" - C# doesn't have discriminated unions yet, which is kind of a big one, especially when you're also looking at pattern matching. A

It has been in discussion for quite some time. I believe they'll get there soon: (example) https://dev.to/canro91/it-seems-the-c-team-is-finally-consid...

In the interim, MS demonstrates how C# 8.0+ can fake it pretty well with recursive pattern matching: https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...

Not the same I know, and I would love me a true ADT in C#.

Edit (a formal proposal): https://github.com/dotnet/csharplang/blob/18a527bcc1f0bdaf54...

Re: Why F#?

#195

> Trivia: F# is the language that made the pipeline operator (|>) popular. I’m not a dabbler in exotic languages, so this definition of “popular” was puzzling. I’ve literally never seen that operator before. Maybe I need to get out more.

It exists in several similar languages such as elixir, and was even a proposal for ecmascript, but never really got traction.

I'm familiar with it via Julia, and I believe recent versions of R also have it.

Re: Why F#?

#196

Earlier quoted context omitted.

I like F#'s syntax when all you're doing is pure logic. But when you have to interface with any IO like a database or REST call or something, you have to abandon the elegance of ML syntax and use these ugly computation blocks. In C# you can do something like this: var post = await _postService.getById(id); in F# the equivalent is basically let getPostById id = async { let! post = blogPostService.getPostById id return…

`var post = await _postService.getById(id);` the F# equivalent is `let! post = _postService.getById id`

You're missing the task {} block

Re: Why F#?

#197

Earlier quoted context omitted.

It is best to just use task CE full-time unless you need specific behavior of async CEs. The author of the original comment, however, does not know this nor tried verifying whether F# actually works seamlessly with this nowadays (it does). Writing asynchronous code in F# involves less syntax noise than in C#. None of that boilerplate is required, F# should not be written that way at all.

F# is a big language so I think it is to be expected that beginners will not know these things. I don't think the fix is to simplify F# we should just understand that F# is not for everyone and that is ok.

This is perfectly fine, but I think it's better to be unsure about specific language feature than confidently state something that is not correct (anymore).

Personally, I'm just annoyed by never-ending cycle of ".NET is bad because {reason x}", "When was this the case?", "10 years ago", "So?".

Like in the example above, chances are you just won't see new F# code do this.

It will just use task { ... } normally.

Re: Why F#?

#198

People will do anything except actually try Elixir. :D ...I mean: pipes, immutability, transparent mega-parallelism... helloooo? I tried F# some years ago (after I was fired from a shop that decided they will go all-in on Java and F# and dropping everything else overnight) and I was not impressed. I mean the language is really nice but the C# baggage and runtime was just a bit much. And I was not left convinced that…

Elixir is dynamically typed, which presumably many people are put off by.

Re: Why F#?

#199

> Trivia: F# is the language that made the pipeline operator (|>) popular. I’m not a dabbler in exotic languages, so this definition of “popular” was puzzling. I’ve literally never seen that operator before. Maybe I need to get out more.

It exists in several similar languages such as elixir, and was even a proposal for ecmascript, but never really got traction.

It made it to Stage 2, which is some traction: https://github.com/tc39/proposal-pipeline-operator

It has been "stuck" at Stage 2 for a while, though.

Re: Why F#?

#200

Earlier quoted context omitted.

There was a large group of folks that left Ruby on Rails for Elixir (even has a similar looking syntax), yet it wasn't on your list of languages to consider. Just curious, was there a particular reason?

I should have mentioned in the message, but I was looking for a strongly typed language. I was an avid-user of dynamically-typed languages, but that particular Ruby on Rails app became unmaintainable, and part of the culprit was due to the dynamic typing. I hoped that using a statically typed language would make it easier to maintain a complex app in the long term. And I must say that it totally materialised, to the…

This is a really minor point, but "strongly typed" and "statically typed" are not interchangeable terms. In the context of your comments here, you are exclusively interested in the static nature of the type system, rather than anything about the "strength" of it (which is something totally different and inconsistently defined).
Post reply on HN