有人能解释一下脚本语言和程序设计语言的区别吗? 你也可以举一些例子。我谷歌了很多,但我总是从Stack Overflow找到最好的答案。
当前回答
如果我们从逻辑上看编程语言和脚本语言,这是99.09%相同的。因为我们使用相同的概念,如循环、控制条件、变量等等,所以我们可以说两者都是相同的,但它们之间只有一件事是不同的,那就是在C/ c++和其他编程语言中,我们在执行前编译代码。但在PHP, JavaScript和其他脚本语言中,我们不需要编译,我们直接在浏览器中执行。
谢谢 Nitish K. Jha
其他回答
在世界还很年轻的时候,在PC世界中,你可以从。exe或。bat中选择,描述很简单。Unix系统一直都有shell脚本(/bin/sh, /bin/csh, /bin/ksh等)和编译语言(C/ c++ /Fortran)。
To differentiate roles and responsibilities, the compiled languages (often referred to as 3rd Generation Languages) were seen a 'programming' languages and 'scripting' languages were seen as those that invoked an interpreter (often referred to as 4th Generation Languages). Scripting languages were often used as 'glue' to connect between multiple commands/compiled programs so that the user didn't have to worry about a set of steps in order to carry out their task - they developed a single file, that delineated what steps they wanted to accomplish, and this became a 'script' for anyone to follow.
Various people/groups wrote new interpreters to solve a specific problem domain. awk is one of the better-known ones, and it was used mostly for pattern matching and applying a series of data transforms on input. It worked well, but had a limited problem domain. The expansion of that domain was all but impossible because the source code was unavailable. Perl (Larry Wall, principle author/architect) tool scripting to the next level - and developed an interpreter that not only allowed the user to run system commands, manipulate input and output data, supported typeless variables, but also to access Unix system level APIs as functions from within the scripts themselves. It was probably one of the first widely used high-level scripting languages. It is with Perl (IMHO) that scripting languages crossed the arbitrary line and added the capabilities of programming languages.
你的问题是关于Python的。因为python解释器是针对包含python代码的文本文件运行的,而且python代码可以在任何有python解释器的地方运行,所以我认为它是一种脚本语言(与Perl相同)。您不需要为每个不同的OS/CPU架构重新编译用户python命令文件(就像使用C/ c++ /Fortran一样),这使得它更易于移植和使用。
这个答案要归功于杰罗德·海曼(Jerrold Heyman)。 原帖:https://www.researchgate.net/post/Is_Python_a_Programming_language_or_Scripting_Language
我认为你所说的“差异”实际上是真实差异的结果。
实际的区别在于所编写代码的目标。谁来运行这段代码。
脚本语言用于编写针对软件系统的代码。它将对软件系统进行自动化操作。脚本将是目标软件系统的指令序列。
编程语言的目标是计算系统,可以是真实的也可以是虚拟机。指令是由机器执行的。
当然,真正的机器只理解二进制代码,因此您需要编译编程语言的代码。但这是针对机器而不是程序的结果。
另一方面,脚本的目标软件系统可以编译代码或解释它。由软件系统决定。
如果我们说真正的区别是它是否被编译,那么我们就有一个问题,因为Javascript在V8中运行时是编译的,而在Rhino中运行时不是。
由于脚本语言已经进化得非常强大,所以它变得更加令人困惑。因此,它们不局限于创建小脚本来自动化另一个软件系统上的操作,您可以使用它们创建任何丰富的应用程序。
Python代码以解释器为目标,因此我们可以说它“脚本化”了解释器上的操作。但是,当你编写Python代码时,你不会将其视为编写解释器脚本,而是将其视为创建应用程序。解释器只是用于在更高级别上编写代码。所以对我来说,Python更像是一种编程语言,而不是脚本语言。
脚本语言是不需要显式编译步骤的编程语言。
例如,在正常情况下,必须先编译C程序才能运行它。但在正常情况下,在运行JavaScript程序之前不必编译它。所以JavaScript有时被称为“脚本”语言。
随着现代硬件和现代编译技术的发展,编译的速度越来越快,这条界限变得越来越模糊。例如,谷歌Chrome中的JavaScript引擎V8(在浏览器之外也经常使用)实际上是将JavaScript代码实时编译为机器代码,而不是解释它。(实际上,V8是一个优化的两阶段编译器。)
Also note that whether a language is a "scripting" language or not can be more about the environment than the language. There's no reason you can't write a C interpreter and use it as a scripting language (and people have). There's also no reason you can't compile JavaScript to machine code and store that in an executable file (and people have). The language Ruby is a good example of this: The original implementation was entirely interpreted (a "scripting" language), but there are now multiple compilers for it.
一些“脚本”语言的例子(例如,传统上使用的语言没有显式的编译步骤):
Lua JavaScript VBScript和VBA Perl
还有一小部分传统上用于显式编译步骤的代码:
C c++ D Java(但请注意Java被编译为字节码,然后在运行时解释和/或重新编译) 帕斯卡
...然后你就有了像Python这样的东西,它们在两个阵营中都有:Python被广泛使用,没有编译步骤,但主要实现(CPython)是通过动态编译字节码,然后在VM中运行字节码来实现的,它可以将字节码写入文件(。Pyc, .pyo),无需重新编译即可使用。
这只是极少数,如果你做一些研究,你会发现更多。
在脚本语言(JavaScript和旧的PHP版本)中,我们使用现有的基本函数和方法来执行我们的工作。 让我们以JavaScript为例,我们可以使用ajax或web-sockets,只有当它们被浏览器支持或方法存在或它们在浏览器中。但在C或c++、Java等语言中,我们可以从头开始编写该功能,即使该功能的任何库都不可用,但在JavaScript中我们不能这样做。
你能在ie8或之前版本的浏览器中使用JavaScript支持web-socket吗 但是你可以用C或c++或Java编写一个插件,它可以为Internet Explorer 8添加web-socket的功能。
基本上,在脚本语言中,我们按顺序编写代码,以执行现有的方法来完成我们的工作。在数字计算器中输入数字和公式来进行运算也是脚本语言的一个很好的例子。我们应该注意到,每种脚本语言的编译器/运行时环境总是用编程语言编写的,我们可以在编程语言中添加更多的特性和方法,并可以编写新的库。
PHP 这是一种有点b/w编程和脚本的语言。我们可以通过添加用另一种高级语言编写的编译扩展来添加新方法。我们不能直接在PHP中添加网络的高级特性或创建图像处理库。
附:我真的很抱歉把我的答案围绕PHP JavaScript,但我使用这两个,因为我在这两个方面有相当丰富的经验。
所有脚本语言都是编程语言。
语言并不被归类为脚本——这完全取决于执行环境。
如果环境是解释环境,则通常称为脚本环境。