The color of your comments

Recently I had a thought that the comments in my code may be getting in the way of me actually seeing the code itself while I’m coding. There seems to be two camps in the code commenting world: (1) Write good code and you should not need comments and (2) Write comments or else you are being lazy and no one will ever be able to work with your code. Well, I’m not here to settle that debate (I fall somewhere in the middle).

So, I had this idea of changing the COLOR of my comments from GREEN to GREY, so that I could still see them, but they would kind of fade away into the background, but would still be there if I took a harder look. I suppose the default VFP comment color must be that classic green color that I’ve been looking at for years, so I’ve changed mine to grey to help me focus better on my code, and not the comments.

Who knows, maybe one day I’ll be a real programmer and won’t even need to write comments at all.

Also, the smart one, Bo Durban, posted this hint on UT (in response to this blog post) about how you are not limited to the base 16 colors:

Did you know…If you set it programmatically, you are not limited to the base 16 colors?:

oReg = NEWOBJECT("FoxReg",HOME(2)+"classes\registry.prg")

So, here are a few screenshots to compare… Give it a try and see what you think.

Grey Comments: Green Comments:

5 thoughts on “The color of your comments”

  1. There are some comments there that wouldn't be needed if code was self-commenting. For example, instead of Create JobFiles object, have a method called CreateJobFiles. Put the IF inside it. Look for the book Clean Code by Robert Martin. But as you said, there are two camps out there.

  2. Matt —

    I prefer comments with a light gray background.

    As for 'writing good code and you'll never need comments' … it is called CODE. Comments on individual lines of code just get in the way, but comments about design, implications, assumptions, dependencies, etc are assumption. The last thing I want to do when reading code is to try to decipher it.

  3. Like it. I might have to try changing my colors that way. I've also had it the exact opposite with a yellow background and a black font.

  4. Thanks, Matt. I tried this, and while this was great for reading code, I found it difficult to type comments that I could barely read. So, using the code from Bo, I wrote a little program to toggle between a "dim" and "bright" color scheme. You can save the following code in a .PRG and run it from the command window, or call it from an ON KEY LABEL:

    *– Set the following two constants to match your personal color
    *– preference.
    *– Current "dim" color is Gray with automatic (white) background.
    #DEFINE COMMENT_COLOR_DIM "RGB(192,192,192,255,255,255), NoAuto, Auto"

    *– Current "bright" color is Green with Gray background.
    #DEFINE COMMENT_COLOR_BRIGHT "RGB(0,128,0,192,192,192), NoAuto, NoAuto"

    LOCAL oReg AS FoxReg OF ( HOME(2) + "classes\registry.prg" ), ;
    lcCurrentColor, ;

    oReg = NEWOBJECT( "FoxReg", HOME(2) + "classes\registry.prg" )

    IF NOT oReg.GetFoxOption( "EditorCommentColor", @m.lcCurrentColor ) = 0
    MESSAGEBOX( "Unable to retrieve current Editor Comment Color.", 16, PROGRAM() )
    RETURN .F.

    *– Check which comment color scheme is being used. If the "dim"
    *– colors are being used, toggle to "bright" colors, and vice versa.
    lcCurrentColor = UPPER( CHRTRAN( m.lcCurrentColor, SPACE(1), SPACE(0) ) )
    IF m.lcCurrentColor == UPPER( CHRTRAN( COMMENT_COLOR_DIM, SPACE(1), SPACE(0) ) )
    lcNewColor = COMMENT_COLOR_DIM

    *– Set and apply the new comment color.
    oReg.SetFoxOption( "EditorCommentColor", m.lcNewColor )

  5. Matt and Mike, thanks for posting the discussion and code. Interesting approach. I normally have my comments green with "highlighted" yellow background, but have incorpoated Mike's code into my developer menu so I can toggle them out of the way.

Leave a Reply

Your email address will not be published. Required fields are marked *