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

夙愿已清 提交于 2019-12-10 14:56:18

问题


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>

回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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.




回答5:


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.



来源:https://stackoverflow.com/questions/1785556/what-concerns-should-i-have-if-i-use-smartcomments-in-development-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!