Thoughts On Using F# For Dev?

Let me preface this by saying F# and c# are functionally equivalent. I’m interested to know if there are any F# RhinoCommon devs who could weigh in on the pros and cons of using F# the F# way? Like the performance gain through ease of concurrency vs the loss from memory allocations due to the default of immutable variables.

I’m currently trying to parse through some c# I wrote years ago, and I’m reminded of all the purported benefits an F#. The conciseness, functions as parameters, piping, etc. of F# is in line with what I’m doing. I don’t want to build a library of objects. I’m building a library of functions to augment Rhino’s library of objects.

2 Likes

If you like F# then you should use it. There is nothing that should hold you back.

I’ve done some work with F# (first incarnation of my GH plug-in GhShaderNodes for creating custom shaders for Raytraced was written with it, some personal stuff), and @Goswin has even created an F# scripting plug-in which works pretty nicely.

Eric,
F# is great for scripting. I prefer it even over Python scripting.
F# is also great for plugins.

You can do object oriented and imperative code just as well with F# as with C#. I think even those are more succinct in F# than in C#.

All performance issues I had were related to approaching the problem wrongly. not to the language used.

here is a plugin template:

Thanks, @Goswin. I appreciate that.

@nathanletwory, I’ve never used F#, but as I’m reading through some stale c# code I’m thinking that it could be better.

I know it can perform just as well, but I’m still trying to wrap my head around the immutable default. The easiest money I’ve ever made was refactoring a website by replacing ‘string’ with ‘StringBuilder’. I can see the safety provided by immutable reference types, but am struggling to comprehend why fixed sized, local, stack value types are immutable. It bothers me there is no ‘i++’. Worse than that, it allows ‘let i = i + 1’ by creating shadow variables.

I’ll port something to F# and study the IL. It will be a good exercise no matter how it turns out.

I like the book Real-World Functional Programming by Tomas Petricek and Jon Skeet. It has lots of examples how to program ‘functionally’ in C# too. It won’t be as elegant and succinct as F#, but you can use many of the functional concepts without learning F#.

But by all means do learn it. Always good to have a new tool in your box.

Much more succinct and expressive. I just looked at domain modeling in F#, things like ‘firstName : String50’ and ‘cellPhone : Phone optional’. I wish I had a time machine. All the time I spent flipping back and forth to data definitions and business rules…

1 Like

That is called a learning curve (:

We use F# 100 percent in Rhino / Grasshopper.
It’s more concise, results in more reusable code with fewer bugs.
I think people are crazy not to use it.

1 Like

Here an über-simple GH component in F#

Note that this contains all necessary classes that makes up a GH plug-in with a GH component.

1 Like