4 ms·
It depends on how often you have written loops just like that though. To my eye, setting a min_value, then looping through the numbers updating min_value when s
by Scarblac 3y ago
It depends on how often you have written loops just like that though. To my eye, setting a min_value, then looping through the numbers updating min_value when something lower is found and returning the end result is just a single "chunk" that's immediately obvious.
With the highly unusual addition that there's an extra if statement inside. That's weird.
And the initial value of 9999 is highly suspicious. All the numbers may be higher than that.
I'd say it has complexity value 4 -- "find the minimum value, in the usual way, except only look at odd numbers, and use 9999 as the initial value".
- deleted 3y ago[deleted]
- AnimalMuppet 3y agoGeneralizing from your first paragraph, things occupy only one chunk when they're an idiom that you know well. That you know well. This is why there's so much disagreement on this stuff. Different people have different idioms that they know well. You're never going to be able to reduce "what is simple" to something everyone agrees on. There's an actionable part of this observation. If you're responsible for a code base, it should use a limited number of common idioms. Have everyone working on the code base learn and use those idioms in preference to other approaches. Consistency reduces the mental burden on the reader.
- larksimian 3y agoI just had the same sort of realization actually, trying to explain to myself why I dislike micro-functions: it pollutes the vocabulary that I need to know at all times with super low value information words that are only relevant in very particular contexts(and that I don't necessarily trust to not be mislabelled). This is an unappreciated value of using code frameworks and doing things the 'framework' way. You might have a somewhat convoluted function using framework or std lib functions to do a task but anyone familiar with the tool can just read it top to bottom and have a genuinely deep understanding of what the code those and what edge cases might show up. If you convert that into your own function vocabulary by wrapping the 'basic' code into extra methods... nobody can read the superficially more elegant function and know anything more than what the function names are telling them. It's like they're reading pseudo-code and can only guess at the implementation subtleties unless they annoyingly 'manually' inline the code by jumping to and reading through the custom function definitions.