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.

Required fields*

4
  • 1
    +1 this also eliminates the potential risk of TOC/TOU issues. Commented Jul 27, 2023 at 16:37
  • @JimmyJames: yes, and did you notice, it also avoids the temporal coupling issue which the OPs question contains - most probably unintentional: calling customSortCountSortStepOnly after customSortReallyModifyArray will result in a stepcount of zero - so in their final example, the calling order needs to be switched to make the program work properly. Commented Jul 27, 2023 at 18:20
  • Good catch. I love this kind of refactoring for a lot of things. My only qualm around not returning anything on a mutable call is that it precludes method chaining. I can understand why it's good rule, though. I often find myself wishing 'void' methods would implicitly return 'this' in OO languages. Commented Jul 27, 2023 at 18:26
  • If a method returns this/self to support method chaining then it’s not really a return value. Commented Mar 20, 2024 at 8:28