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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

It is perhaps easier to describe "unclean" code. For example:

  • Code with lots of code smells (see also wikipedia Code_smell)
  • Lots of magic numbers
  • A 5000-line main program
  • A sub that reads and writes global variables
  • A sub that does not have a single purpose; for example, instead of a sin function and a tan function, someone defines a sin_and_tan function
  • Some of a sub's parameters are not used
  • A sub that is 1000 lines long, aka "Big-Arsed Function"
  • Duplicated code
  • Code with gaping security holes
  • Code that leaks resources
  • Code that is not thread-safe or signal-safe

Conversely, some clean Perl code attributes are:

  • strict-safe
  • warnings-safe
  • taint-safe
  • Good variable naming
  • Minimize variable scope
  • Prefer lexicals to globals
  • Good commenting
  • Consistent indentation and visually pleasing layout
  • Easy to understand
  • Simple, Clear, General
  • Easy to use module interfaces
  • Comprehensive test suite

Finally, TheDamian's new book Perl Best Practices provides much sound advice on writing clean Perl code.

Update: See also Is it correct? by GrandFather:

  • Does it work correctly?
  • Do you understand it?
  • Would anyone else understand it?
  • Will you understand it in a month's time?
  • Does it strike a good balance between terseness and verbosity?
  • Could you make changes to it without it being likely to break in unforeseen ways?
  • Is it fast enough?

Update: See also: On Coding Standards and Code Reviews and Re: I need perl coding standards (Coding Standards References)


In reply to Re: Meaning of "Clean" Perl code by eyepopslikeamosquito
in thread Meaning of "Clean" Perl code by neversaint

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found