Stay Confident and DRY
Maintainable code requires that a developer to adhere to a number of principals that are often to difficult to employ at all times. Often times we are both learning a new domain, API, or language as well as trying to solve complex problems. The combination of the two often forces us to make to make poor design decisions.
The objective of the exercise is to make the sample code "better".
While you and your partner are the ultimate arbitrator of "better" there are some core tenets that are often supported by a large set of developers:
- Pass all tests
- Clear, expressive, and consistent
- Duplications no behavior or configuration
- Minimal Methods, Classes, and Modules
Understand the code.
Define the criteria that would make this code "better".
Implement a solution that employs the criteria you defined. The idea here is to generate a solution that you think is "better".
What did you decided would make the sample code better?
What things were easier to implement?
What things were harder to implement?
What, if anything, surprised you today?
What, if anything, will you do differently in the future?
Chapter 4 - Thursday: Class Definitions
Suggestions and tips on how to write code that makes a statement, not asking a bunch of questions.
This example provided with this exercise provides a simplistic solution.
Attempt a solution that employs a Domain Specific Language
Define a language for setting up the board and making moves
Attempt a solution that limits the use of "Primitives"
Primitives for the sake of this problem include:
Attempt a solution with Test Driven Development
Remember the goal is to write a test that fails and then write the simplest code that passes the test.
Attempt a solution that limits the use of branching logic
Removing as many
case whenfrom your implementation.
Attempt a solution that limits the use of "Primitives" and "Collections"
Primitives were defined above. Collections are objects and derivatives like