Skip to content

Introduce hardcore parameter#30

Merged
DanielAnderson merged 5 commits intomainfrom
hardcore-4
Apr 24, 2025
Merged

Introduce hardcore parameter#30
DanielAnderson merged 5 commits intomainfrom
hardcore-4

Conversation

@DanielAnderson
Copy link
Copy Markdown
Collaborator

@DanielAnderson DanielAnderson commented Apr 24, 2025

💸 TL;DR

Parameterize all the things using "mode" - defaulted to regular. Will be fixing each of those in the future.

Also fix issues with playtesting.

@DanielAnderson DanielAnderson marked this pull request as ready for review April 24, 2025 16:41
this.#redis = redis;
this.#challengeToWordService = new ChallengeToWordService(redis);
this.#challengeToPostService = new ChallengeToPostService(redis);
this.#mode = mode;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: It feels odd for the service to be instantiated to only handle one mode type. I would have imagined the mode would be passed into the method calls.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree - though perhaps the word "service" here muddles things - I don't think it's a particularly good name tbh. Maybe ChallengeManager, WordListManager etc better conveys the purpose of these classes? Happy to change them if you think that's better.

Generally I expect the pattern to be something like this:

Devvit.addTrigger(
  {
    // Get the mode in whatever way
    mode = getMode()

    myService = new ChallengeService(redis, mode);

    // do a bunch of things with the service.
  }
)

Further, most (but not all) of the time, a post only exists with the context of one GameMode - making that a parameter implies that it might change, when in practice one instance will only ever deal with one mode.

Copy link
Copy Markdown
Collaborator

@cytommi cytommi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking suggestions

Comment on lines +35 to +36
private redis: RedisClient,
private mode: Mode
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: prefer using # prefix for private properties. Also suggest prefixing with readonly keyword if we don't anticipate modifications to the property

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack - this was already discussed the prior PR. You can't do that with shorthand constructors.

#mode: Mode;

constructor(redis: RedisClient) {
constructor(redis: RedisClient, mode: Mode) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: could default mode to regular mode by using a default value

Suggested change
constructor(redis: RedisClient, mode: Mode) {
constructor(redis: RedisClient, mode: Mode = 'regular') {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think doing this is extremely error prone and I want to explain why:

Every time ChallengeService is used - it needs to know whether it's in the context of regular or hardcore, and if that's ever determined incorrectly, it will result in bugs. Making this default to "regular" has the slight advantage of making it so this particular PR can be a little smaller - I won't need to update every instantiation. However - every instantiation does need to be updated before we ship - each and every one needs to do something to determine whether it's in the context of hardcore or in the context of regular - and changing them all now forces me to add TODO's for each of them to burn down in the future. I didn't want to do that in this PR because that's a harder thing to do (as each instantiation will need to be handled slightly differently) - but I really don't want mode to have a default long term so adding it in the immediate term doesn't seem like the right idea.

@DanielAnderson DanielAnderson merged commit 78f8a77 into main Apr 24, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants