Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce code-duplication and make sure no duplicated code is written #320

Open
Zomis opened this issue Oct 27, 2022 · 4 comments
Open

Reduce code-duplication and make sure no duplicated code is written #320

Zomis opened this issue Oct 27, 2022 · 4 comments
Assignees
Labels
refactor Improvements to the code quality, not directly to existing functionality

Comments

@Zomis
Copy link
Owner

Zomis commented Oct 27, 2022

Somehow I can't help but get the feeling that some features are re-invented multiple times.

I think this is because of the different approaches the project has been through:

  • Action-based
  • Gameflow
  • Context
  • (Started) Entity-Component-System

This in addition to everything related, such as:

  • Actions (and now also SmartActions), choices, recursive actions, and lots of other things
  • Event handling

More effort needs to be taken to remove old code. The question then being of course: Which approach is the right one?

Could maybe ArchUnit https://www.archunit.org/use-cases help out with structuring the project better to remove duplicates and make code easier to find?

@Zomis Zomis added the refactor Improvements to the code quality, not directly to existing functionality label Oct 27, 2022
@Zomis
Copy link
Owner Author

Zomis commented Oct 27, 2022

This is kinda like https://xkcd.com/927/ but within the same project.

@Zomis Zomis self-assigned this Oct 30, 2022
@Zomis
Copy link
Owner Author

Zomis commented Oct 30, 2022

I had an idea to make all scope-interfaces inherit from some basic Scope marker interfaces:

  • PrimitiveScope (contains one single val or fun)
  • CompoundScope (inherits from multiple PrimitiveScopes, meant to be re-used)
  • UsageScope (for one specific use-case, typically inherits from a single CompoundScope and/or multiple PrimitiveScopes)

All these three inherit from a common Scope interface.

This can also then be asserted using ArchUnit. So far I don't regret this approach.

ArchUnit proves to be very very useful, with rules like:

  • All classes annotated with @GameMarker should be named *Scope
  • All classes named *Scope should be assignable to Scope
  • All classes named *Context should not be interfaces

@Zomis
Copy link
Owner Author

Zomis commented Nov 24, 2022

A sign of code duplication: I have three different games using some kind of event/trigger-system (Coup, Dungeon Mayhem, and one more which is not yet finished). I have three different implementations of an event/trigger system to be used in games.

@Zomis
Copy link
Owner Author

Zomis commented Dec 11, 2022

Some known sources of duplicated code:

  • TestPlays.kt / TestDsl.kt / TestImpl.kt / TestPlaySteps.kt -- these should be rewritten to use GameListeners. See also Make it easier to Test games #102
  • GameImpl vs. GameFlowImpl
  • Old Actions vs. New Actions (especially SmartActions)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactor Improvements to the code quality, not directly to existing functionality
Projects
None yet
Development

No branches or pull requests

1 participant