3 ms·
Learn to simplify. If your code is long, hairy and convoluted, there's probably a better way to do it. If the problem itself is long, hairy and convoluted, the
by statictype 16y ago
Learn to simplify.
If your code is long, hairy and convoluted, there's probably a better way to do it.
If the problem itself is long, hairy and convoluted, then redefine the problem in a different way. ie, come up with a different paradigm for achieving the same result.
If you find yourself writing a lot of special edge case handlers, then try to redefine the model to implicitly take care of those edge cases.
None of this is easy, but being aware of it goes a long way towards becoming better at it.
- arghnoname 16y agoI've had this experience. It took me a while before I realized that a decent chunk of hairy tricky code could be avoided if I just started out with an appropriate data structure in the first place. Starting with a good data structure in the first place is almost like starting with the solution for a surprisingly large amount of problems. Now, whenever I find myself getting confused I try to think really hard about where I went wrong. Good code is like good prose. If you have to read it six times to understand what is happening, the writing sucks.
- eru 16y agoHave a look at the data structures in "How to roll your own Window manager" (http://donsbot.wordpress.com/2007/05/17/roll-your-own-window-manager-tracking-focus-with-a-zipper/ http://donsbot.wordpress.com/2007/05/17/roll-your-own-window...) for a nice example.