Programming is my hobby, so when I write code, I don't have a boss to tell me "This is how you're going to do it or you're fired." But I like to write my variables in this format:

$VariableName
SubName();

Sometimes, I switch to all caps when I use a global variable or an important value.

my $DEBUG = 1;
my $GLOBAL_VARIABLE_NAME = 'hello';

If there's a function or sub that is part of a larger group of subs or "class," I might use an underscore character to divide the name:

Chart_DrawGrid();
Chart_Open();
Chart_Close();
Chart_Move();

If I need to create a "low-level function" that I only call from within certain functions or a function that is called many-many times and needs to be high performance, then I start its name with an underscore:

_FormatName();
_SaveValues();
_RecalculateSize();

For braces, each opening and closing brace goes on a new line, and indentation is always 2 spaces (I don't like to use tabs). In for loops, I like to use single-letter variables in lowercase that starts with $i, $j, $k... I like to avoid using $l because the lowercase L looks like a number 1. That gets confusing very quickly, so I will pick a variable name like $g or $f or something else instead of $l.

for (my $i = 0; $i < 43; $i++)
{
  ...
}


In reply to Re: Formatting variables by harangzsolt33
in thread Formatting variables by Bod

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.