Skip to main content

Timeline for Keep indentation level low

Current License: CC BY-SA 3.0

9 events
when toggle format what by license comment
Jul 26, 2017 at 16:48 comment added JimmyJames @DavidPacker I didn't create the example, obviously, but if I had to guess it was the nested version that was 'wrong'. I think this is exactly why nesting is bad. It's actually much harder to follow because what is returned as a result of the guard condition is separated from the condition.
S Jul 26, 2017 at 16:38 history suggested Mischa CC BY-SA 3.0
fixed mistake in code and added syntax highlight
Jul 26, 2017 at 9:28 review Suggested edits
S Jul 26, 2017 at 16:38
Jul 25, 2017 at 11:57 comment added Andy The first rewritten code is actually wrong. It returns false when a document is not finished but the initial implementation returns true instead.
Dec 7, 2013 at 1:47 history edited Reactgular CC BY-SA 3.0
added 7 characters in body
Dec 7, 2013 at 1:46 comment added Reactgular @kevincline The point of the PrintPage function was to only illustrate the concept of single purpose functions, and removing all operations from inside loops. Yes, one line of code in a function is not a good example but coming up with good examples all the time is hard ;).
Dec 7, 2013 at 1:43 comment added Reactgular @kevincline I'm trying to illustrate a point. While my examples might be overkill in reducing indentation. It answers the OP's question of how do I reduce indention?. My code is simply longer but not more complex. You just perceive it as complex because your mind is used to thinking of if statements as logical blocks. I don't write code to this extent, but it's an example of how to remove all indents. The purest way of doing it is to keep all operations on the first indent, and not to do any work inside blocks. That's why they only contain return statements.
Dec 7, 2013 at 0:11 comment added kevin cline Your code is unnecessarily complex: if (!doc.locked) { return true; } doc.unlock(); return true; should be simply: if (doc.locked) { doc.unlock(); } return true; Also, what is the point of wrapping page.print() with printPage(page) ?
Dec 6, 2013 at 16:52 history answered Reactgular CC BY-SA 3.0