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*

6
  • Good answer. However, you wrote "Variant1 is not terrific." - why do you refer here only to Variant1? AFAIKS all four variants have the same contract issue. Commented Jan 8, 2024 at 20:53
  • 1
    @DocBrown Yeah. Guess I didn't want to keep flogging same horse as I continued to read the next three. I focused on the first because OP held it up as the gold standard, an improvement over the others, and I wanted to show that there's still room to improve. Commented Jan 8, 2024 at 21:04
  • Thank you for your comment, this is very helpful! They way I understand this, there are 2 main criticisms: 1. Going into pre- / post-conditions and invariants. Do I understand this correctly, that you would prefer more comments on the function input and output variables, for example acceptable ranges or the nature of variables like the units etc? 2. Better naming in a way that promotes more “natural” reading of the code, more like an English text, f.e.renaming the function title or using helper functions like isEligibleCustomer. Is that correct? Commented Jan 9, 2024 at 9:08
  • Also, comparing the 4 variants, I should have maybe mentioned that there is no documentation except for the code (not my choice), and no requirements document. Requirements are basically done "on the fly". While, as already mentioned, your criticism is very much valid, this question was supposed to be more about the style that you should choose generally (expressiveness vs. conciseness). Do you have any thoughts on that? Commented Jan 9, 2024 at 9:13
  • 1
    ... or this: if(lastLoginDay == lastDay - with an explaining variable leftRewardedDays = lastDay-lastLoginDay; the test If(leftRewardedDays<0) becomes self-explanatory. That should be the way to go to make the comments superfluous. Commented Jan 9, 2024 at 16:58