Live data from Hacker News

Why F#?

batsov.com

351–360 of 424 posts

Re: Why F#?

#351

I'm completely convinced that F# (along with Scala, Haskell, and OCaml) adoption has stalled due to having ridiculously bad build systems. More significantly, they are being passed up in favor of Rust, which is a great language but nonetheless a bad fit for a lot of problem domains, simply because Rust has a superior build system. Hell, 80% of the reason I choose Rust over C++ for embedded work is because of the buil…

It’s always puzzled me that so many languages have their own build systems and package managers. Why aren’t programming language-agnostic build systems like Bazel and Buck more popular? It seems so strange that every new programming language essentially has to reinvent the wheel multiple times, inventing a new build system, package manager, formatter, linter, etc. I wonder if we’ll ever see something like LLVM for th…

Firstly a strong desire to self-host: write the build system in the language itself.

Secondly, often very differently shaped requirements. The dotnet SDK tries to keep its build specification (.csproj) files editable by Visual Studio, which is why most of the stuff in them is just XML properties.

You probably could build C#/F# with Bazel but that's not what Microsoft chose, and you kind of need to stay aligned with them and the large amount of MSBuild files in the SDK.

Re: Why F#?

#352
post #297
post #73

The problem with F#, Clojure and Elixir (hosted languages) For F# , you need some basic C# knowledge For Clojure, you need some basic Java knowledge For Elixir, you need some basic Erlang knowledge I like all 3 languages but usually each vm have a primary language, and each hosted language eventually become hosted on that primary language not the vm I understand that for many task simple, to medium complexity, you mi…

I've written a lot of Clojure now, and I've managed to avoided learning any Java really.

That’s a reassuring thing to hear as a new clojure learner who has little interest in java.

What bits of java have you ended up needing? Like do you often use java libraries that don’t have clojure wrappers?

I feel like I’m often running up against little things. I’ll google “how to do xyz in clojure” and the top SO answer is to use a java library that apparently everybody already knows about, cause so many clojurists came from java first!

Re: Why F#?

#353
post #59

In the case of F#, the use cases are diminishing with every new C# release, since C# is getting better and better at the things F# is supposed to be strong at (record types, pattern-matching, etc.). Better to write the thing in C# using modern features of the more popular and capable language.

F# can be nicer to use for a functional programming style.

It's not always about the features such as keywords, built-in functionality and types. It's also how language features work together.

C# is more fit for an imperative or OOP style when F# is more fit for a functional style.

Re: Why F#?

#354
post #350

Earlier quoted context omitted.

could also be "4" or 4! 4 seems like it would be the most evil option, honestly

The real evil option is C: 2+"22" = 0, 4+"4" = undefined behavior and probably the value of some other variable.

I think you meant: "22"+2 = "", and it is not UB to make the second pointer, only to use it

Re: Why F#?

#355

Earlier quoted context omitted.

You may start to get a point when C# gets a two-directional type inference system. As it's now, any functional-looking code requires so much boiler plate that it's shorter and less bug-prone to copy your functions code everywhere you want to use them.

Can you give an example of said boiler plate?

Using OneOf library or something similar instead of discriminated unions / sum types.

Trying to use a functional pipeline instead of DI.

Re: Why F#?

#356
post #350

Earlier quoted context omitted.

could also be "4" or 4! 4 seems like it would be the most evil option, honestly

The real evil option is C: 2+"22" = 0, 4+"4" = undefined behavior and probably the value of some other variable.

The real horror is "1d9" + 1 = 2, as does PHP: https://3v4l.org/Dn6Sm

Re: Why F#?

#357

Earlier quoted context omitted.

Static typing removes the downside of whitespace. Oh, and every language with line comments (so most of them) has significant whitespace.

> Static typing removes the downside of whitespace. How so? > Oh, and every language with line comments (so most of them) has significant whitespace. Technically true, but that's not what people mean by "significant whitespace" in this context. So you're being pedantic rather than saying anything meaningful. But you made me think. The ultimate nightmare would be significant trailing whitespace - the spaces and/or tab…

In f#'s case, there is the trifecta of everything being an expression, static typing and default immutability. This means you often write code like this:

let foo = if bar then baz else someDefault

Due to it being an expression you assign what the if evaluates to to foo. Due to static typing, the compiler checks that both branches return the same type. Due to the default immutability you don't declare and assign in separate steps. What this results in, is that accidentally using the wrong indentation for something usually results in an error at compile time, at the latest.

Compared to how python does significant whitespace is that it's dynamic typing + statement based, which means you can easily end up assigning different types to the same variable in different branches of an if, for example.

I hope I explained it in understandable terms

Re: Why F#?

#358

Earlier quoted context omitted.

Everything is an expression (i.e. its an actual functional programming language), and along with it comes a different way of thinking about problems. Coupled with a really good type system which has discriminated unions, you'll have much fewer bugs. Pro tip: don't write F# like you would write C# - then you might as well write C#. Take the time to learn the functional primitives.

if I may elaborate on "everything is an expression," F# allows you to do things like (with apologies for being a tad rusty with the syntax) let bar = if foo then 7 else 11 or let bar = try // code that might throw 7 with ex -> 11 and will ensure that both/all code branches return a compatible type for the `let` binding. Whereas in C# you have to do like int bar; if (foo) { bar = 7; } else { bar = 11; } And C# will le…

Also C#:

bar = foo switch

{

   true => 7,

   false => 11

}

Re: Why F#?

#359
post #73

The problem with F#, Clojure and Elixir (hosted languages) For F# , you need some basic C# knowledge For Clojure, you need some basic Java knowledge For Elixir, you need some basic Erlang knowledge I like all 3 languages but usually each vm have a primary language, and each hosted language eventually become hosted on that primary language not the vm I understand that for many task simple, to medium complexity, you mi…

> For F# , you need some basic C# knowledge For Clojure, you need some basic Java knowledge For Elixir, you need some basic Erlang

Honestly, none of this really rings a bell. Having used all three options, I never felt that. Well, I already knew C# before getting into F#, but honestly, it felt like my C# knowledge at the time was more of a distraction. Been using Clojure for nine years, never done any serious Java and have not felt any need for it. Not knowing Erlang wasn't a problem with Elixir, like at all.

Re: Why F#?

#360
post #297

Earlier quoted context omitted.

I've written a lot of Clojure now, and I've managed to avoided learning any Java really.

That’s a reassuring thing to hear as a new clojure learner who has little interest in java. What bits of java have you ended up needing? Like do you often use java libraries that don’t have clojure wrappers? I feel like I’m often running up against little things. I’ll google “how to do xyz in clojure” and the top SO answer is to use a java library that apparently everybody already knows about, cause so many clojurist…

> What bits of java have you ended up needing?

The same with Clojurescript and JS (and probably with Clojure-Dart) - you have nice interop with the hosting platform. The need for learning anything about Java (while writing Clojure) basically boils down to finding API documentation for a specific class and simply using it. That's all. That's all you'd ever need.

Post reply on HN