Methods candidate for the use of const. (Requests/Action Idea 🔏)

Off all the functions we’ve written so far, I believe that all the functions that request (return) an information but don’t explicitly state that that information is being changed should be marked as const, while functions that seem to indicate that an action is going to be performed in the method should not be marked as such, as member variables can possibly be changed during its execution.

This includes both of our GETters, GetCurrentTry() and GetMaxTries(), because we’re explicitly saying in our method name that we’re only returning information and not modifying it.

Same wise, IsGameWon() should be marked as const as well. While it doesn’t specifically say it’s GETing something, the method name still states that a request is being replied too (we’re asking the function if the game has been won and returning that information). It also doesn’t state that an action is being performed in that method. We’re only returning a boolean, not changing it.

Reset() is a different story, as we’re explicitly saying that we’ll be performing an action in that method, and therefore, there’s a high probability that we will be changing member values while we’re at it.

CheckGuessValidity() however, could both be const or not depending on how we decide to implement it. Since the function name starts with Check, I’d consider that it is performing an action in that method, and therefore, shouldn’t be marked as const. However, in case we confirm that it indeed doesn’t change any member variables, then we should mark is as const.

Privacy & Terms