Saturday, September 7, 2019

I saw Eric Harding present at Triangle F# on Tuesday night.

North Carolina's Tech Triangle is founded around three nearby universities in Raleigh, Durham, and Chapel Hill and really the identity has expanded to a triangle of tech sphere jobs based around those three North Carolina cities. I visited all three on 9/3/2019, catching lunch at a brick and mortar Korean bar that evolved out of some food trucks called Namu in Durham, dinner at a Laotian restaurant called Bida Manda in Raleigh, and a tech event at the Chapel Hill public library on F#. Eric Harding hosted the event, a monthly meetup.com meetup of a group called "Triangle F#" (we just discussed what the triangle part of the name means) and while he kind of projected from his laptop (well, we could see his laptop display on a TV in the room) and spoke some it might be a stretch to say that he was the speaker or that there was a particular topic. Instead, this just seemed to be a free-for-all of thoughts from a handful of F# enthusiasts in the room. A lot of what I experienced builds atop this talk with mentions of Fable-Elmish and MVU. A host of other wacky things came up. Racket is a language based on the Scheme dialect (support for both functional and procedural programming) of Lisp. Eliza is an old chatbot. C came out in 1972 and machine learning (ML) in 1973. In "choose" in the gang of four patterns, you walk a chain of responsibilities trying to see if you match at each link of the chain and continuing if you do not. Blah, blah, blah. In MVU a view function is a pure function which takes in an immutable model and produces a model tree (a view) while an update function takes in your existing message and a model and gives you an updated model. A dispatch takes in an event. Eric showed off fable.io/repl on the TV, which is an online play place for F#. It uses, by default, I think, FiraCode (pronounced a bit like "fear of code") as a font which does wacky things like turn |> into a rightward pointing triangle (there is a triangle again) kind of like the play button of tapeplayer controls and -> into a rightward pointing arrow. So what do these two things do? Foo(Bar(Baz(qux))) in C# could be qux |> Baz |> Bar |> Foo in F# and the rightward pointing arrow is kind of like a lambda operator suggesting use what's at the left of the arrow as a variable name for immediate scope to be used in the machinery at the right of the arrow. Fake is the F# Make/Jake/Rake/Psake build tool. F# embraces immutability by default using immutable types and this means we have structural equality wherein you can just compare two different, independently created objects and still have the objects be equal if all of their properties are the same. That's not how it works with reference types in C# wherein you would be comparing two different pointers in a similar scenario and the two objects could never be equal. In C# you end up comparing perhaps the unique id of a database-driven object, be it integer or GUID, to its counterpart on a sister object to gauge if the sisters are really the same girl. The Fable, F# to JavaScript, porting is the way to go for the UI. The only variations for the UI are: What JavaScript framework do you poop code out to? It doesn't have to be React which is kinda the default. It can be Vue. Eric had not seen an Angular rollout but he didn't see why that would not be possible. In an App.fs file is where you would normally assign what version of JavaScript to spit out with something like .withReactBatched for example. There is no markup in the F# UI. You just have a function to represent a button for example. Here is what was shown off for making an HTML table:

Sencha Ext JS of course famously took this approach too and it wasn't really a good thing. One nice thing I will say about this is that when you think of what Blazor is attempting in the C# space, well, F# is really already there isn't it? If you want to explicitly compile to WebAssembly Bolero kinda leverages Blazor in the F# space. The reason to go there is if you want to loop in extras via NuGet packages as opposed to npm packages (which is what Elmish demands). Fabulous for F# spits out Xamarin XAML instead of JavaScript. OpenGL (Open Graphics Library) and GLSL (GL shading language) are things you may interop with from F#. You make 3D graphics with this stuff. A sequence in F# is like IEnumerable in C#. A discriminated union in F# is kind of like a union in TypeScript allowing for multiple possibilities with a pipe symbol wherein type Msq = | ChangeValue of string | Reverse might be an example. The SAFE stack uses Saturn, Azure, Fable, and Elmish. So what's Saturn? It is an abstraction on top of ASP.NET that allows you to write server-side stuff in a functional F# way that is somewhat akin to Ruby on Rails. It has canned routing for example. If you want to come off the rails, Giraffe is the do-what-you-will alternative. The convention of giving every class its own file in C# does not carry over to F#. Instead many things are often nested in one big file and scope builds top to bottom in a way it does not in C#. If you see a type in use and you wonder what it is you can probably just look upwards in the file to find it. Don Syme and Tomas Petricek are some of the big names in F#. F# tries to balance correctness with performance while F* (pronounced F star) has a heavier emphasis, as a similar programming language, on the correctness. Mozilla is porting F* to C in building their Everest project which attempts to allow builds that are verified as HTTPS-friendly (the S in HTTPS stands for Secure) top to bottom of web gunk. The immutability of F# plays nice with parallelism and allows for gains even as Moore's law breaks down. Also CPUs increasing have more than one die with their cores (actor managing a thread, doing work) not necessarily on the same die (chunk of silicon) and a packet cannot be shared across two dies like it might be across two threads. Herein again, the parallelism of immutability is a nice to have. let! (pronounced: let bang) is like the await keyword in C#. A packet.lock file allows for some of the Yarnesque-version-locking-flavored stuff. Type providers in F# allow for some code generation that lives at database tables. Of the two eateries, it was Namu I went back to again.

No comments:

Post a Comment