xenou
MrExcel MVP
- Joined
- Mar 2, 2007
- Messages
- 16,836
- Office Version
- 2019
- Platform
- Windows
I'd apply the 6 month rule. If it's not clear immediately what you did when you come back to it, it should have been commented.
Sounds fair to me. Of course you only discover what this really means after coming back to code a few times after six months to discover you have no idea anymore ... while the fact that I *have* done just that is evidence that I don't always follow the so-called inviolable commandments...
I'll take good code any day no matter what the style. I've seen enough bad code with nicely declared variables to convince me that what I like to see in a program is a good programmer behind it. If you have code that you expect to use and maintain for many years, then its well worth time documenting it. As far as your original example goes, I wouldn't need the comments for such a case so no problem there. Much of my code is broken into functions and subs, usually with a kind of "plot summary" in the comments that tell me what I'm doing more than how it works - when I review the code I read the comments to understand what it is meant to do so I can follow the flow quickly and figure out where I want to put my attention. Since I like to break up code into functions and subroutines, "meaningful procedure names" can be a form of self-documentation.
I use a lot of {i, j, s, t, a, x} variables for simple stuff in functions of 10-20 lines. After that I start getting more careful about meaningful identifiers. This is especially helpful in VBA where we don't have block level scope (too bad - I'd really love that).
Last edited: