Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Switch

by Cow1337killr (Scribe)
on Aug 06, 2016 at 16:22 UTC ( #1169259=modulereview: print w/replies, xml ) Need Help??

Item Description: Switch - A switch statement for Perl, do not use if you can use given/when

Review Synopsis: The Switch module should be marked deprecated.

My thesis is that the Switch module should be marked deprecated.

One will find that many Perl Monks advise fellow programmers not to use the Switch module in any Perl program that even hints at eventually becoming production status source code. (The evidence is in the paragraphs below.)

This proposed deprecation marking is for the benefit of beginning and intermediate Perl programmers.

In most cases, advanced Perl programmers know better than to use it in serious source code, because many of them spend time at Perl Monks , stackoverflow, or in IRC channels devoted to Perl programming and see the (sad) results of beginning and intermediate Perl programmers being lured into using this module.

Let me mention its history, briefly. The Switch module was once a core module in Perl. (Of course, one can use corelist to get the details.)

% corelist Switch Data for 2016-06-20 Switch was first released with perl v5.7.3, deprecated (will be CPAN-o +nly) in v5.11.0 and removed from v5.13.1

One more administrative detail to deal with here: This review is part of a larger project to deprecate the Switch module. For details, please read this post describing a step by step recipe for deprecating this module (or any module) by hippo.

Below, I offer some hyperlinks that (I hope) will convince the reader that the Switch module should be deprecated.

I have "set the table". By now, the reader should be thinking "Such a strange module with a strange history". If you are "ready to dine", please read on.

In the recent post by hippo entitled Re^7: Perl Code Changes Behavior if Two Subroutine definitions are swapped, he references a Switch module bug report:

If the reader is still here at this point, it must be because he/she craves still more detail, because the bug report mentioned above should have satiated most of the audience. But, I can offer more for those that are "still hungry".

Here are some Perl Monks threads on the subject. It is not a complete list. For this task, I did a Google search with a query of site:perlmonks.org switch.

I hope that this review has convinced the reader that the Switch module should be marked deprecated.

Replies are listed 'Best First'.
Re: Switch
by CountZero (Bishop) on Aug 07, 2016 at 07:56 UTC
    This is a module that was originally conceived almost 10 years ago. The last changes go back more than two years.

    It says clearly in the documentation not to use it when you can use the "given ... when" keywords.

    It is not part of core, so if you use it you must have installed it yourself.

    I'm against an "official" deprecation mechanism for non-core modules. If one starts doing that, one must do so for each and every non-core module that has some "issues" or otherwise people will start relying on the fact that a module is not being "officially" deprecated.

    Deprecation of modules should remain the author's responsibility and using non-core modules should remain the user's responsibility. This is the only sensible approach, in my opinion.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      I'm against an "official" deprecation mechanism for non-core modules.

      I agree (eg.), but it would be nice if CPAN did some kind of page rank thing to move modules that have bad reps down the search results list.

      The problem with a module like Switch is it sounds like exactly what you want, and even appears to provide it at first; it's only once things get complicated and/or modified by others; that it suddenly starts to cause mysterious failures.

      Offering up that kind of apparently useful utility as benign, and letting every user have to discover it pitfalls for themselves, is like selling Samurai swords for cleaning your nails; its a matter of when, not if.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.
        it would be nice if CPAN did some kind of page rank thing to move modules that have bad reps down the search results list
        Indeed, but then one would have to install a "reputation" tracker first.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: modulereview [id://1169259]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (11)
As of 2016-09-28 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (532 votes). Check out past polls.