by josephg · 3y ago · 0 comments
Mmm I've been programming for 30 years across a lot of languages. My code doesn't look the same as it did when I was a beginner. Sure has flopped around a lot though. Take comments:
- When I started, I used no comments (because I was ignorant)
- Then I put comments everywhere because someone told me it was good practice
- Then someone said comments are a sign your functions are too long and poorly named. So I went back to no comments for a bit. But I sort of hated the resulting code - functions were too small and it still wasn't "obvious" no matter how cleverly I named my functions.
- So then I had a few comments here and there, wherever my code wasn't "obvious".
- Then I tried literate programming, and my code was in small islands amidst an essay of comment. That was fun, but it didn't last.
These days I use comments for 2 purposes: to document my APIs, and to write little letters to my future self. Eg:
// This code looks wrong at first glance, but its actually correct.
// Here's why: ...