Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

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

Perl contains many shortcuts (or conveniences, if you prefer) designed, in part, to save some typing. For example:

  • Matching regular expressions don't need the leading m--provided forward slash is the delimiter.

  • Subroutines calls don't always need the leading ampersand.

  • The diamond operator (<>) can be used instead of <STDIN>.

Update: Fixed the slash problem (thanks, Fastolfe).

Given some of the recent discussion regarding coding style, is it best to avoid counting on these shortcuts?

My thinking here is based on my experience in other languages. For example, in certain languages, you can occasionally get away with implied typecasting. However, there are times when the results of an implied cast are not what you were after and the novice ends up fruitlessly hunting for a bug in what appears to be perfectly good code.

More practically, I wonder if certain examples (no, I don't have any in mind) reply too heavily on shortcuts.

What do you think? What shortcuts, if any, do you take advantage of and which ones do you specifically ignore (e.g. type the longer form)?

----------
For the record, I try to be as specific as possible, if only to help the hapless novice that has to maintain my code in the future.


In reply to Regarding style by footpad

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.