What concerns should I have if I use Smart::Comments in development code?
Asked Answered
M

5

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>
Method answered 23/11, 2009 at 19:58 Comment(2)
See also daotoad's community wiki that he opened up after answering this question: #1786352.Method
See the 2015 Perl Advent article on Smart::CommentsMethod
S
4

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.

Shive answered 23/11, 2009 at 20:41 Comment(0)
T
10

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.

Treacherous answered 23/11, 2009 at 23:17 Comment(1)
++! 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.Shive
L
5

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.

Logion answered 24/11, 2009 at 23:27 Comment(1)
Thanks! Yet another way to do it.Method
S
4

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.

Shive answered 23/11, 2009 at 20:41 Comment(0)
M
2

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.

Marlowe answered 23/11, 2009 at 21:17 Comment(0)
D
1

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.

Duckweed answered 23/11, 2009 at 21:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.