Who Cares About Functional Programming?

Came across

Who Cares About Functional Programming?

via

https://twitter.com/FrancescoC/status/1176815716340785152

On a related note:

Dependency Injection revisited - Mark Seemann

Blog:

An entertaining demonstration by Mark Seemann showing the awful hoops one has to jump through in C# to (fully) implement the (much more straightforward) F#/Haskell inspired Dependency Rejection technique.

Kind of reminded me of this old topic:

C# can do everything that Elixir can do and more

The issue is that C# will never inform your thinking to better solution approaches where using C# in itself may become an obstacle/hinderance.

Teaching Functional Programming to Professional .NET Developers (pdf)

9 Likes

Mark Seemann is always entertaining. He illustrates perfectly in this video why I ran the hell away from C# in general. I tried for so long to scratch my FP itch with that language. But ended up with horribly unreadable code that not one of my colleagues could grok. Even with really nice libs such as LanguageExt.

I got pretty deep into Scala for a few years and got tired of the type wrangling that made it feel unnatural.

F# was nice. But I got the green light at a new gig on Elixir.

To be perfectly honest, I thought I would miss the static typing. But I’m really liking the BEAM without it.

4 Likes

The C# vs. F# situation seems similar to worse-is-better vs. the-right-thing all over again (Back to the Future: Is Worse (Still) Better? (pdf); c2.com: WorseIsBetter).

2 Likes

I am one of the weird people (maybe the only one) that hates strict static typing. I always feel limited by it.

I’ve always felt that if a program feels limited by static typing than the program is ill-defined. ^.^;

Static typing is a check on yourself and future maintainers, it will not limit a program that is not ill-defined.

I only worked with Typescript and Golang so far when it comes to static typing.

Typescript is a mess when you want to interact with DOM elements. Code works just fine but Typescript still complains about stupid things.

Golang is a whole new level of annoyance. If you don’t use a Golang specific IDE/Editor, then you are lost. It often doesn’t even compile because there is an unused variable because you just commented things out to debug something. Instead of optimizing that in the compiler, the stupid thing just cries like a 2 month old. Anyway, back to the static typing. Yesterday I just wanted to consume a simple JSON API endpoint. Load the data, iterate over it, done. Nope. Parsing the JSON into map[string]interface{} works, but then you can’t use the data in any usable way. It contained an array of items. I just wanted to iterate over it, but Golang didn’t let me because it didn’t know there was an array. So I had to cover the whole JSON structure with structs to silence Golang.

You might say “Well, but if the API doesn’t return what you expect, the program will fail!”. Right, but if that is the case, the program will fail anyway because it can’t parse the JSON into the structs. Same outcome (program fails) but twice the work.

For several years, I worked with PHP without any typing system and never had any problems. Now I am using Elixir and with pattern matching, I don’t even see the need for a stricter typing system.

You could have done a type assertion, something like this:

data := parseJsonIntoMapStringInterface()
if names, ok := data["names"].([]string); ok {
  for _, name := range list {
    fmt.Println(name)
  }
}

But yeah, adhoc JSON interaction is painful. And whenever possible I try to avoid go, though go any python are about the only options at my company :frowning:

I also have to work with golang here. It’s horrible. It’s basically Google Driven Development. And not having the functions from Elixirs Enum module is really frustrating.

Oh I’m sorry! Those are bad ones to start with…

Typescript’s typing is very much designed to fit the javascript ecosystem, it helps add checks but it is a bit more…fluffy then what is traditional.

Go’s types are extremely limited, like I’m not sure I’ve ever seen a language with more limited typing, like it’s so limited that most code I’ve seen in it abuses Interface{}'s horrible, which just returns to dynamic typing…

Yeah the whole javascript/DOM ecosystem is a very organically grown mess, typescript tries it’s best, but it is anything but clean, lol. ^.^;

Try Rust instead, it even has The Rust Book documentation/tutorial on how to learn/use the language. Rust makes very good use of types if you are wanting something on the level of Go (in entirely my opinion, there is absolutely never ever a reason to choose Go over Rust). Ocaml is a great language to learn for it’s strong types as well.

Anyway, back to the static typing. Yesterday I just wanted to consume a simple JSON API endpoint. Load the data, iterate over it, done. Nope. Parsing the JSON into map[string]interface{} works, but then you can’t use the data in any usable way. It contained an array of items. I just wanted to iterate over it, but Golang didn’t let me because it didn’t know there was an array. So I had to cover the whole JSON structure with structs to silence Golang.

Yup! Go’s language is a horrible mess. ^.^;

For several years, I worked with PHP without any typing system and never had any problems. Now I am using Elixir and with pattern matching, I don’t even see the need for a stricter typing system.

Did you know PHP has a built-in typing system now too? Lol.

2 Likes

I started reading it a while ago. But it is not as exciting as reading the Elixir guides a few years ago when I started with Elixir. But Rust is definitely something I would enjoy more than Go.

I know. I kinda dropped out of the PHP ecosystem some time after PHP 7 came out. I used the new typing system here and there but not with 100% coverage. I liked that it wasn’t forced on me and that I could decide where I want to use it or not.

1 Like