views:

175

answers:

5

I understand that Smart::Comments should not be used in production code, since it is a source filter.

However, I have been using Smart::Comments in my development code and then commenting out the "use" line before sending the code to production.

Given that I'm going to use it in my development code, what I should specifically be concerned about? I've searched the Internet and not found any reasons that I should be worried except that source filters are "a bad idea" or "evil" or that they should never be used in production code.

UPDATE: I'm now using a key binding in vim to implement Sinan Ünür's approach:

map <Leader>c <Esc>:!perl -MSmart::Comments %<CR>
+4  A: 

Source filters are bad problematic because they use an imperfect parser to rewrite your code. Everything works great, as long as the filter manages the code you feed it.

The moment you add something that breaks the filter, the whole system self-destructs and you get bizarre bugs.

Source filters also confuse the debugger, which can be a problem--if you use the debugger.

daotoad
+2  A: 

I have no opinion on the source-filters part. But just look at the Synopsis of Smart::Comments. They may be smart, but what you end up with can hardly be called "comments". If you need a progress bar, go ahead, add one explicitly. If you need to comment something, do it in a way that let's the next guy reading your source understand what you meant.

innaM
+1  A: 

Smart::Comments is specially written in such way, that when you comment out "use Smart::Comments" it would be only comments, so program is not affected at all. Other modules have more serious problems, like when you will not be able to get exact line number of error.

Alexandr Ciornii
+6  A: 

I prefer not to put:

use Smart::Comments;

in my code. When I do indeed use Smart::Comments, I invoke the script using:

$ perl -MSmart::Comments test.pl

This way, there is no chance Smart::Comments will be used in production code.

Sinan Ünür
++! I've often looked at S::C and wished I didn't believe in total abstinence from source filters. This provides a safe way to use S::C--now I may actually use them.
daotoad
Thanks! Good approach.
molecules
+3  A: 

I'm a huge fan of Smart::Comments, and it is called throughout our code, development and production copies. I rarely use it for progress-bars, mostly for assertions and debug output.

However, the practice is to pull it in using the form:

use Smart::Comments -ENV;

If the environment variable Smart_Comments is not set, Smart::Comments is completely inert.

Best of both worlds.

RET
Thanks! Yet another way to do it.
molecules