By: Frederik Banning
Re-posted from: https://forem.julialang.org/fbanning/julia-abm-3-what-a-difference-a-day-makes-2k1l
In the previous issue we have laid out the basic events that happen in our model – both as verbal descriptions in plain English and as algorithmic representations in simple Julia code. Sally and Richard are now not merely static pieces of data anymore but they can act in three different ways: work, eat, and trade.
However, today’s lesson content will be a bit more technical in nature and deal with how we work with Julia. So far we had just written out the pieces of our modelling code in long blocks of for-loops that stood on their own and weren’t really connected to each other. While it works great for simple examples, this will become increasingly harder to read. Furthermore, it is relatively complicated to reason about which pieces of our code belong to which category of actions. To take care of this, today we will primarily learn about two things:
- Writing our code in plain text files and including them in a running Julia REPL.
- Encapsulating our code in functions takes care of this and provides us with more options to easily structure our model code and even improve its performance.
So let us not hesitate any longer and start the refactoring.
Brief remark on future posts:
From now on, future issues in the Julia ❤️ ABM series will primarily be published on my personal blog and new issues will afterwards be announced here on Julia’s Forem instance. This allows me to avoid the extra formatting work required to publish on here while still retaining the ability to get in touch with the community, especially through the comment section. This approach also gives me full control over how these posts are styled and structured and in the long run it also feels nice from an self-hosting/archiving perspective. Thanks for your understanding and happy reading. 🙂