DEV Community

Kang-min Liu
Kang-min Liu

Posted on • Updated on

CPAN Release of TooMuchCode 0.17

Perl::Critic::TooMuchCode is a set of policy addons that generally checks for dead code or redundant code.

I feel grateful that this small project starts to draw some attention and endorsement and now it is receiving pull-requests from the Perl/CPAN community.

In version 0.17 we improved the policy ProhibitDuplicateLiteral and now it we can whitelist strings and numbers in configurations. If you somehow really need to use number 42 and "forty two" literally in the code many times, you list them in .perlcriticrc:

[TooMuchCode::ProhibitDuplicateLiteral]
whitelist = "forty two" 42
Enter fullscreen mode Exit fullscreen mode

Thanks to @ferki from project Rex!

Rex is an automation framework, or remote-execution framework. In a sense, similar to Ansible. It's a simple way of telling machine what to do, with some code named Rexfile -- a task manifest. which is also perl code. Within which you'd repeat some strings literally such as:

service 'apache2',  ensure => 'started';
service 'mysql',    ensure => 'started';
service 'memcached, ensure => 'started';
Enter fullscreen mode Exit fullscreen mode

... and that is OK. Because those manifests should be direct instead of indirect/abstract with the use of variables / constants to just hold the string 'started'. Doing such is an unnecessary level of indirection since the purpose of task manifests is to tell machine what to do and we do not want to make human readers read twice just to understand what those statement means. After all, repeatition by itself isn't necessarily the problem.

Well, apparently in the context of coding Rexfile, some repetition are allowed. In general, perhaps repetition are OK in any DSL code. DSL itself already reduce some repetition by hiding the details and DSL keywords tends to be high-level constructs that are designed to be easily understandable for human readers. Repetition of DSL keywords almost never leads to be unreadable or "bad small".

I might have repeated the word "repetition" too many times.


Originally posted at: gugod's blog -- CPAN Release of TooMuchCode 0.17

Top comments (3)

Collapse
 
averageguy profile image
Jim

Might be picky but I think you need to review this statement "... read twice before they can understand what it really means, the is a problem." perhaps you mean "...that is a problem." I would ignore this except that I suspect non English speakers might be confused since there appears to be a number of ESOL folks in this group.

Collapse
 
gugod profile image
Kang-min Liu

Thanks for being picky and bothered to reply!

I rephrased that last sentence to better summarize the paragrph. Usually I read my posts twice before publish them, but doing so never make "weird things" disappear.

Collapse
 
averageguy profile image
Jim

I think we all suffer from that. It's probably because we see what we meant, not what we wrote.