When is a language considered a scripting language

2019-01-03 11:38发布

What makes a language a scripting language? I've heard some people say "when it gets interpreted instead of compiled". That would make PHP (for example) a scripting language. Is that the only criterion? Or are there other criteria?

See also:

30条回答
我只想做你的唯一
2楼-- · 2019-01-03 12:05

One division is

  • scripting = dynamically interpreted
  • normal = compiled

A dynamically interpreted language is interpreted at runtime whereas a compiled language is compiled before execution.

I should add that as Jörg has pointed out, the interpreted / compiled distinction is not a feature of the language, but of the execution engine.

You might also be interested in this explanation of Type system, which is related and focuses more on the language aspect, instead of the execution engine. Most scripting languages are dynamically typed, whereas "normal" languages are mostly statically typed.

In general the division of statically vs dynamically typed languages is better defined and has more implications on the usability of the language.

查看更多
淡お忘
3楼-- · 2019-01-03 12:06

If it doesn't/wouldn't run on the CPU, it's a script to me. If an interpreter needs to run on the CPU below the program, then it's a script and a scripting language.

No reason to make it any more complicated than this?

Of course, in most (99%) of cases, it's clear whether a language is a scripting language. But consider that a VM can emulate the x86 instruction set, for example. Wouldn't this make the x86 bytecode a scripting language when run on a VM? What if someone was to write a compiler that would turn perl code into a native executable? In this case, I wouldn't know what to call the language itself anymore. It'd be the output that would matter, not the language.

Then again, I'm not aware of anything like this having been done, so for now I'm still comfortable calling interpreted languages scripting languages.

查看更多
姐就是有狂的资本
4楼-- · 2019-01-03 12:07

"A script is what you give the actors. A program is what you give the audience." -- Larry Wall

I really don't think there's much of a difference any more. The so-called "scripting" languages are often compiled -- just very quickly, and at runtime. And some of the "programming" languages are are further compiled at runtime as well (think of JIT) and the first stage of "compiling" is syntax checking and resource resolution.

Don't get hung up on it, it's really not important.

查看更多
聊天终结者
5楼-- · 2019-01-03 12:07

I'll just go ahead and migrate my answer from the duplicate question


The name "Scripting language" applies to a very specific role: the language which you write commands to send to an existing software application. (like a traditional tv or movie "script")

For example, once upon a time, HTML web pages were boring. They were always static. Then one day, Netscape thought, "Hey, what if we let the browser read and act on little commands in the page?" And like that, Javascript was formed.

A simple javascript command is the alert() command, which instructs/commands the browser (a software app) that is reading the webpage to display an alert.

Now, does alert() related, in any way, to the C++ or whatever code language that the browser actually uses to display the alert? Of course not. Someone who writes "alert()" on an .html page has no understanding of how the browser actually displays the alert. He's just writing a command that the browser will interpret.

Let's see the simple javascript code

<script>
var x = 4
alert(x)
</script>

These are instructs that are sent to the browser, for the browser to interpret in itself. The programming language that the browser goes through to actually set a variable to 4, and put that in an alert...it is completely unrelated to javascript.

We call that last series of commands a "script" (which is why it is enclosed in <script> tags). Just by the definition of "script", in the traditional sense: A series of instructions and commands sent to the actors. Everyone knows that a screenplay (a movie script), for example, is a script.

The screenplay (script) is not the actors, or the camera, or the special effects. The screenplay just tells them what to do.

Now, what is a scripting language, exactly?

There are a lot of programming languages that are like different tools in a toolbox; some languages were designed specifically to be used as scripts.

Javasript is an obvious example; there are very few applications of Javascript that do not fall within the realm of scripting.

ActionScript (the language for Flash animations) and its derivatives are scripting languages, in that they simply issue commands to the Flash player/interpreter. Sure, there are abstractions such as Object-Oriented programming, but all that is simply a means to the end: send commands to the flash player.

Python and Ruby are commonly also used as scripting languages. For example, I once worked for a company that used Ruby to script commands to send to a browser that were along the lines of, "go to this site, click this link..." to do some basic automated testing. I was not a "Software Developer" by any means, at that job. I just wrote scripts that sent commands to the computer to send commands to the browser.

Because of their nature, scripting languages are rarely 'compiled' -- that is, translated into machine code, and read directly by the computer.

Even GUI applications created from Python and Ruby are scripts sent to an API written in C++ or C. It tells the C app what to do.

There is a line of vagueness, of course. Why can't you say that Machine Language/C are scripting languages, because they are scripts that the computer uses to interface with the basic motherboard/graphics cards/chips?

There are some lines we can draw to clarify:

  1. When you can write a scripting language and run it without "compiling", it's more of a direct-script sort of thing. For example, you don't need to do anything with a screenplay in order to tell the actors what to do with it. It's already there, used, as-is. For this reason, we will exclude compiled languages from being called scripting languages, even though they can be used for scripting purposes in some occasions.

  2. Scripting language implies commands sent to a complex software application; that's the whole reason we write scripts in the first place -- so you don't need to know the complexities of how the software works to send commands to it. So, scripting languages tend to be languages that send (relatively) simple commands to complex software applications...in this case, machine language and assembly code don't cut it.

查看更多
淡お忘
6楼-- · 2019-01-03 12:08

Scripting languages tend to run within a scripting engine which is part of a larger application. For example, JavaScript runs inside your browsers scripting engine.

查看更多
Explosion°爆炸
7楼-- · 2019-01-03 12:08

A script is a relatively small program. A system is a relatively large program, or a collection of relatively large programs.

Some programming languages are designed with features that the language designer and the programming community consider to be useful when writing relatively small programs. These programming languages are known as scripting languages, e.g. PHP.

Similarly, other programming languages are designed with features that the language designer and the programming community consider to be useful when writing relatively large programs. These programming languages are known as systems languages, e.g. Java.

Now, small and large programs can be written in any language. A small Java program is a script. For example, a Java "Hello World" program is a script, not a system. A large program, or collection of programs, written in PHP is a system. For example, Facebook, written in PHP, is a system, not a script.

Considering a single language feature as a "litmus test" for deciding whether the language is best suited for scripting or systems programming is questionable. For example, scripts may be compiled to byte code or machine code, or they may be executed by direct abstract syntax tree (AST) interpretation.

So, a language is a scripting language if it is typically used to write scripts. A scripting language might be used to write systems, but such applications are likely to be considered dubious.

查看更多
登录 后发表回答