Sunday 4 March 2012

Script vs Program - A pragmatic view


First, it'd be useless to talk about the distinction between a "scripting language' and a 'programming language', because it's clear that the same language can be used in different contexts and environments, be interpreted in some cases or compiled in others.

The only distinction worth discussing in my opinion is whether a portion of source code is a script or a program.

A very easy conclusion can be found in "Building Skills in Python", S. F. Lott:
The “scripting” distinction is an operational feature of POSIX-compliant operating systems. Files which begin with the ‘#!/path/to/interpreter’ will be used as scripts by the OS. They can be executed from the command-line because the interpreter is named in the first line of the file.
Languages like Java, C and C++ do not have this feature; these files must be compiled before they can be executed.

So what happens if you have, say, a couple of thousands lines of Perl code, distributed in about a hundred classes, using a few CPAN modules?
It'll be interpreted, not compiled, but would you present it as a script? I don't think so.

Also, the "shebang" (#!/path/to/interpreter) is not really the point, is it? You can omit it and then specify which interpreter has to be used and still have an interpreted execution.

See this other definition (Think Python - How to Think Like a Computer Scientist, A. Downey):
script: A program stored in a file (usually one that will be interpreted)
As superficial as this may seem, I think this is actually getting to the point, so here comes my personal definition of "script":

A script is a sequence of instructions, stored in a file, which can be directly executed by an interpreter.

Of course this has be taken in an honest and pragmatic way. A good software developer won't put the thousands of lines of Perl mentioned above in a single file, even if it's absolutely legal.

When a script starts to become so big (say more than a page? - 200 lines of code or so) to require the inclusion of other files, depending on my definition that becomes a program, even if it's still interpreted.

What do you think?

2 comments:

  1. if i'm honest, i think all scripts are programs. 'script' in most conversations these days is a reference to the triviality of the application. A trivial objective often requires little effort, thus there is a common tendency to overlook the quality of the code. Some traditional 'scripts' then grow pretty big, and get really unwieldy.

    anyway.. i don't really mind. My take home from this post of yours is that you're reading through a fair bit of python-focussed material, which is a good thing! :)

    ReplyDelete
  2. I agree with you and with Adam when he says that all scripts are programs.

    When we discussed about that difference, my point was, following the definition, that if the code is wrote with a scripting language it is a script, on the other hand if it is wrote with a programming language it is a program but I know that a code wrote in Python, PHP, etc could be more a program than a "real" program speaking about the functional side and the complexity.

    PS: I think to know a place where having thousands of lines of code in a single file is a well established practise :P

    ReplyDelete

About ICE negotiation

Disclaimer: I wrote this article on March 2022 while working with Subspace, and the original link is here:  https://subspace.com/resources/i...