Keep in mind that the layout of any source file is supposed to be useful for the reader. The compiler or interpreter doesn't care what it looks like. I worked with a sysadmin who was vision impaired, and didn't use any indentation, anywhere, ever. That worked for him, and bash didn't care.

So here's how one of my typical scripts looks like:

#!/usr/bin/perl use strict; use warnings; # 2021-0413: An explanation of why I wrote this script. use Template; use lib '/my/local/libs'; use MyStuff; ...
Other people use different hash bang lines, perhaps using env instead. Fine. I always put strict and warnings up there, and I fix whatever errors they highlight. I also put a comment block up there -- even writing down what I think I'm doing helps clarify what my goal is. And if it might help me in six months time, great.

Then I get into the modules, and I list them in the same order I ordered my #include statements forty years ago when I was learning C -- I put the system ones first, and then my personal or local ones after that. Partly it's so that I'm reminded that my choices get higher priority than the system choices. I wrote some C code for a Perlmongers presentation on memory allocation recently, and one of the source files started like this:

#include <stdio.h> #include <assert.h> #include "mmh.h" /* This code more or less duplicates the functionality of the * original double allocation. */ struct something { int iValue; void *pvAnotherThing; };
So I've got two system includes, followed by a local include.

Anyway, work starts soon, so just to reiterate .. the source code layout is to assist the human. The computer doesn't care. I try hard to write in a style that's legible to me, and to other developers. I have pride in my work -- I want people to look at the code and have a good first impression.

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.


In reply to Re^3: Code style advice: where to put "use" statements? by talexb
in thread Code style advice: where to put "use" statements? by eyepopslikeamosquito

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, details, 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, summary, 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.