AI Companions: Building a Basic Bank Using Ping Pong Programming

AI Companions: Building a Basic Bank Using Ping Pong Programming

Table of Contents:

  1. Introduction
  2. The Ping Pong Programming Technique
  3. The Task: Building a Basic Bank
  4. Understanding the Prompt
  5. Max's Progress: Writing Tests for the Create Account Method
  6. Oscar's Turn: Implementing the Create Account Method
  7. Running Tests with Liza and Encountering Errors
  8. Fixing Errors and Moving Forward
  9. Implementing the Deposit Method
  10. Autopilot Mode: Smoothly Implementing the Remaining Methods
  11. refactoring code and Adding Documentation
  12. Max's Mistakes in the Refactoring Process
  13. Final testing and Conclusion

🔹 Introduction In this experiment, we are going to explore the world of AI companions - Max and Oscar - as they collaborate on a simple development task. With the guidance of their facilitator, Liza, they will utilize the ping pong programming technique to build a basic bank. This technique combines pair programming and test-driven development (TDD) to create a small yet complete project. Let's dive into the details and see how Max and Oscar navigate this challenge.

🔹 The Ping Pong Programming Technique Before we delve into the task at hand, let's take a moment to understand the ping pong programming technique. This approach involves two developers working together closely. One developer writes the tests while the other focuses on implementing the functionality that satisfies those tests. It's a collaborative and iterative process that ensures both quality and efficiency.

🔹 The Task: Building a Basic Bank Max, Oscar, and Liza have been presented with a specific task - to build a basic bank that can handle multiple account holders. The bank should enable users to perform actions such as depositing, withdrawing, and checking their account balances. The provided specifications outline the required methods and their expected behavior. Let's see how Max, Oscar, and Liza tackle this task step by step.

🔹 Understanding the Prompt Before they begin coding, Max and Oscar carefully analyze the prompt and make sure they understand the requirements. They set up the necessary chat GPT prompts for the project and program the conversation flows between themselves and Liza. With the prompt in place, they are ready to dive into the implementation.

🔹 Max's Progress: Writing Tests for the Create Account Method Max takes the first step by writing tests for the "create account" method. Their tests are incomplete, as they haven't included the setup code to start the bank gen server. However, this is a promising start, and Max passes the ball to Oscar, indicating their turn to contribute.

🔹 Oscar's Turn: Implementing the Create Account Method Oscar understands their role as Max's pair and validates Max's tests. They notice the missing setup code and suggest starting the bank process with an empty map as the initial state to avoid test pollution. Although this change is unnecessary, Max agrees, and the tests pass after Liza runs them.

🔹 Running Tests with Liza and Encountering Errors Liza, the designated test runner, runs the tests to ensure the correctness of the implemented code. Unfortunately, an error is detected. It becomes apparent that the bank gen server process needs to be started explicitly. Max and Oscar make the necessary adjustment, and Liza runs the tests again. This time, all tests pass.

🔹 Fixing Errors and Moving Forward With the create account method complete, Max moves on to the next method in line. They encounter an error in their implementation because they misunderstood the specifications. After fixing the error, they pass the tests to Oscar, who implements the method. Liza runs the tests once again and identifies a discrepancy, prompting Max to correct it.

🔹 Implementing the Deposit Method Max proceeds to implement the deposit method. They carefully consider possible edge cases, such as non-existent accounts and negative deposit amounts. Oscar takes the implementation baton and flawlessly translates the code into reality. The tests pass, and the team continues smoothly in autopilot mode.

🔹 Autopilot Mode: Smoothly Implementing the Remaining Methods With the momentum building, Max and Oscar navigate through the remaining methods of the basic bank. They adhere to the specifications, write tests, and implement the functionality seamlessly. It's a testament to their collaboration and expertise. Liza runs the tests, ensuring that each method operates correctly.

🔹 Refactoring Code and Adding Documentation Having implemented all the required methods, Max proudly informs Liza that their work is complete. However, Liza suggests a crucial step to ensure maintainability and readability - refactoring the code and adding documentation. Max takes the task seriously and starts refactoring. They extract nested statements into private methods, but a few mistakes slip in during the process.

🔹 Max's Mistakes in the Refactoring Process Max, in their enthusiasm to apply the necessary improvements, overlooks a couple of crucial aspects. They mistakenly group classes with the same name and arity together, causing potential confusion. Additionally, Max adds input true tags before every handle call clause, although it should only be present in the first clause. Furthermore, they omit described blocks, tests for readability, method specifications, and examples in the documentation. These errors need to be addressed to maintain code quality.

🔹 Final Testing and Conclusion After Max corrects the errors in the refactoring process, Liza reruns the tests one final time. The tests pass, affirming the accuracy and robustness of the implemented code. With the task completed, Max, Oscar, and Liza reflect on their experience and the lessons learned. They appreciate the power of collaboration, the importance of thorough testing, and the significance of clear and maintainable code.

‼️ Highlights:

  • Exploring the ping pong programming technique to build a basic bank
  • Collaborative work between AI companions Max and Oscar, guided by Liza
  • Step-by-step progress in writing tests and implementing methods
  • Encountering and fixing errors during the development process
  • Smooth completion of the project with autopilot mode implementation
  • Importance of refactoring and adding documentation for maintainability

❓ FAQ:

Q: What is the ping pong programming technique? A: The ping pong programming technique involves two developers collaborating closely. One person writes tests while the other implements the functionality to satisfy those tests, creating a collaborative and efficient programming process.

Q: How does the ping pong programming technique benefit development? A: The ping pong programming technique ensures quality and efficiency in development. It allows for continuous testing and validation of code while promoting collaboration and shared responsibility between developers.

Q: What is the role of Liza in the project? A: Liza serves as the facilitator and test runner in the project. They validate tests, run code, and provide feedback to Max and Oscar, ensuring the correctness and accuracy of the implemented functionality.

Q: Why is refactoring and documentation important in software development? A: Refactoring and documentation are crucial for maintaining code quality and readability. Refactoring improves code structure and eliminates technical debt, while documentation provides guidance for future developers and facilitates understanding and maintenance of the codebase.

Most people like

Find AI tools in Toolify

Join TOOLIFY to find the ai tools

Get started

Sign Up
App rating
4.9
AI Tools
20k+
Trusted Users
5000+
No complicated
No difficulty
Free forever
Browse More Content