Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: Starting a New Script

by afoken (Chancellor)
on Sep 16, 2016 at 18:48 UTC ( #1171955=note: print w/replies, xml ) Need Help??

in reply to Starting a New Script

How do you start a new script? Do you just open a blank editor page and start typing?

Yes, exactly that. I usually start with this:

#!/usr/bin/perl use v5.12; use warnings;

(In the old days, I used strict instead of v5.12, but now all machines that I use have at least perl 5.12 installed. Modules start with package Some::Package::Name instead of the shebang line.)

From there on, everything depends very much on what kind of script / module I write and for what purpose I write it. Automating those three lines of code is a waste of time, simply because even those three lines may vary.

I'm no big fan of generating tons of boilerplate code. If a system - especially in an OOP environment - needs hundreds lines of code just for a hello world program to work, something has gone horribly wrong in the early stages of the system.

Loading your top 1000 modules in every script just because you could need one of them during the lifetime of one of your scripts looks as insane as the boilerplate aproach to me.

Furthermore, every coder (except for the snake lovers) has his/her own preferences of how code should be structured, ordered and indented. The same is true for projects and companies, and of course, all preferences are different. So any code generator you could write either generates code using "the wrong style" or has a phantastillion of options allowing to configure any option, including the most insane ones. Naturally, you need to support at least a hundred different configuration mechanisms to fit all needs.

During my professional carreer, I saw and used very different methods for creating new source code. "Do as I say (don't do as I do)", "Do what ever you want to solve the problem", "Use the only style that works", "Copy the templates and fill in your code, following the coding guidelines written on those two pages", "Copy some old code and modify it until it works", and of course "Follow this simple 350 page instruction manual to create a skeleton for a hello world program".


Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: Starting a New Script
by stevieb (Canon) on Sep 16, 2016 at 18:55 UTC
    Yes, exactly that. I usually start with this: #!/usr/bin/perl
    use v5.12; use warnings;

    As do I, but for a few years now, I've left out the shebang line and use a call to perl instead. Whether I'm using an IDE (intelliJ IDEA with Vim plugin) or just Vim, I have a macro in my .vimrc that inserts it for me:

    iab _perl use warnings;<CR>use strict;<CR>

    Any time I'm writing a Perl file, I just go into Insert Mode, and type _perl, and it injects:

    use warnings; use strict;

    ...of course, I have a couple of others, but that's the one I use most often.

    As far as usefulness of the OPs project, I'd have to see it, but I doubt I'd be inclined to use it to be honest, for reasons yourself (afoken) and Your Mother have stated.

    ...and LOL at "the snake lovers"... I code in Python because I'm FORCED to, damnit! ;)

Re^2: Starting a New Script
by shmem (Chancellor) on Sep 16, 2016 at 20:55 UTC
    ... (except for the snake lovers) ...

    ...and Java's Witnesses, whose preferences are often eclipsed by their IDE...

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re^2: Starting a New Script
by gsiems (Deacon) on Sep 19, 2016 at 15:22 UTC
    ++ for "phantastillion". Made my morning.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1171955]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2023-12-10 10:46 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (39 votes). Check out past polls.