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

Adding approach for Bob #2861

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open

Conversation

jagdish-15
Copy link
Contributor

pull request

This pull request adds an approach to the Bob exercise.

I was unsure how to generate a uuid for the approach, so I've left it empty. I would greatly appreciate guidance on how to generate one.


Reviewer Resources:

Track Policies

if (isAsking(inputTrimmed))
return "Sure.";

return "Whatever.";
Copy link
Member

Choose a reason for hiding this comment

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

To be honest, I think this approach is the same as the existing if-statement approach. The only difference is that the conditions are in methods instead of variables. Is there something else that differentiates this approach from the other ones?

Copy link
Contributor Author

@jagdish-15 jagdish-15 Nov 15, 2024

Choose a reason for hiding this comment

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

Thanks @kahgoh for your feedback! I understand your point, and while both the method-based approach and the if statement approach use condition checks, there are a few key differences that I think set the method-based approach apart:

  1. Separation of Concerns:

    • In the method-based approach, I’ve separated the logic for determining if the message is a question, shouting, or silent into individual methods (isYelling(), isAsking(), isSilent()). This makes the main hey() method cleaner and focused on handling the flow of responses.
    • In the if approach, the logic is directly embedded in the main method, which could become harder to read and maintain as more checks are added.
  2. Improved Readability:

    • With the helper methods, it’s clear what each condition is doing without having to dive into complex inline if statements. For example, isYelling() immediately tells you that it’s checking for shouting behaviour, and isAsking() clarifies the question check.
    • This helps future readers (and even future maintainers) quickly grasp the purpose of each check.
  3. Maintainability:

    • While maintainability may not be a major concern for these one-time exercises, the method-based approach provides a structure that makes it easier to modify individual checks without cluttering the main method. This is generally a good practice for ensuring clean, readable, and maintainable code, even in simple exercises.
  4. Scalability:

    • While this specific exercise may not need to scale in the future, separating the logic into individual methods makes it much easier to extend or modify if more conditions are added down the line. Even though we don’t expect more checks here, structuring code this way is generally a good practice for scalability in larger, more complex applications.

In summary, while both approaches work, the method-based approach tends to be cleaner, more modular, and easier to extend. It may seem similar on the surface, but the structure I’ve chosen is designed with maintainability and scalability in mind, which are good practices even for small exercises like this one.

If you have any suggestions or further insights on this approach, I'd be happy to hear them!

@jagdish-15
Copy link
Contributor Author

I've updated this approach to incorporate all the suggestions from the PR for the Queen Attack exercise here. This update ensures consistency in style with the other exercises' approaches. Additionally, the newly added approach's content.md file is now aligned with the format and structure of the two existing approaches.

Please review and let me know your thoughts on this version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants