Re:Guidelines for writing readable code
by yonixw on Friday September 14, 2018 @08:23AM
(#17986658)
they are all gathered at once.the following lines could assume any combinations of those conditions. in simple examples it is not an issue but as the function get more complex I found it excruciating.
[ Parent
| on HN ]
Re:Guidelines for writing readable code
by aw1621107 on Friday September 14, 2018 @09:05AM
(#17986886)
> the following lines could assume any combinations of those conditions.
Do you mind expanding a bit more on this? From what I understand, if you have early returns the only way you can get into the rest of the function is if all of the conditions pass, not any arbitrary combination of them.
Also, do you have an example of a more complex function with early functions that you find difficult to read?
Re:Guidelines for writing readable code
by de_watcher on Friday September 14, 2018 @09:23AM
(#17986994)
I just soak everything in asserts.
That way there is no need to scroll up for preconditions, be it a nested tree or some returns at the start.
And when you move a small piece of code, you're told exactly what you should be thinking about, you need to decide what to do with that assert that represents an assumption.