3 ms·
That breaks efficient code reading. When you read code, you tend to skip through basic-blocks (i.e. consecutive statements without branches) and follow them to
by mahmud 16y ago
That breaks efficient code reading. When you read code, you tend to skip through basic-blocks (i.e. consecutive statements without branches) and follow them to that intersection point where a decision has to be made. In traditional form, if you have:
if (condition) consequence();
You're able to "run" the condition in your head and step into the consequence without loss of pace. But when you put the consequence before the condition, you will have to backtrack.
- v_ 16y agounless the consequence itself is something that signifies the end of a basic block, like a break or a next or a return.
- brianto2010 16y agobacktrack = true unless consequence.signifies? :block_end It doesn't seem that much harder to read.
- draegtun 16y agoUnfortunately though you are potentially adding subtle bugs here which can only be caught at run time. To avoid excessive test coverage it would be more pragmatic to do: backtrack = (consequence.signifies? :block_end) ? false : true But that's not as easy to read :(
- mahmud 16y agoI didn't reply to that one-liner because it is a one-liner. A lot of software engineering lore crumbles into tautologies or is completely obviated when you're working at the microscopic level.