Continuations: What Have They Ever Done for Us? (Experience Report)

Marc Kaufmann,Bogdan Popa
DOI: https://doi.org/10.1145/3677998.3678223
2024-08-30
Abstract:Surveys and experiments in economics involve stateful interactions: participants receive different messages based on earlier answers, choices, and performance, or trade across many rounds with other participants. In the design of Congame, a platform for running such economic studies, we decided to use delimited continuations to manage the common flow of participants through a study. Here we report on the positives of this approach, as well as some challenges of using continuations, such as persisting data across requests, working with dynamic variables, avoiding memory leaks, and the difficulty of debugging continuations.
Software Engineering
What problem does this paper attempt to address?
The problem that this paper attempts to solve is how to effectively manage and handle the states of participants during the research process when designing and implementing platforms (such as Congame) for economic experiments. Specifically: 1. **State Management**: Economic experiments usually involve stateful interactions. For example, participants receive different messages according to their earlier answers, choices or performances, or interact with other participants in multi - round transactions. These interactions require complex logic to track and manage the state of each participant. 2. **Simplifying the Programming Model**: The traditional Web programming model is very complex when dealing with such stateful interactions, especially when multiple steps and conditional branches are involved. The author hopes that by using **delimited continuations**, this complexity can be simplified, making it more straightforward and natural to write such applications. 3. **Improving Code Reusability and Flexibility**: By using delimited continuations, researchers can combine and reuse experimental modules more conveniently, thereby improving development efficiency and code quality. 4. **Avoiding the Defects of Custom - made State Management Systems**: Many existing platforms (such as oTree) rely on manual state management, which is prone to errors and difficult to maintain. Congame aims to reduce these problems through automated state management. ### Specific Contributions of the Paper - **Simplifying State Management**: Congame automatically tracks and manages the states of participants, so that research designers do not need to implement complex and error - prone state management systems by themselves. - **Natural Programming Style**: By using delimited continuations, Congame allows surveys to be written in a declarative way, and the next operation of participants can be determined at each step without concerning about the underlying Web programming details. - **Flexibility and Extensibility**: The design of Congame is very flexible. It supports the dynamic generation of research and can easily add new features (such as static page processing) without making major modifications to the core framework. ### Challenges Encountered - **Parameter Management Problem**: The interaction between delimited continuations and dynamic variables sometimes leads to unexpected behaviors, such as the loss of parameter values or excessive restoration. - **Difficulties in Debugging**: Especially when problems such as memory leaks are encountered, debugging becomes very complicated. For example, composable continuations may magnify other small errors, leading to serious performance problems. In general, this paper shows how to use delimited continuations to simplify the development of stateful Web applications and discusses the advantages and challenges of this method.