r/functionalprogramming • • Aug 28 '24

Question Thoughts on The Composable Archiecture (TCA) in Swift?

I have some academic experience in functional programming, and over my last 25 years mostly worked with OOP and at a higher abstraction level, component-based software development.

A recent experience with TCA using Swift still has me wanting to learn more. Most of my experience is in lower-level C++ code. Chromium's browser application process is the best example that is open source and people might recognize.

First, as TCA scales up (it seems fine for ToDo-like simple apps), it seems to lead to massively complicated switch statements that remind me of WNDPROC callbacks in Win32, but with a bonus of pattern matching and better params than WPARAM/LPARAM in Win32.

For an app I was working on, a switch statement for a reducer was thousands of lines long. Call stacks for a crash, hang, or performance analysis were often 200-300 levels deep with just Reduce|Reduce|Reduce, and so on. In the C++/OOP world I'm used to seeing a lot less except in pathological situations, and the stack is meaningful and leads to quick triage and diagnosis. With so many levels of just reducers and complex switch statements, for post-mortem debugging I mostly have to rely on logs.

When profiling, I worry about the state being copied a lot by value, though Swift is supposed to optimize this away?

The people I worked with worshipped TCA and I'd like to better understand why. It's certainly a different way of thinking IMHO. I've seen many of the PointFree videos but I guess I just don't get it. Maybe I'm just set in my ways?

13 Upvotes

11 comments sorted by

View all comments

Show parent comment

4

u/Rollos Aug 28 '24

I think another point in its column that you somewhat touched on is the access to the thought process of the maintainers.

The repository of episodes going over almost every design decisison and implementation detail of the framework, starting from first principals, lets developers that want to use it gain a really in depth understanding of the tool and how to use it.

The episodes are interesting, not only going over what they’re building and why, but each episode has lessons and teachable moments that build your skills as a developer.

From a FP front, they actually don’t call it a functional programming framework. It does a bunch of things that aren’t technically FP, like allowing for reference types in the state, and dependency injection. Their goal is to try to take the best benefits of FP concepts, like composition, separating side effects, modeling your domain using value types allowing for exhaustive testing, etc.

But, they aren’t sticking to strict Functional Programming at a dogmatic level, instead, picking and choosing what suits the purpose, which is a framework for solving common problems of building applications.

2

u/GoldenShackles Aug 29 '24

Thanks. I sent a PM

1

u/vanisher_1 Nov 12 '24

Why pm? 🤔