Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
    .. why would the location of the statement in the code make any difference to the speed of the code?

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":



  • 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 goofing around in the Monastery: (1)
As of 2024-04-18 23:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found