4 ms·
The goal is that everything in the core is pure data types and functions. Now, depending on your problem domain, your core can be small or huge compared to the
by pwm 8y ago
The goal is that everything in the core is pure data types and functions. Now, depending on your problem domain, your core can be small or huge compared to the shell. Your question was all about IO/effects. They are impure and belong to the shell. If what you work on does mostly IO then you will have a lot of impure code lying around by definition. Still, the idea is that you should keep the amount of time spent in impure land minimal, ie. drop into pure structures/computation as soon as possible during program execution and only dip out of on occasions when you have to do IO.
Here is a good talk about these ideas: https://www.youtube.com/watch?v=US8QG9I1XW0 https://www.youtube.com/watch?v=US8QG9I1XW0
- lackbeard 8y agoI guess what I'm getting at is that in any non-trivial program with many external dependencies and cross-cutting concerns, almost all of your code is the "shell", so either I'm missing something, or this is stating the obvious (write pure functions where you can) in a very roundabout way. I've never seen a program written explicitly in this style that wasn't a trivial example.
- ramchip 8y agoThe functional core can return a symbolic description of actions to take, which the shell executes, a bit like a simple interpreter. This is a good example: https://www.theerlangelist.com/article/spawn_or_not https://www.theerlangelist.com/article/spawn_or_not (Note the context is Elixir, so it’s talking about lightweight processes, not OS processes. It explains how to keep that stateful / effectful code very simple, and have all the real logic be pure functional code.)
- yen223 8y agoI think it's more that a lot of programs aren't actually doing anything terribly complex, logic-wise. A lot of apps out there do nothing more than fetching data from one service, and dumping it out to another.
- pwm 8y agoThe system I've been working on in the past 6 months is non-trivial and written in this style. Roughly 2/3 of the code is in core and 1/3 is in shell.