10

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 difference.

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.

Community
  • 1
  • 1
zxcvbnm
  • 1,833
  • 3
  • 27
  • 35
  • 5
    Yes, typical implementations of Java (and C#) run bytecode in a virtual machine, aka interpreter, just like typical implementations of Python or Ruby (indeed it can be the _same_ interpreter;-). So the distinction is rather badly-founded, as you've noticed. – Alex Martelli Nov 06 '09 at 23:36
  • 1
    Java is not an interpreted language. You have a compiler called javac and (virtual) machine object binaries called class files. – alphazero Nov 06 '09 at 23:41
  • 1
    Java is not considered an interpreted language. You write Java code, then you have an explicit compile step, where the Java code is turned into bytecodes. The bytecodes are then interpreted in the Java Virtual Machine. Usually when people say "interpreted language" they mean a language where you can just run your code directly without an explicit compile step. (The "interpreter" might use Just-In-Time compilation as a speed optimization.) It's fuzzy: even languages everyone agrees are "compiled" languages, like C, can have interpreters. (Google search for "C interpreter"!) – steveha Nov 06 '09 at 23:54
  • 4
    Python does the exact same thing, only you don't notice. You can tell it to just compile a file, and you get a .pyc bytecode, which is essentially compiled Python. – Javier Nov 06 '09 at 23:55

6 Answers6

12

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.

steveha
  • 74,789
  • 21
  • 92
  • 117
  • 1
    agreed mostly, except on point #1: it's not really true; the only language I know of that's not garbage collected is C/C++. – hasen Nov 07 '09 at 09:43
  • 3
    @hasanj, what do you mean "it's not really true"? I claimed that any language that requires you to `malloc()` and `free()` memory yourself is disqualified as a "scripting language". I made no claims that "non-scripting languages" must force you to manage memory. – steveha Nov 07 '09 at 22:47
  • @hasanj, if you look into it, you will find many languages that are not garbage collected. FORTRAN, Pascal, and C/C++ all come to mind, but there are many. AWK was a big deal to me when I first learned about it, because you didn't even have to declare how long a list would be; you could just keep adding to it whenever you wanted! It's true that many modern languages are going to garbage collection, but lack of garbage collection was a big deal when the "scripting languages" first started to appear. Read the "Historical Overview" here: http://en.wikipedia.org/wiki/Scripting_language – steveha Nov 08 '09 at 07:34
  • +1 for "coerce types with wild abandon" -- not often that I have cause to laugh whilst reading SO ... – Ed Graham Oct 16 '13 at 12:52
  • @EdGraham thank you! :-) The point I was trying to make is that many people think that Python is weakly typed because you can rebind a variable name from any type to any type. It's actually strongly typed, as you will find if you try to do `1 + "2"`. But JavaScript will return 3 for `1 + "2"`... wild. (It is true that Python is "dynamically typed" rather than "statically typed" but it is not true that it is weakly typed.) – steveha Dec 24 '13 at 07:11
  • 1
    @steveha -- indeed. Your point is very clear and your style of writing both expressive and informative. Keep up the good work! – Ed Graham Dec 31 '13 at 00:40
  • 1
    @steveha Too many people confuse "dynamically typed" (variables not caring what the type of their value is) and "weakly typed" (things will be coerced to the appropriate type, or something equivalent, and only if _that's_ impossible will it fail); and, similarly, "strictly typed" (variables do care what type their value is, and you can only have one type per value) and "strongly typed" (things aren't coerced at all; if they don't fit the bill, it's an error) – Nic Sep 13 '18 at 19:55
6

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...;-).

Alex Martelli
  • 854,459
  • 170
  • 1,222
  • 1,395
3

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.

wentbackward
  • 546
  • 3
  • 11
2

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).

Andrew Hare
  • 344,730
  • 71
  • 640
  • 635
0

"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.

Community
  • 1
  • 1
Steve S
  • 5,256
  • 1
  • 29
  • 26
0

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.

Parappa
  • 7,566
  • 3
  • 34
  • 38