Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • if (somecondition == true) Commented Sep 28, 2016 at 9:12
  • 1
    The gain in breaking would be that if the function ever changes in a way that makes it impossible to return directly from within the case statements, there is less refactoring, making it less likely to introduce new bugs in the future. Commented Sep 28, 2016 at 9:17
  • Then you are breaking YAGNI. Until a need arises, do not overengineer the code, unless you are absolutely, 100% certain that the code will change in the proximate future. Commented Sep 28, 2016 at 9:50
  • 1
    @5gon12eder I can understand adding == false, because it might make the code more readable, e.g. if (!somecondition) as opposed to if (somecondition == false). However, adding == true to the condition makes the code more cluttered to me, so personally I avoid doing that. Commented Sep 28, 2016 at 9:59
  • 1
    @VladimirStokic I wish there was a principle for not trying to shoehorn every damn principle in every project. Adhering to things like DRY, KISS, YAGNI, etc can have great advantages, but they aren't 100% universal and should definitely not be the baseline for all code in all projects. Commented Sep 28, 2016 at 10:32