开发者

What is a scripting engine?

I've seen here that what sets a programming language apart from a scripting language is the scripting engine. But I don't understand how it works, so I don't know the differe开发者_运维知识库nce.

For example, I see code in Java calling methods in imported libraries, but it doesn't seem "different enough" from Python or Ruby code - both are scripting languages, right? I guess this also has to do with the procedural and object oriented paradigms, but in the end, I can't see why they are classified they way they are.

EDIT: About a scripting engine being an interpreter... Isn't Java an interpreted language? I know there's the compiled bytecode, but still, it doesn't make sense to me.


There is no hard and fast line between a "scripting language" and a "programming language".

Properties of "scripting languages" tend to include:

  • garbage-collected memory manager, with no need to explicitly allocate and free objects

  • ability to simply execute commands, without a bunch of boilerplate code. Java is usually used as a counter-example of this. In Python you can simply say print("Hello, world!") but in Java you need a lot more syntax (the example here is seven lines of code).

  • Related to the above, usually in a "scripting language" you don't have to explicitly declare variables, and you rarely need to declare types of variables. Some scripting languages (such as Javascript) will coerce types with wild abandon, and others (such as Python) are strongly typed and raise exceptions on type mismatches.

  • no need for an explicit compile or link step; you just write code and run it. (A "scripting language" can still be Just-In-Time compiled internally; Python does this, for example.)

Beyond these basics, a "scripting language" can range from something primitive and trivial, like the "batch" language in MS-DOS, on up to an expressive and powerful language like Python, Ruby, etc.


You've basically discovered that the distinction between a scripting language and a "non-scripting" language is pretty artificial. Python can be compiled to JVM bytecode (with Jython), and I believe Ruby also can -- then the "engine" running the Python or Ruby code in question will be a JVM, the same "engine" that runs Java code (or Scala code, etc etc). Similarly with .NET and IronPython (or IronRuby) -- then the "engine" is Microsoft's CLR, just as for C#, Boo, and so on. Languages said to be "scripting" are often dynamically typed ones... but I've never heard the term used for other important dynamically typed languages such as Smalltalk, Mozart/OZ, or Erlang...;-).


I know you have accepted an answer, however there is some amgiguity.

When referring to a scripting engine, we typically mean a small embedded language that sits within a template and generates textual output or documents. For example Freemarker and Velocity are often referred to as scripting engines. Erb would sit here too, but oddly is not referred to as a scripting engine that often.

A scripting language generally needs no compile step, therefore can be run more simply as a, or, from a shell script. This includes things like awk, perl, tcl, python, ruby and so on. These languages typically need to be terse and type safety is often optional. Windows supports a number of languages in it's scripting host facilities. This exposes scripting languages to various components within Windows.

So then fully compiled languages such as Java may well run as bytecode and could be considered as interpreted, however the point is that there is an explicit compile step, there is no interpreter (with the Sun JRE anyway) that provides a runtime executable environment for java code.

Other languages such as VBA are embedded, many of the languages above can be embedded. Embedded languages could be referred too as a scripting engine for the host application.

In my mind a scripting engine interprets programmatic instructions and in turn instructs a larger host application or system. The instructions are executed immediately without concern for any remaining instructions.

Many Lisps have no distinction between data and code, possibly compiling dynamically at runtime. The interpret, compile and execute steps are available to the Lisp programmer to be manipulated as programmers manipulate data in other languages.


Probably the closest thing to what you are talking about is an interpreter:

In computer science, an interpreter normally means a computer program that executes, i.e. performs, instructions written in a programming language. While interpretation and compilation are the two principal means by which programming languages are implemented, these are not fully distinct categories, one of the reasons being that most interpreting systems also perform some translation work, just like compilers.

Basically an intepreter (or scripting engine if you prefer) is the component that is responsible for turning a script into machine code at execution time (as opposed to a compiler which creates machine code prior to execution time).


"Scripting language" might be called a colloquialism. The term is not well defined, and you will see some disagreement about which languages are scripting languages. It is sometimes useful for conveying a vague idea of the properties of a language (See steveha's answer).

"Scripting language" might also refer to a particular use of a language. For example, a piece of software might use Lua as its scripting language -- the language used by the end user to automate (or "script") complex tasks.


One useful distinction between scripting / interpreted languages and compiled languages is that you can typically embed a scripting language's interpreter in a compiled project, such as a game engine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜