That is a subjective question, and the answers will vary greatly based on opinions.

However, here is my opinion. In general, good code works according to a detailed specification over a wide range of input conditions. In other words, it is free of bugs. How do you know it is free of bugs? You create a comprehensive test suite and run it on multiple platforms/os/perl-versions. How do you know your test suite is comprehensive? You measure code coverage, etc.

Good code also conforms to standard layout styles. In other words, it looks good and is easy to follow (perltidy).

Good code is easy to use. It has a good user interface and documentation.

I have a few comments about your code. It is good that you use the strictures. It is good that you are validating your inputs, though you should do more to prevent common mistakes like div-by-0. Your indentation is good, except I don't like the double-spacing of lines. Your header prints would be less noisy using a HERE-DOC.

If code is expecting me to enter input from the prompt, I would prefer single-letter response, and make it case-insensitive: v instead of voltage, etc.

if($calculation =~ /v/i)

I'm not a fan of the empty elses. I understand why some use them, but I think they add clutter.

You have some excessive chomping going on:

my $resistance = <STDIN>; chomp $resistance; print "Now type the voltage of the circuit.\n"; my $voltage = <STDIN>; chomp $voltage; my $current = $voltage / $resistance; chomp $current; # <--------------- NOT NEEDED

Don't repeat yourself: put the current validation into a sub.


In reply to Re: What makes good Perl code? by toolic
in thread What makes good Perl code? by slinky773

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.