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*

8
  • 6
    This. (Upvoted comments above that were similar re: readability). 30 years ago, when we were working with machines that had less than 1mb of RAM, squeezing performance was necessary - just like the y2k problem, get a few hundred thousand records that each have a few bytes of memory being wasted due to unused vars and references, etc and it adds up quick when you only have 256k of RAM. Now that we are dealing with machines that have multiple gigabytes of RAM, saving even a few MB of RAM use vs readability and maintainability of code isn't a good trade. Commented Sep 5, 2018 at 13:19
  • @ivanivan: I don't think the "y2k problem" was really about memory. From a data-entry standpoint, entering two digits is more efficient than entering four, and keeping things as entered is easier than converting them to some other form. Commented Sep 5, 2018 at 16:13
  • 10
    Now you have to trace through 2 functions to see what's happening. You can't take it at face value, because you can't tell from the name whether these are inclusive or exclusive bounds. And if you add that information, the name of the function is longer than the code to express it. Commented Sep 5, 2018 at 16:27
  • 1
    Optimise readability and make small, easy-to-reason functions – sure, agree. But I strongly disagree that renaming a and b to number1 and number2 aids readability in any way. Also your naming of the functions is inconsistent: why does IsSumInRange hard-code the range if IsValueInRange accept it as arguments? Commented Sep 5, 2018 at 19:30
  • The 1st function can overflow. (Like other answers' code.) Although the complexity of the overflow-safe code is an argument for putting it into a function. Commented Sep 5, 2018 at 23:36