Linus' idea of "good taste" code

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Wed Oct 26 02:41:42 PDT 2016


On 10/25/2016 5:19 PM, bluecat wrote:
> Interesting, that's going in my tips.txt file. Quick question, if you don't
> mind. What would be the top three things you've learned that significantly made
> you a better programmer?

Ha, great question. Never thought about it before. Off the top of my head:

1. Never try to do two things at once, i.e. never mix:

    refactoring
    translation
    more than one bug fix at at time
    optimization
    feature addition

I sure endlessly beat people on github with clue-by-fours over this.


2. If the code looks ugly, it is guaranteed to not work properly. If you're 
stuck debugging someone else's code, look at the ugly bits first. (I've had 
several experienced developers tell me this, too.)


3. Anybody can write clever, complex code. It takes genius to write simple code.


4. Macros are like crack. The first hit feels great, but macros inevitably turn 
everything they touch into crap. It took me a loooong time to learn this. Some 
years ago I made a concerted effort to purge macros from the dmd front end, and 
have been purging them from the back end. I've been very pleased with the results.


5. Global variables are the Spawn of Satan. (They make code very hard to reason 
about.)


6. Nearly all bugs can be fixed with under 10 lines of code, and quite a few 
with 1 line. It's always a red flag for me when a fix PR has 200+ lines of code 
(test case lines of code don't count, neither do comments).


7. If you're stuck on a programming problem, go out for a jog. I often find the 
answer that way. What can I say, it works for me.


More information about the Digitalmars-d mailing list