If a method has many return statements, inserting print lines for debugging can become a nightmare. Print lines are required in many places in the method in order to figure out where/what the method is doing and returning. If the method only has one return statement, you only need one print line to determine what the method is returning.
Example
Overriding visiblePosition()
of connectors in Snapper
:
Bad Example
/** * Visible position of 'c' where 'p' is its current position in snapper coordinates. */ public point visiblePosition(Connector c, point p, Connector t) { if (c == conX) { return (1, 0, 0); } else if (c == conY) { return (0, 1, 0); } else if (c == conZ) { return (0, 0, 1); } return super(..); }
Good Example
/** * Visible position of 'c' where 'p' is its current position in snapper coordinates. */ public point visiblePosition(Connector c, point p, Connector t) { point res = super(..); if (c == conX) { res.x += 1; } else if (c == conY) { res += (0, 1, 0); } else if (c == conZ) { res = (0, 0, 1); } return res; }
Comments
0 comments
Please sign in to leave a comment.