in reply to What makes good Perl code?
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.
|
|---|