Hi all,
Recently, I implemented a project that was due right now. Given the time constraints on this project, I implemented it as efficiently and quickly as I could -- I left out nearly all embedded documentation (comment blocks) as well as all inline comments. After having handed off the desired deliverable, I am going back and tidying my code and adding comments. My office doesn't have many coding standards, but one coding standard that we have is that each subroutine must be preceded by a comment block that describes the subroutine -- we use the Natural Docs style for these blocks -- similarily each Perl package has to have a Natural Doc style comment at the beginning of the package describing the purpose of the package. I am not a fan of having comment blocks before subroutines or at the top of a package, at least if I think the subroutine or package is straight forward enough. However, I do like putting comments in my code. For example: when I am processing data, I often have an outer loop that causes the given algorithm to iterate through the entire data set. Inside that outer loop, I will often have two inner loops. The first inner loop reads data into a buffer until the buffer contains a sufficient set of data to be processed. The second inner loop processes the data that the first inner loop put into the buffer and only leaves behind the tail end of the buffer if the tail end does not consist of a complete subset of data to process. Placing those two inner loops in an outer loop causes all of the data subsets in my data to be processed. For the sort of thing that I just described, I usually have lines of comments placed before each statement to help any one reading my code and to help me later when I have to fix it or enhance it.
Here is my question:
Is there a performace hit to heavily commented Perl code?
I've generally assumed that the answer is no. My understanding on how Perl works is that the Perl engine contains a "just-in-time" compiler that compiles the Perl code just before it executes it -- this is different from purely interpreted languages where the symbols are parsed, tokenized and executed all at the same time. I figured the Perl "just-in-time" compiler probably left out comments, so that even though having a lot of comments would slow down the compilation phase just a little, it would have NO IMPACT on the execution phase of the statements that the Perl engine just compiled.
Does any one know, is my above assumption true? Does any one know, is there a performance hit to heavily commented Perl code?
Does any one have any opinion in support of or against commenting your Perl code for the benefit of yourself and others?
Kindest regards,
Peter J.
In reply to Are there any drawbacks to comments -- can they hurt the performance of Perl code? by jira0004
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |