3 ms·
> There is a reason regular front-to-back books are more popular then choose-your-own-adventure books. You know where you are, and you dont spend all day flippi
by hvidgaard 6y ago
> There is a reason regular front-to-back books are more popular then choose-your-own-adventure books. You know where you are, and you dont spend all day flipping back and forth.
I don't think that has anything to do with it. It's a roleplaying adventure where you need to keep track of things on a piece of paper and use dies for encounters. People that want to read don't want to participate, just consume. Active vs passive.
Regardsless, splitting 4-5 lines of code out into a function and giving that a proper name can enhance readability significantly. And modern IDE tools make it simple to read that without disrupting the flow. Visual Studio and IDEA for instance has a peak definition that makes it trivial.
If that function does not do what it say, that is a different problem.
- srtjstjsj 6y agoInstead of cramming the description into a NonPunctuatedFunctionName, just lay down some scoping brackets and write a comment. IDEs are food at folding code. If the function doesn't need to be called many times, it doesn't need to exist.
- hvidgaard 6y agoCode folding is not good for readability, and creates a significant overhead when reading the code. Even to the point where some static analysis tools default to highlight the use of "regions" as problematic.
- will4274 6y agoJumping up and down in the file while hitting f12 is not good for readability and creates a significant overhead when reading the code. C# finally introduced local functions in a recent version, which will hopefully remind other enterprise-y languages and IDEs that humans are programmed to read lines on a page in order.
- hvidgaard 6y agoIn VS you can press Alt+F12 to peak the function, no need to jump back and forth. Regardless, programming in that way requires that the functions adhere to SRP and a clear name can be written.
- quelsolaar 6y agoI think it can be good to have functions that are only called in one place if they do really well defined things. load_settings, or similar is probably one called on one place, but if it makes sense to have it as a separate function. I prefer clear naming over comments, because comments doesn't "travel" everywhere the named function/type/variable does.
- hvidgaard 6y agoAnd comments needs to be maintained too, which often slips even in PR reviews.
- CuriouslyC 6y agoIf you've got an algorithm or hot loop that's hard to follow because it needs to be, some simplifying functions can keep it from overflowing people's brains, which IMO is the worst overflow error.