Custom Search
Managing Your Code and Time Using Comments
January 27, 2007
While doing programming, sometimes what I would do is first before writing
code, I would put the steps I wrote down to achieve what that portion of the
code's supposed to do in comments. Then under each comment I would start
writing the code. Such as this:
// *** TO DO: Create initialization values for new variables
// *** TO DO: Determine if there will be a deposit or withdrawal
// *** TO DO: Ask the user for the amount
// *** TO DO: If deposit, add amount to total.
// Otherwise subtract amount from total
// *** TO DO: Display the total to the user.
Note that a // denotes a comment for C++ and PHP. Here are some other comment
notations:
Visual Basic, use '
Perl, bash scripting, use #
C, php can also use /* and */ for comment blocks
As each portion of the code is done, I remove the *** TO DO: text from the
comments. This serves two purposes: 1. To keep your program flow going
according to plan and 2. To show what areas you still have to work on. This is
very important in very large code that runs to 500 lines, for example (I am
working on a VB.NET web application for work that is well over 500 lines of
code for just one page!) and it also shows what you need yet to do.
This also helps you so that tomorrow you can go back to where you left off.
Another important thing. Especially if you are working on stuff for yourself.
ALWAYS take breaks and put comments in your code so you can go back to it
without losing track of what you are doing. I don't mean to scare anybody but
the following scenario HAS happened to some people. If you just keep at it
until it's done, one thing will lead to the next, you will end up going to bed
when the sun comes up and you will burn out and become very tired and
exhausted, sometimes DANGEROUSLY so! Taking breaks from programming is
essential for proper health! Some may laugh about this but it's not a joking
matter, really. I've been burned out before (in fact, that's what happened to
me this past week which made me quite sick). I've also heard of others who
actually ended up in the hospital because of pushing too hard! It's very easy
to get too involved.
Comments can (maybe literally) save your life. It'll save your code at least
and show you where you'll be next.
I have been given a link in school to the Mind Tools web site. I would
consider this required reading. Manage your project so you don't spend all
your hours trying to fix something. If you can't fix it in a certain amount of
time (be reasonable here), then put in COMMENTS in your code what is
happening, what went wrong, error messages and *** TO DO: NEEDS FIXING so that
you know it needs to be fixed!
I thought I'd mention all this because of my own experiences and that of
others. Unlike a 9 - 5 programming job where the boss expects you to punch out
at a certain time (as he might not want to pay overtime) or you have a certain
time to complete certain tasks, those of us with more lenient jobs (I work
from home and have a very understanding employer) have to do our OWN planning.
Those of you who would like to do this as your own business or just as a hobby
also should think about this.
Programming is fun and rewarding. But can be hazardous to your health if you
don't keep in mind your limits.
Something as simple as commenting code may seem trivial. But I think you can
see now how it can also be very healthy thing to do. Not just for others to
read your code, but for you to manage your programming time better so that you
can stay healthy, take breaks and be more productive.
Some other reading which touches on "computer addiction" of sorts is the book
"Virus" by Graham Watkins. VERY interesting book!
Normally, people who can sit at a computer, then get up after a two hours to
go do something else without much effort to think to do so aren't at risk
here. But in case some DO find themselves with the "Oh geez! It's two in the
morning!" Re-think what you're doing and re-plan it. This way you never will
need to worry about overdoing it if you keep your code commented, and keep
your plan on schedule and in perspective.