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

An important difference is strong typing (versus weak typing). Scripting languages are often weakly typed, making it possible to write small programs more rapidly. For large programs this is a disadvantage, as it inhibits the compiler/interpreter to find certain bugs autonomously, making it very hard to refactor code.

查看更多
一夜七次
3楼-- · 2019-01-03 12:10

In My Opinion, I would say that dynamically interpreted languages such as PHP, Ruby, etc... are still "normal" langauges. I would say that examples of "scripting" languages are things like bash (or ksh or tcsh or whatever) or sqlplus. These languages are often used to string together existing programs on a system into a series of coherent and related commands, such as:

  1. copy A.txt to /tmp/work/
  2. run the nightly cleanup process on the database server
  3. log the results and send them to the sysdamin

So I'd say the difference (for me, anyway) is more in how you use the language. Languages like PHP, Perl, Ruby could be used as "scripting languages", but I usually see them used as "normal languages" (except Perl which seems to go both ways.

查看更多
欢心
4楼-- · 2019-01-03 12:11

I think Mr Roberto Ierusalimschy has a very good answer or the question in 'Programming in Lua':

However, the distinguishing feature of interpreted languages is not that they are not compiled, but that any compiler is part of the language runtime and that, therefore, it is possible (and easy) to execute code generated on the fly

查看更多
戒情不戒烟
5楼-- · 2019-01-03 12:12

I prefer that people not use the term "scripting language" as I think that it diminishes the effort. Take a language like Perl, often called "scripting language".

  • Perl is a programming language!
  • Perl is compiled like Java and C++. It's just compiled a lot faster!
  • Perl has objects and namespaces and closures.
  • Perl has IDEs and debuggers and profilers.
  • Perl has training and support and community.
  • Perl is not just web. Perl is not just sysadmin. Perl is not just the duct tape of the Internet.

Why do we even need to distinguish between a language like Java that is compiled and Ruby that isn't? What's the value in labeling?

For more on this, see http://xoa.petdance.com/Stop_saying_script.

查看更多
贪生不怕死
6楼-- · 2019-01-03 12:13

A scripting language is a language that configures or extends an existing program.
A Scripting Language is a Programming language.

查看更多
beautiful°
7楼-- · 2019-01-03 12:15

There's a lot of possible answers to this.

First: it's not really a question of the difference between a scripting language and a programming language, because a scripting language is a programming language. It's more a question of what traits make some programming language a scripting language while another programming language isn't a scripting language.

Second: it's really hard to say what a XYZ language is, whether that XYZ be "scripting", "functional programming", "object-oriented programming" or what have you. The definition of what "functional programming" is, is pretty clear, but nobody knows what a "functional programming language" is.

Functional programming or object-oriented programming are programming styles; you can write in a functional style or an object-oriented style in pretty much any language. For example, the Linux Virtual File System Switch and the Linux Driver Model are heavily object-oriented despite written in C, whereas a lot of Java or C# code you see on the web is very procedural and not object-oriented at all. OTOH, I have seen some heavily functional Java code.

So, if functional programming and object-oriented programming are merely styles that can be done in any language, then how do you define an "object-oriented programming language"? You could say that an object-oriented programming language is a language that allows object-oriented programming. But that's not much of a definition: all languages allow object-oriented programming, therefore all languages are object-oriented? So, you say, well a language is object-oriented, if it forces you to programming in an object-oriented style. But that's not much of a definition, either: all languages allow functional programming, therefore no language is object-oriented?

So, for me, I have found the following definition:

A language is a scripting language (object-oriented language / functional language) if it both

  • facilitates scripting (object-oriented programming / functional programming), i.e. it not only allows it but makes it easy and natural and contains features that help with it, AND
  • encourages and guides you towards scripting (object-oriented programming / functional programming).

So, after five paragraphs, I have arrived at: "a scripting language is a language for scripting". What a great definition. NOT.

Obviously, we now need to look at the definition of "scripting".

This is where the third problem comes in: whereas the term "functional programming" is well-defined and it's only the term "functional programming language" that is problematic, unfortunately with scripting, both the term "scripting" and the term "scripting language" are ill-defined.

Well, firstly scripting is programming. It's just a special kind of programming. IOW: every script is a program, but not every program is a script; the set of all scripts is a proper subset of the set of all programs.

In my personal opinion, the thing that makes scripting scripting and distinguishes it from other kinds of programming, is that …

Scripts largely manipulate objects that

  • were not created by the script,
  • have a lifetime independent of the script and
  • live outside the domain of the script.

Also, the datatypes and algorithms used are generally not defined by the script but by the outside environment.

Think about a shell script: shell scripts usually manipulate files, directories and processes. The majority of files, directories and processes on your system were probably not created by the currently running script. And they don't vanish when the script exits: their lifetime is completely independent of the script. And they aren't really part of the script, either, they are a part of the system. You didn't start your script by writing File and Directory classes, those datatypes are none of your concern: you just assume they are there, and you don't even know (nor do you need to know) how they work. And you don't implement your own algorithms, either, e.g. for directory traversal you just use find instead of implementing your own breadth-first-search.

In short: a script attaches itself to a larger system that exists independently of the script, manipulates some small part of the system and then exits.

That larger system can be the operating system in case of a shell script, the browser DOM in case of a browser script, a game (e.g. World of Warcraft with Lua or Second Life with the Linden Scripting Language), an application (e.g. the AutoLisp language for AutoCAD or Excel/Word/Office macros), a web server, a pack of robots or something else entirely.

Note that the scripting aspect is completely orthogonal to all the other aspects of programming languages: a scripting language can be strongly or weakly typed, strictly or loosely typed, statically or dynamically typed, nominally, structurally or duck typed, heck it can even be untyped. It can be imperative or functional, object-oriented, procedural or functional, strict or lazy. Its implementations can be interpreted, compiled or mixed.

For example, Mondrian is a strictly strongly statically typed lazy functional scripting language with a compiled implementation.

However, all of this is moot, because the way the term scripting language is really used in the real world, has nothing to do with any of the above. It is most often used simply as an insult, and the definition is rather simple, even simplistic:

  • real programming language: my programming language
  • scripting language: your programming language

This seems to be the way that the term is most often used.

查看更多
登录 后发表回答