Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Developing code to be a module

by space_monk (Chaplain)
on May 01, 2013 at 05:42 UTC ( [id://1031497]=note: print w/replies, xml ) Need Help??


in reply to Developing code to be a module

I hope this doesn't sound too rude, but the way you've described reeks of having no forward planning or idea of where you want your code to get to. Code shouldn't have to be 'turned into' a module; it should have been planned to be a module or modules in the first place.

Even for apparently trivial projects, you should spend some time thinking about how it breaks down into packages/objects before you start to code. You should look on CPAN, PerlMonks, StackOverflow etc to see if anything similar has been done before. With a little luck you may not have to write a line of code yourself. I think the mark of a good developer is not how many lines of code he/she produces, but how much of the problem he solves using existing solutions.

Also you should have some method of verifying your code does the job it is supposed to. Look at Test Driven Design as a methodology, and Test::Simple and/or Test::More as potential packages to ensure you have Unit tests to verify your package does the job it is supposed to.

Also have someone else look at the problem or code. A second pair of eyes often confirms that you are a Programming God, or points out a better way, from which you can learn. Both results are good. :-)

If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

Replies are listed 'Best First'.
Re^2: Developing code to be a module
by Utilitarian (Vicar) on May 01, 2013 at 10:02 UTC
    Many of us toiling at the "adminface" will develop a "-e" solution to a specific problem, which subsequently becomes a script as it "got a little complex".

    When it becomes a script strictures are applied and the code get slightly neater.

    Then a couple of weeks/months/years later you end up automating a process around this script, at which point it needs to be "modularised".

    At that point we add tests so that future development doesn't lead to regressions etc... and our humble script has made it through the admin's software lifecycle, it bears a passing resemblance to a developers software lifecycle after this stage has been reached.

    Personally I wouldn't count the failure to anticipate a simple flip-flop filter with an END block becoming a full blown log file parsing tool for a production service as bad coding.

    print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
Re^2: Developing code to be a module (perl -lanse)
by Anonymous Monk on May 01, 2013 at 07:37 UTC

    Lots of folks write programs that don't have functions, programs that don't start from a template

    #!/usr/bin/perl -- use strict; use warnings; Main( @ARGV ); exit( 0 ); ...

    This is typical for short programs and one-offs

    And you can't beat perl lanse :)

    $ echo hi there | perl -lanse " print qq{$greet\t$F[1]}" -- -greet=by +e bye there $ echo hi there > stuff $ perl -lanse " print qq{$greet\t$F[1]}" -- -greet=bye stuff bye there

    These types of programs can live and do good work quite for a long time before they need a second look, or functions/modules/tests...

    Code doesn't need to go places :)

      I don't have a problem with "Perl Golf" short solutions to problems and sometimes use them myself. I even have a go at some of them on here! :-)

      However its obvious the OP (Original Poster) is not talking about those basic sorts of problems.

      If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

        I don't have a problem with "Perl Golf" short solutions ...:-)

        There is nothing even remotely "Perl Golf" about that, IMHO that is practically a slur against perl, practically anti-perl-propaganda :)

        However its obvious the OP (Original Poster) is not talking about those basic sorts of problems.

        Sure its not :) Take for example Watching long processes through CGI (Aug 02), nothing particularly basic about it, sure its got 2 functions, but most of the code isn't in functions, less than 100 lines

        Or take for example Text-CSV_XS-0.97/examples/csv2xls, 200 lines, one function( usage(), mostly string/heredoc)

        Its easy to well past 1000 lines with this type of program, and its obvious to me this is the type of program the OP is talking about -- doesn't need modules or Test:: anything

Re^2: Developing code to be a module
by rpnoble419 (Pilgrim) on May 01, 2013 at 13:49 UTC

    Space_monk;

    Thank you for the time it took for your reply but you missed my point. I was trying to see how others perform their tasks. I'm not a perl newbie (started with perl 4) and have been a professional programmer for over 30 years. I was interested in other methods to make sure I was not missing something. All programmers get stuck in their own ways.

    Not every module started off as a module specific code base and I was interested in how others move code from single use to multiple use as code evolves. That was the point of the post.

      I've also been using Perl since 199cough on and off. I'm not trying to say there is only one way { I've been through Yourdon, SSADM, Agile, TDD and lots of others :-)}, but that if you start off as organised and methodical you won't get to a state where you end up saying "If you want to get to there, I wouldn't start from here" :-)

      If you spot any bugs in my solutions, it's because I've deliberately left them in as an exercise for the reader! :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2024-03-19 02:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found