Why F# and Statically Typed Functional Programming?

Home Essays

What is programming?

Foremost, programming is a human production. Humans most distinguished capabilities are free will and abstract knowledge. Furthermore, we often put these two things together towards changing nature and producing stuff. Whenever we do that, we are doing art. Programming is an art.

Sculptors turn raw rocks into status. Painters turn canvas into paintings. Programmers are just like painters and sculptures, but our raw materials, processes, and outcomes are of a special kind.

The art of programming consists in: 1. abstracting away a representation of a real world process, then 2. encoding this abstract problem in a language, and finally 3. plugging this representation into a machine which interacts with the real world.

In doing the above, we want good tools. It seems to me a good tool should allow me to focus on the real world processes, and not on the tool itself. I don't want a tool that has me focus on the details of the tool! That would me insane! I am an "encoder of real world processes" and not a "user of a programming languages".

Now, back to FP. Our industry has evolved 2 main lines of languages: structured and functional.

In the early age of computers, we had assembly language, which mapped directly to the workings of the machine. Then industry people came and thought about hiding a few of the details within procedures. The languages though were still geared towards concepts of the machine, and to this day, people working with these tools keep being reminded of that. It seems Object Oriented actually had an interesting insight, but ended up deviated, and have turned into yet another way of hiding machine details. OO people are painting with a screwdriver. Plus, they are many, and they think that "being many" is reason enough in order for all of mankind to paint with a screwdriver.

On the other side of the story, when searching for inspiration to design their languages, mathematicians looked for the tool we have been using for thousands of years: mathematics. They defined 2 or 3 concepts, and from that it was derived computing power equivalent to the machines we have. Three concepts! Symbols, functions, and function application. The Lord be praised! This is beautiful. How many CPU instructions you need to get your basic hello world? Whereas structured languages are trying to hide the mess of thousands of CPUs instructions, FP starts with 3 concepts.

Then there is freaking Category Theory, which is yet another branch of Mathematics, and which tries to capture the essence of how composition works. If not in nature itself, at least in the human brain. And bang! FP people reviewed their language design in order to incorporate leanings from CT. Not only FP has fewer concepts to deviate you from the real world process, but it knows how real world process are composed! It seems we are getting closer to painting with an actual brush.

Now, of course, we have to pay our bills. If it was impossible to build with FP, I would happily pay my meals with OO dollars. Except the year is 2022, and thank to a bunch of awesome people, it is possible to ship web apps with FP. I am pretty sure history needs me on the side pushing FP, and not adding more numbers to the side trying to paint with screwdrivers.

Finally, let's get our attention to statically typed. If there is any value in automating processes, why not automate the process of automating processes? A dynamically typed language and a non relational database are the biggest "casa de ferreiro espeto de pau" I am aware. It basically says "you my dear customer, you are not organized enough to solve your problems without automation, but me, I am a special cookie, and I will handle my mess myself". Or maybe a fat nutritionist: "You eat the vegetables and exercise while I eat mc donalds". If you value your programming skills, apply it to your own job. Adopt static typing and relational databases today!

And what's more: FP and statically type work great together! Advanced function composition can get tricky to get right, and the compiler is there to remind you when you miss the types.

And the above reminds me of one final point: despite what people might say, programming is not about connecting libraries, but even when connecting libraries, I would do it with FP and statically typing.

Why F# in particular? Additionally to being FP and statically typed, it has access to a wide range of tools that I need to get the job done. Plus, I think the people behind it have more of a clue then the people behind Scala. Microsoft hires Haskell people, so F# stays neat, whereas Scala has to keep coping with weird JVM stuff. I am happy to consider any other tool that has statically typed + functional programming + has access to the libraries that help me ship on time.

Date: 2022-06-27 seg 00:00

Author: Juarez

Created: 2023-12-14 qui 10:16

Validate