Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: What is code readability?

by swampyankee (Parson)
on Jan 03, 2007 at 03:39 UTC ( [id://592691]=note: print w/replies, xml ) Need Help??


in reply to What is code readability?

APL? I had a friend (who was involved in building the engine monitoring software for the Rutan Voyager) described APL as a "write-once" language.

I don't think coding for readability and coding for maintainability are that much different. In either case, the program has to be written for an audience, and the chances are the audience will be less skilled. This may mean eschewing perfectly valid Perl, such as multiple statements on one line, or leaving in syntactically meaningless white space, or (horror!) putting in use English;, or adding parentheses that are not strictly needed.

I tend not to be too fussy about indentation (as long as it's reasonably consistent: 2, 4, 3, whatever is fine). I tend to dislike the practice of splitting long lines before operators, e.g.
$x = $a +$b +$c;

with "operator" including both arithmetic and logical operators.

I tend to keep my copy of Kernighan & Plauger's The Elements of Programming Style near to hand. Despite the examples being mostly in PL/1 and FORTRAN-66 (pdf file), most of the basic concepts are still applicable.

Probably the most extreme version of "readable code" is Donald Knuth's Literate Programming. I've never tried it (has anybody here tried it?)

emc

At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.

—Igor Sikorsky, reported in AOPA Pilot magazine February 2003.

Replies are listed 'Best First'.
Re^2: What is code readability?
by Herkum (Parson) on Jan 03, 2007 at 04:10 UTC

    I tend to dislike the practice of splitting long lines before operators,

    Well it depends on the situation in your example it is not such a big deal. However, problems occur when lines tend run long. Example:

    # Long line my $absolutely_very_long_value = $value_reference->{$first_record}{$se +cond_key}{super_property} + $value_reference->{$second_record}{$secon +d_key}{super_property}; # Split Line my $absolutely_very_long_value = $value_reference->{$first_record }{$second_key}{super_property} + $value_reference->{$second_record}{$second_key}{super_property};

    I think the worst example for a long-line is something like this,

    my $print = qq~ # HTML that goes on for 30+ lines # This some more text here. text text text text text text text~ if $in +s{save_changes};

    I could have strung up the original programmer for this. This sort of syntax you may not even know you are working on a if statement. You don't see it unless you page down or you have to scroll all the way to the right.

      Well it depends on the situation in your example it is not such a big deal. However, problems occur when lines tend run long.

      I just prefer to split lines after operators.

      In your example, my code would look like this:

      # split line my $absolutely_very_long_value = $value_reference -> {$first_record}{$second_key}{super_property} + $value_reference -> {$second_record}{$second_key}{super_property};

      emc

      At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.

      —Igor Sikorsky, reported in AOPA Pilot magazine February 2003.
Re^2: What is code readability?
by sgt (Deacon) on Jan 08, 2007 at 17:04 UTC

    I came across the technique while reading Hanson's C interfaces & Implementations. By the way the book is a very good read (it abstracts and amplifies the techniques used in the creation of lcc). At least for books it seems quite useful. As far as using it for real in code, I don't know, you will have to teach your editor to put a link to code, and to present whatever is linked in-place in a different font say. Mean IDEs could even replace the code by a function! ;)

    cheers --stephan

Log In?
Username:
Password:

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

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

    No recent polls found