Sunday 20 November 2011

Does the use of comments affect program speed, executable size, or efficiency? in C programming

Does the use of comments affect program speed, executable size, or efficiency?

No. When your program is compiled, all comments are ignored by the compiler, and only executable statements are parsed and eventually put into the final compiled version of the program

Because comments have no bearing on your program’s speed, size, or efficiency, you should use comments as often as possible. Each of your program modules should have a header that explains the purpose of the module and any special considerations. Similarly, each function you write should have information such as author name, date written, modification dates and reasons, parameter usage guidelines, description of the function, and so forth. This information will help other programmers understand your programs better, or it might help you remember some key ideas of implementation later.

You also should use comments in your source code (in-between programming statements). For instance, if you have a particular portion of code that is complex or if you feel that something needs a bit more clarity, do not hesitate to put a comment in the code. Doing so might take a little more time up front, but you or someone else might be able to save several hours of valuable time by glancing at the comment and immediately knowing what the programmer had in mind.

See FAQ XIX.4 for an example program that shows how using comments, white space, and the underscore
naming convention can make your code much cleaner and much more understandable by others.

Cross Reference:

XIX.4: Does the use of white space affect program speed, executable size, or efficiency?
XIX.6: Do longer variable names affect the speed, executable size, or efficiency of a program?

No comments:

Post a Comment