-
-
Notifications
You must be signed in to change notification settings - Fork 680
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
base: main
Are you sure you want to change the base?
Adding approach for Bob #2861
Conversation
3ddea06
to
e509381
Compare
if (isAsking(inputTrimmed)) | ||
return "Sure."; | ||
|
||
return "Whatever."; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
-
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 mainhey()
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.
- In the method-based approach, I’ve separated the logic for determining if the message is a question, shouting, or silent into individual methods (
-
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, andisAsking()
clarifies the question check. - This helps future readers (and even future maintainers) quickly grasp the purpose of each check.
- With the helper methods, it’s clear what each condition is doing without having to dive into complex inline
-
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.
-
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!
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. |
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