Am Tue, 25 Oct 2016 15:53:54 -0700 schrieb Walter Bright <newshou...@digitalmars.com>:
> It's a small bit, but the idea here is to eliminate if conditionals where > possible: > > https://medium.com/@bartobri/applying-the-linus-tarvolds-good-taste-coding-requirement-99749f37684a#.nhth1eo4e > > This is something we could all do better at. Making code a straight path > makes > it easier to reason about and test. > > Eliminating loops is something D adds, and goes even further to making code a > straight line. On a more controversial note, I sometimes replace nested blocks of conditionals and loops with flat spaghetti code and goto with verbose labels. There are situations where you can explain straight forward what needs to be done first, second and last, but special cases and loops make it hard to tell from "normal" code. if (valueTooBig) goto BreakBigValueDown; ProcessValue: ... return; // ====================== // BreakBigValueDown: // makes big values manageable ... goto ProcessValue; There is a concise piece of code that handles 90% percent of the cases and another block for anything that requires special handling. It can in theory also avoid costly memory loads for rarely used code. > One thing I've been trying to do lately when working with DMD is to separate > code that gathers information from code that performs an action. (The former > can > then be made pure.) My code traditionally has it all interleaved together. Interesting. -- Marco