4 ms·
I disagree with no.11 ... I prefer nested code of if's because as a reader I learn which conditions are relevant and assumed, rather than check-it-all at the st
by yonixw 8y ago
I disagree with no.11 ... I prefer nested code of if's because as a reader I learn which conditions are relevant and assumed, rather than check-it-all at the start.
- aw1621107 8y agoHow does checking at the start not convey what conditions are relevant and what assumptions can be made in the rest of the function?
- wongarsu 8y agoIf I put all my early exits at the start, for the remainder of the function I only have to remember the list of preconditions established by the early exits. With deeply nested code I instead have to keep a stack of currently fulfilled conditions in mind. Sure, at any given point the stack is shorter than the list so there's less things to keep in mind, but for me dealing with mental lists is much easier than dealing with mental stacks.
- ThorinJacobs 8y agoWhat level of nesting are you referring to here? I ask because I experience the opposite - with more than one or two levels of nesting I have difficulty keeping track of the condition the block expects. Depending on the size of the method sometimes even one level can make me stumble a little.