

Many times I have seen a project derailed by the programmers not considering throughput, and only understanding it is not high enough when it was too late. which queue is used to provide input to a process and ignore the rest. How do you represent a conditional structure like IF or CASE in a dataflow language like Erlang? You define receiving functions with pattern matching and/or select which stream of data i.e. Pick up resources, but only when the number of resources is smaller than X. Pick up multiple resources at the same time. Why are those interesting? Conditionals! Conditionally pick up this type of resource, but not that type. One more thing important thing you can see in the images are the inserters, the robotic arms which pick up the resources from belts to place them into assemblers. Inserters - Selectors of the data to be input into functions It is no accident that creators of functional languages use factory analogies. It is no accident that we live in the times of "reactive" programming, micro-service architectures, functional programming. The whole infrastructure of a computer program is created from actors/processes/functions working with data and queues moving data between them. The whole infrastructure of the factory is created from assemblers working with resources and belts moving resources between them. One assembler will harvest the raw resources and push them onto belts, then another assembler will take these resources and produce something out of them. This is also analogous to pattern matching in Erlang.īelts are queues with resources and data. Assemblers also can only work when the inputs are of correct type, otherwise they get stuck. This makes it very easy to understand what each assembler / process does, because it has a single logical responsibility to transform inputs into outputs, whenever inputs are provided. They do it continuously, whenever there are resources / data present at the input. The assemblers / functions start to assemble their resources / data the moment resources are available at the input inbox. These functions take the data provided by-value at their inputs inbox and transform this data into some new piece of data, sent further by-value as result. You can then recursively invoke the function to receive messages and process them accordingly. In languages like Erlang starting a function as a parallel process is cheap, and each one gets an inbox queue to which messages can be sent. This is directly analogous to parallel processes/actors receiving and acting on messages. For processing raw resources furnaces can be used. These things can be assembled either manually, or a machine called an assembler can be used to do it automatically instead of the player. These can be something like iron plates and wires producing something like basic integrated circuits. Assemblers - Pure functions or processes? Both.Įverything in Factorio has to be assembled or processed from simpler components or raw resources. There are many valuable analogies and parallels.

Now you might ask, what does it have to do with programming? Everything! Even better, it has a lot to do with functional programming and dataflow! You need to continuously assemble more complex components, until you finally get to the most complex component - the spaceship.

How can you do that? You have to build and automate a gigantic factory, which will turn raw resources like coal, iron, copper, oil and uranium into more and more complex products. How can you do that? You have to build every single part and component to build the spaceship. You have to survive the alien attacks, build a spaceship and get off the planet. You land on an alien planet without anything but the basic tools at your disposal. If you have not played Factorio, let me give you a quick introduction. Can factory automation games make us better programmers?
