News for hackers. Stuff that matters.
Re:Functorio by munchbunny on Tuesday February 16, 2021 @03:44PM (#26158581)
I can definitely see the point the author is trying to make, and I agree that it naturally lends itself to a functional model of how the game works.

On the other hand, and this is speaking as someone who has played the game for an embarrassing number of hours all the way into endgame "megabase" territory: my mental abstraction of the game isn't really functional. It's directed graphs. Sure, the two views can be equivalent representations, but I find thinking about the game as a directed graph (and reasoning about throughputs in a graph representing a network) to be the perspective that gives actionable insights most readily.

Re:Functorio by m_mueller on Tuesday February 16, 2021 @09:18PM (#26161821)
It also seems to me that the author is conveniently ignoring the mechanics that aren’t mapping well to FP. To me, belts and buffer chests are much easier to describe as a mutable data structure (FIFO queues). That’s also analogous to how real world applications typically look like: functional core / imperative shell (see also Gary Bernhard’s brilliant ’Boundaries’ talk). It’s a nice article to introduce FP but I get immediately suspicious about statements like ‘Engineering is FP’. FP is a tool, not a unified theory on how to model the world.
Re:Functorio by lmm on Tuesday February 16, 2021 @10:48PM (#26162408)
FP is a unified theory on how to model the world: as functions, where equivalent inputs will always produce equivalent outputs. If there's something that makes outputs inequivalent, you should (under this theory) represent that with a corresponding input.

It's not the only possible way to model the world, but it absolutely is a unified approach that you can apply to a whole system, and it tends to work better when you do - trying to apply "FP as a tool" within a fundamentally mutation-oriented system (for example) gets you a very limited subset of the benefits, IME.

Re:Functorio by m_mueller on Wednesday February 17, 2021 @02:51AM (#26163807)
Real world is dirty. It needs logging, I/O, etc. Yes you can model those with monads in Haskell, but what happens much more frequently is that you’re in a team of Java/Python/Js/C++ programmers and you want to profit from some of the benefits of FP at least (testability, composeability). And that is where the perfect becomes the enemy of the better if you then just give up because you can’t get your single paradigm FP language. As a modeling tool however it is still very powerful, as are some aspects of OOP.
Re:Functorio by haet on Wednesday February 17, 2021 @10:27AM (#26167366)
What does a functional Python look like?

To me, a functional language without tail recursion seems pointless. Is it possible to abstract away whether you are recursive or iterative, like an iterative recursion scheme?

One thing that I think would be great is if there was a Python approach to effects systems like Polysemy (free monads); what might an in between be for this?

Re:Functorio by m_mueller on Wednesday February 17, 2021 @12:43PM (#26169125)
I don't think Python's type system is capable enough (yet) for something like this. However tail recursion optimization to me is a non issue - for something expensive and deeply nested I use an iterative approach, and for everything else python's recursion is good enough. There are not that many usecases like this per code base anyways, in my experience. In my current one there is one central facility to do object loading based on yaml definitions, that's the one place I need it there for example.
Re:Functorio by lmm on Wednesday February 17, 2021 @10:33PM (#26175317)
> To me, a functional language without tail recursion seems pointless.

Tail recursion is a low-level detail IMO. Scala does fine without it.

Re:Functorio by Qem on Thursday February 18, 2021 @10:28AM (#26180892)
Re:Functorio by lmm on Wednesday February 17, 2021 @02:59AM (#26163854)
In my experience a codebase that crisscrosses back and forth between FP and mutation-based style ends up worse and buggier than one that commits fully to one or the other; it's not perfect being the enemy of better because it's not better.
Re:Functorio by rkangel on Wednesday February 17, 2021 @07:38AM (#26165686)
Criscrossing backwards and forwards would be bad, but the 'functional core, imperative shell' does work well. It is an excellent fit for Erlang/Elixir - you write a lot of pure functional logic (with the equivalently easy tests), and then you 'glue' it to the outside world with as little process machinery and statefulness as possible.

We are in Erlang though, so I wouldn't call it 'mutation' necessarily. The stateful bits are individual actors, creating a new internal state in response to messages.

Re:Functorio by m_mueller on Wednesday February 17, 2021 @03:15AM (#26163944)
I think it needs to be thought of as part of an overarching design - again, see Gary Bernhardt. A pure functional core that can be unit tested against, where the tricky logic happens. And a shell where you deal with dirty but dumb things like thread pools, logging, error handling, non-pure libraries etc. And then just be very diligent to separate concerns, i.e. don't put too many smart things into the shell.
Re:Functorio by lmm on Wednesday February 17, 2021 @10:31PM (#26175294)
> I think it needs to be thought of as part of an overarching design

Right. Which is very much opposed to your initial "FP is a tool, not a unified theory on how to model the world".

Re:Functorio by m_mueller on Thursday February 18, 2021 @02:06AM (#26176878)
I don’t think it is? I don’t see the contradiction. My point is FP, imperative and OOP can be combined effectively in one architecture.
Re:Functorio by lmm on Sunday February 21, 2021 @04:14AM (#26212063)
They can be, but you need to adopt a particular global perspective/worldview to make it work. Treating FP as just a tool in the toolbox that you can use ad-hoc anywhere in the codebase is not effective.
Re:Functorio by travv0 on Wednesday February 17, 2021 @09:43AM (#26166775)
"Functional core, imperative shell" is exactly what IO in the Haskell type system enforces.
Re:Functorio by munchbunny on Wednesday February 17, 2021 @02:50AM (#26163798)
I think the core of the issue is that, while you can take a FP based view on how Factorio works, typically the interesting problems to model in Factorio aren't really "FP" problems. They're not really "imperative" problems either. Really, I don't think they're programming problems, even if they kind of look like programming problems.
Re:Functorio by herodoturtle on Wednesday February 17, 2021 @10:22AM (#26167296)
> speaking as someone who has played the game for an embarrassing number of hours

I enjoyed reading that line - made me chuckle :) Would you mind sharing what it is that keeps bringing you back to play?

I'm a grey beard programmer, husband, father, and vanilla Linux kinda guy - and I've seen Factorio being mentioned on this forum quite a bit over the years. The chatter here today has once again piqued my interest to say the least.

I was once an avid gamer in my youth, but these days I have little free time - so if I were to pick up a game, it would have to be the sort of experience that I can play for a few minutes here and there (and / or immerse myself in for several hours at a time when the opportunity arises). It would also need to run smoothly on Linux, and be relatively easy on computing resources.

I tried Minecraft for a bit - and it ticked most of the above boxes - but I didn't much enjoy the interface and lack of "systems" if that makes sense. I love building things, but I also just enjoy sitting back and watching systems work. I prefer top-down planning / building games like the Sim City of old but that got boring pretty quickly.

Anyhow I think I oughta just install Factorio and check it out - but I'm deeply curious what it is that keeps bringing you back for more.

Re:Functorio by munchbunny on Wednesday February 17, 2021 @03:53PM (#26171613)
> Anyhow I think I oughta just install Factorio and check it out - but I'm deeply curious what it is that keeps bringing you back for more.

There's a demo version which gives you a pretty good idea of how Factorio feels. I forget whether the demo runs on Linux, but the full game is straightforward to run on Linux, by which I mean I forget whether you need an emulation layer.

> Would you mind sharing what it is that keeps bringing you back to play?

To be fair, I did reach the "I'm done with Factorio" point. I have one last hurrah of getting one last accomplishment in progress, and then I'm realistically done with the game.

But to answer your question: it's because Factorio's systems are extremely deep, where the nature of the puzzles and the way you think about them keep evolving. And as you solve those problems you get the satisfaction of seeing those systems working. It's the same high I get from seeing my code work, but in video game form.

> it would have to be the sort of experience that I can play for a few minutes here and there (and / or immerse myself in for several hours at a time when the opportunity arises).

Factorio isn't the type of game you can play for a few minutes at a time. For me, Factorio relies on the same kind of flow state I use for other focused work. So I play it when I opportunistically have long blocks of time. Most of my hours put into Factorio were from earlier years of my life when I had fewer responsibilities and obligations.

Re:Functorio by shakow on Wednesday February 17, 2021 @12:55PM (#26169313)
> I love building things

> I tried Minecraft [...] but I didn't much enjoy the [...] lack of "systems"

> I also just enjoy sitting back and watching systems work

> I prefer top-down planning

Yeah, you should love Factorio!

Re:Functorio by willis936 on Tuesday February 16, 2021 @03:53PM (#26158684)
Because factorio is much closer to a gui-based HDL layout tool than a programming language. It might be fun to program a simulated annealer to play factorio.
Re:Functorio by buildbot on Tuesday February 16, 2021 @06:11PM (#26160024)
That sounds like an awesome project for a graduate EE design class!
Re:Functorio by mhh__ on Tuesday February 16, 2021 @07:13PM (#26160738)
One of the HDL-to-Minecraft(Redstone) projects was done by undergraduates - from scratch even!

These kinds of projects are one of the only things I get FOMO over studying physics - I really like the idea of getting a few months to (say) write a compiler as a group rather than piles of utterly inane lab work teaching me how to use equipment I already know how to use

Re:Functorio by zygomega on Tuesday February 16, 2021 @05:17PM (#26159454)
I often think about functional programming as a directed graph consuming information.
Re:Functorio by LesZedCB on Tuesday February 16, 2021 @11:18PM (#26162640)
i honestly don't know of another way to think about it.

it's literally arrows

Re:Functorio by beaconstudios on Tuesday February 16, 2021 @07:35PM (#26161001)
it's essentially the same as Reactive Streams (http://reactivex.io/) - the best known instance being RxJS.
Re:Functorio by dexwiz on Tuesday February 16, 2021 @04:19PM (#26158919)
The author is one of the main sources of Category Theory for Programmers material. Take that as you will.
Re:Functorio by munchbunny on Tuesday February 16, 2021 @04:44PM (#26159172)
> The author is one of the main sources of Category Theory for Programmers material. Take that as you will.

I'm having some trouble coming up with plausible inferences from that fact. Do you mean to imply that "when you have a hammer everything looks like a nail"?

Re:Functorio by dexwiz on Tuesday February 16, 2021 @05:22PM (#26159503)
That, or this article is an attempt to explain the author's speciality using a concrete example.
Re:Functorio by swagonomixxx on Tuesday February 16, 2021 @05:54PM (#26159837)
Pretty much. Bartosz's posts are pretty much exclusively about the superiority of Haskell and functional programming, with occasional forays into C++ to explain a functional concept in a more familiar syntax.
Re:Functorio by ksm1717 on Tuesday February 16, 2021 @05:15PM (#26159444)
Maybe more like: “the best hammers can treat anything as a nail”
Re:Functorio by steerablesafe on Wednesday February 17, 2021 @06:37AM (#26165280)
Including thumbs.
Re:Functorio by AnHonestComment on Tuesday February 16, 2021 @05:19PM (#26159468)
The realization at the end of your post is what the author is trying to get people to reach about software.

The category theory for programmers crowd argue that categorical diagrams (annotated graphs) are the right way to reason about software to gain insights — and the rest is describing the equivalence between functions in a type theory and maps in a category.

Your mental model of directed graphs is a functional model.

Re:Functorio by munchbunny on Wednesday February 17, 2021 @02:07AM (#26163574)
Your mental model of directed graphs is a functional model.

In the more general sense that may be true, but I was talking about Factorio specifically, where I'm using the graph representation to do the analysis.

Or rather, just because a functional interpretation exists doesn't mean I actually reach for the toolkit filed in my memory in the box labeled "functional stuff". In practice I mostly reach for the boxes I've filed away under "linear algebra", "graph theory", and "circuit design", which aren't things I typically reach for when I'm actually doing functional programming.

Re:Functorio by kortex on Tuesday February 16, 2021 @07:45PM (#26161078)
Well, this article helped me understand monads better than any of the other articles (though they provide important pretext).
Re:Functorio by dnautics on Tuesday February 16, 2021 @07:11PM (#26160723)
if you don't mind going impure, you could translate those functions into actors and (easily) test their resiliency against alien attack using a virtual machine like the BEAM.