More indentation equals more mental context required.
But although these shorter, less-indented functions are inherently easier to understand, they're not necessarily freer of bugs...
21–30 of 71 posts
More indentation equals more mental context required.
But although these shorter, less-indented functions are inherently easier to understand, they're not necessarily freer of bugs...
While the patterns themselves are interesting, the idea that all code must be rearranged in to smaller functions to be “refactored” seems a little juvenile.
It'd be better to ask if the code is more complex than it needs to be.
I liked the terms John Ousterhout uses. For some module of a program (e.g. a method, class, package, etc.), it has an interface and an implementation. The interface is "what you need to know to use the module", the implementation is "how it's done".
Complexity comes from dependencies (e.g. more interfaces you need to know about), and from obscurity (e.g. things you need to know about, which aren't obvious from the interfaces given).
In some cases, many small methods would be an increase in complexity overall. In some cases, one big method may be an increase in complexity.
How much longer will this rumor persist that "good code" doesn't need commenting? Good comments explain things that aren't immediately obvious from the code.
While the patterns themselves are interesting, the idea that all code must be rearranged in to smaller functions to be “refactored” seems a little juvenile.
I'm glad I'm not the only one who pays attention to this. This is completely unsubstantiated and coming from a relatively inexperienced programmer, but it's been my experience that better code tends to produce nicer shapes. An obvious example not mentioned in the article arises when code is nested too deeply and too thinly, creating jarring and disproportionate peaks.
Not saying I go by shape alone, but if it looks messy, that's a warning flag.
> ... not so good code: if it was, we wouldn’t need a comment... How much longer will this rumor persist that "good code" doesn't need commenting? Good comments explain things that aren't immediately obvious from the code.
So that leaves the “why”. To my mind, code comments are the worst place to record why a particular implementation exists. The why often needs collaboration with non-coders.
While the patterns themselves are interesting, the idea that all code must be rearranged in to smaller functions to be “refactored” seems a little juvenile.
https://news.ycombinator.com/item?id=8374345
https://webcache.googleusercontent.com/search?q=cache:http:/...
> ... not so good code: if it was, we wouldn’t need a comment... How much longer will this rumor persist that "good code" doesn't need commenting? Good comments explain things that aren't immediately obvious from the code.
> ... not so good code: if it was, we wouldn’t need a comment... How much longer will this rumor persist that "good code" doesn't need commenting? Good comments explain things that aren't immediately obvious from the code.
My process of writing code is to of course code a proof of concept in order to get a feel for the problem domain this could be considered a spike in agile parlance
Then the primary and alternate flows can be coded against a basic test suite
followed by a refactor and then a comments pass
Depending on what comments arise perhaps another refactor may be in order
I typically try to follow the spirit of TRUE software
> ... not so good code: if it was, we wouldn’t need a comment... How much longer will this rumor persist that "good code" doesn't need commenting? Good comments explain things that aren't immediately obvious from the code.