My first programming language was C, which I learned from Kernighan & Ritchie's book. That was my concept of the correct way to indent and format programs. Gradually my ideas evolved ... different languages create situations that didn't exist elsewhere. But my current job, maintaining software that has been around for a long time, convinces me the best solution is to have a perltidy configuration file that everyone used. I can cope with just about any arrangement, if it's consistent.

Your 700 line problem is that you begin at the beginning, and add lines until you reach the end. Instead, describe the task on a top-level basis.

# Read patient records from file, one by one # parse the data # output summary

Well, there's an 'open file' and a loop hidden in that first element, but there are essentially a few routines there.

my $options = parse_cmd_args(); my $patient_file = open_patient_file( $options ); my $result_file = open_result_file( $options ); while ( my @record_lines = get_record( $patient_file ) ) { my $record_hash = parse_record( @record_lines ); output_results( $result_file, $record_hash ); }

I'm not saying the above is the ideal result, but it IS simple, localized, readable. Expand each subroutine into a few steps, actually coding items that are simple, using abstract steps that need to be defined for more complex steps.

Before you start coding, write a top level description of what you want, focus on generalities, rather than details. Some of this will change as you begin implementing. Even after years of experience, I find some steps become very complicated, and need to be split into multiple steps, while other steps wither away. But without any toplevel concept, your program will be a tangle of spaghetti.

As Occam said: Entia non sunt multiplicanda praeter necessitatem.


In reply to Re: Code Critique by TomDLux
in thread Code Critique by rhiridflaidd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.