Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

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

OI!

We speak about style a lot. Do we put subs near the top, or do we insist on having them at the bottom? Do we cuddle our elses? How are our variables named, do we have space after commas, where's the opening curly anyway? Do we like arrows or double sigils? And what about indenting?

We all have different opinions about style. Style is very personal, so that may or may not be a good thing. However, we argue about style a lot, and never really sum our favourite style.

The Perl Style Geekcode was inspired by the original Geekcode and the Perl Geekcode, but because I didn't want to imply good or bad, I chose to use digits instead of + and -.
I leave a lot of subjects untouched, like programming logic, infinite loops, module usage, and a lot more. Sorry 'bout that.

Here it is:

Updates are denoted by a coloured character in front of what has been added or changed.
% 2002-03-25 16:32 CET
% 2002-03-25 18:13 CET

I - Indenting

Add the number of spaces you use, or t if you use only tabs. % If you use tabs, you can add "=4" to indicate you have set your editor to show tabs as 4 spaces.
Those who consider a tab to be multiple normal indents, may also suffix t, but with a number.
% If you have your editor change existing code automatically to follow your style, add an exclamation mark.

Example: 4-space indents and tab is two of those: I4t2
% Example: tab indents, but shown as 4 characters: It=4
% Example: I make my editor convert tabs to 8 spaces: I8t!
% Example: I use tabs, but I consider 8 spaces equal to one tab: It=8

O - opening curly

  • s => same line
  • n => new line
    • i => indented
    • % <i => indented, but less than the following block
  • 0 => no space before
  • 1 => space before
Example: on the same line and space before: Os1

; - semicolon

  • 0 => no space before
  • 1 => space before
  • 2 => line up semicolons

S - whitespace around operators

Add signs to the following items. The possible signs are (with X as the item):
  • <X => space before
  • X> => space after
  • <X> => space on both sides
  • % X => no space around this operator
Add a question mark on the _inside_ if you change style a lot: x?>

The operators: qw(, . + ** = && and ++ gt ==) Plus implies all simple math operators, what you say for && goes for ||, gt is all comparison operators, and so forward. With ++, it's only about between ++ and its variable.
%With ++ it's only about the difference between $foo++ and $foo ++ (choose any direction).

Example: S,><.><+>**<=><&&><and>++<gt><==>

B - spaces in brackets and parens if (XXXXX foo XXXXX)

% Floating point possible
  • 0 => never
  • 1 => only around complex things
  • 2 => always
  • 3 => more spaces indicates lower precedence

L - blank lines

  • 0 => never
  • 1 => between chunks
  • 2 => more blank lines means more different chunks

C - cuddling (else)

  • -1 => fully uncuddled and un-indented more than the curlies
  • 0 => uncuddled
  • 1 => half cuddle
  • 2 => full cuddle
Examples:
    C-1       C0        C1       C2
    }         }         }        } else {
  else        else      else {
    {         {

P - parens

% Floating point possible
  • -1 => I always try to avoid them
  • 0 => I don't really care, as long as it works
  • 1 => I always use parens
  • 2 => I'm extremely cautious
  • 3 => I'm paranoid: if ((($foo > $bar) && ($baz < $xyzzy)))

N - newline

  • < => before operator
  • > => after operator
  • e => I make an exception for qw(and or || &&) and such
Example: N>e

R - dereferencing

  • -1 => I prefer ${ $foo }{bar}
  • 0 => I prefer $$foo{bar}
  • 1 => I prefer $foo->{bar}
  • 2 => I wish there were a way to dereference the entire thing with an arrow

V - variable and sub names

  • % l - language
    Put the language(s) in parens, and separate with comma's. Most frequently used language first. Use ISO 639 2-letter codes. (Example for "mostly english, but dutch sometimes): l(en,nl)
  • c - caps
    • 1 => perl-like: long_names_like_this
    • 2 => studdlycaps: LongNamesLikeThis
    • 3 => java-like: longNamesLikeThis
  • a - abbreviation
    • 0 => i never abbreviate
    • 1 => sometimes
    • 2 => i even use "ary" instead of "array"
    • 3 => my variable names are never longer than five characters
  • p - plurality (put its arguments in parens)
      (-1: never, 0: sometimes, 1: always)
    • s - scalar names
    • h - hash names
    • a - array names
  • r - references
    • 0 => I don't include "ref" in the name
    • 1 => I do include "ref" in the name
    • 2 => I even call them "arrayref", "aryref" or "aref"
  • d - dummy names
    • 0 => % I name them a single letter
    • 1 => I call them "dummy" %, "temp" or something like that
    • 2 => I use "foo" and friends
Example of Slash style (incomplete): Vc1a0p(s-1h1a1)

H - habits

What is part of your normal every-script routine? (simply include those that are)
  • s - use strict
  • w - use warnings(1) or -w(2)
  • T - tainting on
  • d - use diagnostics
  • % a - $|++
Example: Hsw2

End with one of these

  • main-sub => main code before subs
  • sub-main => subs first, main code at the end
  • main => ALL subs are in external files
Add curlies to main if you put your main logic in a sub: "{main}-sub".


My code:
I4t2 Os1 ;0 S,><.><+>**<=><&&><and>++<gt><==> B1 L1 C2 P-1 N>e R2 Vl(en,nl)c1a1p(s-1h0a1)r0d2 Hsw2 sub-main
I'd like to know yours :)

U28geW91IGNhbiBhbGwgcm90MTMgY
W5kIHBhY2soKS4gQnV0IGRvIHlvdS
ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
geW91IHNlZSBpdD8gIC0tIEp1ZXJk


In reply to Style geekcode by Juerd

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 chanting in the Monastery: (3)
As of 2024-03-28 18:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found