What is difference between scripting languages and other languages [duplicate] - programming-languages

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
When is a language considered a scripting language?
I am really confused between different types of languages.
Can any one guide what are diff types of languages or diff categories.
Like some saying python is scripting langauge. Now what does that mean. Are other langueages like php , asp , java not scripting langauges

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

A scripting language is typically interpreted instead of compiled.

See scripting-and-programming,
whats-the-difference-between-a-script-and-an-application
and many similar discussions.

There are many taxonomies for classifying programming languages.
In regard to scripting, a scripting language (python, ruby, php) is a language that runs on an interpretor directly from source code.
Other languages are either compiled languages (run from binary form: c, c++, pascal) either intermediate, compiled to an intermediary form and run inside a virtual machine (java, c#).

A scripting language is a language that focuses on making it easy to chain together or manipulate other programs
Wikipedia says:
"When a language is used to give commands to a software application (such as a shell) it is called a scripting language"
"A scripting language, script language or extension language is a programming language that allows control of one or more software applications."
This is orthogonal from whether it is interpreted or otherwise - Java was originally interpreted, for example, but nobody called it a scripting language. It just happens that, if you're implementing a scripting language, interpreting it is a straightforward approach to take.
Many scripting languages are compiled, either to bytecode or to machine code, often with JIT.

The distinction between script languages and other languages is mostly between interpreted, dynamically typed languages (for example PHP, VBScript, JScript and Javascript), and compiled, statically typed languages (for example C#, VB.NET, Java, C++ and Delphi).
ASP is not a language, but a platform for scripting languages (VBScript / JScript), while ASP.NET is a platform for compiled languages (mainly C# / VB.NET).

Related

Explain how information flows between programming languages, for beginning programmers

I am an autodidact, teaching myself how to program and script in different languages (novice in: Java, C++, Javascript/Node.js, HTML/CSS), design projects and schematics, adding electronics and peripherals.
What I have seen a lot of while researching is the use of multiple languages to achieve a set of goals (such as building a Web server in Javascript/Node to handle HTTP requests and responses, responding with a Web page written in HTML and customized/stylized with CSS and embedded with Javascript mannerisms; or instead of Node, you write it in PHP or Python).
I'm having a hard time wrapping my mind around WHY multiple languages are used instead of just one (some high-level languages are capable of performing a large portion, if not all, of the required tasks) and HOW information is passed in between the different languages. Could one program call another (I know that an HTML file can make "calls" to CSS and Javascript files, so, I understand that instance)?
I think the reason why I am hung up on this is because of my inexperience and lack of knowledge of other common languages. Does that mean that certain languages are meant to handle only specific tasks in a specific manner?
I feel like some languages, such as Java and C++, for example, can be used in various ways and in various instances to handle a myriad of different tasks. Is that not true of some of the others (PHP & Python, for instance)?
I'm digging into the wealth of knowledge and the collective experience of some of the most brilliant minds this world has to offer but remember that I am new to this and I don't have the advantage of doing this in a classroom but I have read and own many books on programming in specific languages and the like. Please answer in a way that I and the others that may follow can understand.
Thank you for your time and I look forward to the responses.
Cheers.
Fantastic answers!
I'm curious though; when working towards a solution for a specific problem, when does the programmer know when to stop in one language and continue a segment in another language?
That's where I am confused. Is it typically up to the software developer and his/her own particular and artistic preference on how something is done or are certain things just not possible without using multiple languages?
I do understand scripting and when it's beneficial to use rather than a program or application and I know runtime execution/compiled code, environments and frameworks and virtual machines but none of that clearly lays out a defined perimeter or a limit in functionality/ability for any particular language. Why call a C++ function in Python? Could Python not accomplish what was needed in the first place and could choosing a more appropriate language have mitigated the need for adding another level of complexity to the solution? I may be overthinking it but knowing this will guide me in my learning and help me map out better solutions as a programmer.
Basically the different technologies (browsers, operating systems etc) and with it programming languages evolved over time so that there are many different languages used in practice. For the same reason that there are multiple real languages. You could design a web browser that supports Python instead of JavaScript for front-end programming, but this would involve designing the APIs the scripts use to access the pages (DOM HTML model), it would need to be supported by all major web browsers, standardized, and web developers would need to use it.
Yes in many cases it is possible for programs written in one language to call programs written in another languages. There needs to be some kind of interface connecting the two parts, depending on the context. For example:
C and C++ are both compiled languages. That is, they get translated into machine code to be executed by the processor. The positions in the machine code where code for one function is located are stored with it. The linker of the operating system is responsible for linking two modules (.c files) such that function calls made in one module towards a function defined in the other result in the right machine code being loaded. For a C++ program to call a C program, one problem (many others) is that functions are named differently (name mangling). In practice the functions from the C program would need to be declared extern "C" in the C++ source code for the linker to set this up correctly.
JavaScript, CSS and HTML are interpreted and executed (for JavaScript) by the browser, but not necessarily translated into machine code. (JavaScript engined may use Just-in-time compilation). So the browser provides possibilities for the JavaScript code to access the CSS definition, for example. .style.color = ....
For scripting languages like Perl, PHP, Python etc to call each other, different libraries exist that handle the necessary intermediate steps ("glue code"). There are many possibilities, for instance the PHP code could invoke the Python interpreter to execute a Python program, or it could pass data to a running Python program through the operating system's mechanisms etc.
Wrappers such as SWIG allow C/C++ code to be called from scripting languages. They add the necessary symbols (functions) to the code that Python would call internally. Than the C++ program is compiled as a Python extension, which is loaded by the Python interpreter, itself a compiled program, and the operating system's linker is used. The Python interpreter then interprets Python code in such a way that calling a given Python function results in the machine code of the extension's wrapper function to be executed.
There are many ways to classify programming languages into categories. For example from low level (machine code) to higher level (more abstraction, translation to machine code handled automatically):
Assembly (for expressing machine code instructions)
Compiled languages for system-level programming. (C, C++, Pascal, ...)
Compiled languages running in a VM (Java, C#, ...)
Scripting languages (Python, Perl, PHP, ...) Less focused on efficiency, but more flexible.
Higher domain-speficic level languages (MATLAB, AppleScript)
Shell scripting (bash, sh)
Programming is all about creating solutions to problems. People think differently. People see the world from different perspectives. People like to tweak solutions and play with tools. Languages are created by people in order to solve different problems and in some cases just for play. My response is more along the lines of 'Why would there only be one language?'.

searching good embedded & hosting language pair

I am searching for two (one?) languages. One of them would be a host, capable running some "environment", and second, which could used to script "agents" acting in this environment.
Some details:
host should be capable to run multiple "agents" (threads of embedded language), ideally capable to limit number of instructions executed by every thread at a time (though more sophisticated ways of control are welcome)
embedded threads should have access only to objects explicitly exposed by host
embedded threads should be isolated. No shared memory, all communication going via host
embedded language should be rather simple, with dynamic typing
hosting language should be rather high-level
performance is not a primary concern
I was thinking of Python being a host embedding Lua, for example Lunatic Python, or some pair of JVM languages (Scala / Groovy ?), but i'am not sure of possibilities of real isolation of embedded threads (see 2, 3). So I am searching for any ideas, frameworks, successfull implementations etc...
I think the conditions that you have listed aren't very restrictive, you are going to find a large list of pairs of host/thread scripting languages that fall within your six requirements.
So my most important recommendation is that you choose the languages that the intended users will like the most.
There are a couple of ways to approach this. If you decide to start picking a host language, then I think you have the following options:
C/C++: If your intention is to have more freedom of choice for the thread language, then having a C or C++ host will give you the most options, since most interpreted scripting languages are written in C/C++ and have easy mechanisms for embedding into C/C++ applications. Choices for thread languages could be Lua, Javascript, Python, Ruby, PHP, Basic, Scheme, Pascal, Lisp, and many many more.
Java: With Java as a host language you have a short number of scripting languages that are embed friendly. Here is a list.
.NET: I would only go with this if you intend to run on Windows and nothing else, if not I would avoid it. Like Java, you'll find a list of interpreters that can be embedded in a .NET application.
Something else: If you don't like C/C++ or Java as a host language, then you'll have to decide what kind of host language you like, but no matter the choice, you will have a very limited set of options for an embedded language. You suggested Python as a possible host language, which I think is a decent choice. I would advise against using Lua over Python though, that could be a debugging nightmare should you ever need to debug at the language VM level. Instead, I can offer two suggestions: (1) also use Python for the thread language, then you have a nice uniform language across the entire system; (2) find a scripting language that has a native interpreter written in Python (there aren't many that I know of). Instead of Python, you can go with Ruby, PHP, or any other major scripting language for the host, but in all cases you'll have not many options for the embedded language.
Now, instead of looking for a host language, you could pick the embedded language first, then find a host language that can embed that language. You suggested Lua as an embedded language, which is also a very good option. If you are set on using Lua, then I think C or C++ should be your host language, as that will give you the best embedding experience.
To summarize, I recommend one of two following approaches to choosing your pair of languages:
(a) pick a pair of languages where the embedded language interpreter is implemented in the host language. Examples: Lua and C++, Javascript and C++, Python and C++, Scheme and C++, Jython and Java, JRuby and Java, Rhino and Java, etc.
or
(b) pick the same high level scripting language for host and threads, and work on an unified platform without embedded scripting. Examples: Python and Python, Lua and Lua, Ruby and Ruby, etc.
Good luck with your search!
You could also use Common Lisp in particular thru its SBCL implementation.
Using javascript/v8 as the embedded language, and c++ as the host language might be a good solution. See this for how to embed.
V8 provides Contexts, each of which has its own Security Context. These allow you to create multiple separate threads for different clients, each of which is in their own sandbox.
Another alternative is java/javascript(rhino) which also allows embedding. Limiting access to other objects will be harder in java (you have to use a security manager), but you can limit the time a script is allowed to take, see an example in the javadocs here.
I know this question is a couple of years old now, but I'd recommend ObjectScript language.
ObjectScript, OS for short, is a new programming language. It's free, cross-platform, lightweight, embeddable and open-source. It combines the benefits of multiple languages, including: JavaScript, Lua, Ruby, Python and PHP. OS features the syntax of Javascripts, the "multiple results" feature from lua, syntactic shugar from Ruby as well as magic methods from PHP and Ruby - and even more!
A good example here is SnapScript it can be run on any Java compatible environment. In addition to the standard JRE it can also be run on Android (Dalvik and ART) without any modifications.
The IDE actually manages an agent pool for hot execution.

what are scripting languages? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
When is a language considered a scripting language?
What languages are scripting languages?? Couldn't we write scripting languages as a stand alone??
A scripting language, script language
or extension language is a programming
language that allows control of one or
more software applications. "Scripts"
are distinct from the core code of the
application, as they are usually
written in a different language and
are often created or at least modified
by the end-user. Scripts are often
interpreted from source code or
bytecode, whereas application software
is typically first compiled to a
native machine code or to an
intermediate code.
Source
There is PHP, Perl, Python, Ruby, etc. More HERE.
Scripts are ran by an interpreter, so there must be an interpreter in the Operating System for the script to run.
In my opinion a scripting language is a language that is interpreted rather than compiled.

Lua, what is Lua? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I read something about Lua today, and I was wondering what it was.
I did a Google and Wikipedia search, I understood it until they began talking about C and API. I still don't understand it.
What is Lua and are there any tutorials for beginners?
Lua is a lightweight interpreted programming language developed in Brazil with a focus on embedding.
It is written in Pure ANSI C which means high portability, even as C++ code.
Here is an example:
print("Hello World!")
Wikipedia Summary
Official Site
I'm surprised everyone is getting this one wrong.
Lua is the Hawaiian word for "toilet".
Lua is a scripting language for C and C++. It allows to use the simpler syntax of Lua and execute these scripts in your C/C++ application. Therefore you don't have to compile the program on each change, but simply deliver a new script version.
For tutorials just use google, you'll find enough to keep you busy the next days.
Lua is a simple lightweight highly portable dynamically typed embeddable and extendable multi-paradigm scripting language. The "vanilla" (some would say official) implementation of it is made purely on ANSI C and has an awesome (simple yet powerful) C API that you can use to both embed Lua on your app or extend the behavior of the language itself. It is developed at the Informatics Department of the Pontifical Catholic University of Rio de Janeiro (PUC-Rio).
Thought it was not primarily designed for that, Lua found a big niche in game scripting, with big names such as "Grim Fandango" and "World of Warcraft". Nonetheless, because of its speed, simplicity and portability, it is also heavily used in embedded systems (see, for example, eLua project) and graphic computing.
Its philosophy is to be minimalistic, i.e its core libraries are very small with only minimum functionality (quite like C's standard libraries), though through the C API it is very simple to add features that wouldn't be possible through the pure core library, such as sockets, GUIs etc. In fact, Lua is so minimalistic that its main -and only- structured data type are 'tables', that could be described as associative arrays on 'roids.
Lua is procedural in its essence, but also supports multiple paradigms such as functional programming and object orientation.
Though Lua is not the fastest scripting language around (probably javascript's V8 project wins the prize) it is very fast (faster than vanilla Python or Ruby, for instance) and also features a non-official just-in-time implementation called LuaJIT.
In the end, Lua is actually no more than a fun language to play with, which I recommend!.
=)
About tutorials, I'd recommend the article about that on the lua-users wiki.
I hope I helped! =)
PS: I couldn't post all the links because I'm new on stack overflow, but it shouldn't be hard to find everything on Google. Sorry. =(
Lua is a scripting language. Link is to lua.org. It is heavily used in game development, most notably (to me) World of Warcraft.
Lua is a lightweight, embeddable scripting language. It's garnered a lot of popularity partly due to it's use in many popular games. A good example of this is World of Warcraft which uses an embedded version of lua to drive the behavior of the UI elements in the game.
A good intro to the language can be found here: http://computer-programming-languages.suite101.com/article.cfm/a_brief_introduction_to_lua_scripting
And the official online reference for the language can be found here: http://www.lua.org/manual/5.1/
It's a scripting language that is designed to work with C (and C++). It is designed to be embedded into C/C++ programs. Which means unlike a lot of other scripting languages, it makes no use of global variables and such, this means you can easily thread lua scripting engines.
It also makes claims about being the fastest dynamic scripting language.
I've made use of it in PC based C++ application for creating a plugin scripting interface, and also used it as a embedded scripting language. Its quite versitile, nice and small.
as a general purpose scripting language? Its not quite in the same league as your ruby/python/perl type stuff. It doesn't have as many libraries and the user community is pretty small.
But for extending C++/C apps? its awesome.
The C API, which looks to be the part that confused you, is designed to make it very easy for you to take existing C code (or new C code) and control it with a Lua script. This is what is meant by embedding. Via embedding, you can get a lightweight, programmable, interactive, text-based interface to any C code, for very little effort. Even if you don't embed things yourself, Lua is a very nice little scripting language.
My favorite example is that a nice person put a great many POSIX system calls into Lua. When I want something that is like a shell script but is more sophisticated, I can just use this library. Likewise with the MD5 library and with many others.
When learning Lua you can ignore the C API completely—just benefit from other people's work with the API—and if you ever need to embed your own code, you can come back to it later.
Lua is a SCRIPTING language written in C and is commonly used in game development because of its power and flexibility. Lua is also cross-platform so it can be used anywhere on any platform. Lua can also be used as a programming language with a handy program I use called AutoPlay Media Studio which allows you to create fully fledged applications for the Windows platform. I hope this clears things up for you.
Website: http://www.lua.org.
AutoPlay Media Studio: http://www.indigorose.com.
Lua is a powerful, fast, lightweight, embeddable scripting language.
Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.
for more you can read here

How do you create a computer or scripting language for an application?

Duplicate of:
Learning to write a compiler
Documentation on creating a programming language
Learning Resources on Parsers, Interpreters, and Compilers
Suggestions for writing a programming language?
Compiler-Programming: What are the most fundamental ingredients?
Are there some online resources about compiler principle?
and others I'm too lazy to find right now.
I'm not asking how to make an incredibly complex language. I just wanted to understand the basics. I would use c# as the underlying language. I know it's vague. I was hoping for something very basic to direct me.
I think I'm mostly interested in creating scripting languages. For example, I see people that write programs but then they have a scripting language for their application. I do not want to rewrite a windows scripting language. Say I had a text file reader and for some reason wanted a scripting language to automate something. I'm not sure how to ask.
Thank you.
EDIT - Thank you for the answers. I was looking at it more for the learning not the doing at the moment. I would probably use LUA, but I am trying to learn more about the concept in general.
You could take a look at LUA - I've used it to great success each time I asked myself the question "How would I automate insert task here in insert one of my apps here?"
Edit: Here are some examples (taken from the links page, admittedly, unwieldy Lua Wiki) on how you could embed Lua in your app:
Embedding Lua in C: Using Lua from inside C
Embedding a scripting language inside your C/C++ code
Embeddable scripting with Lua
You can use an existing language like Python or Javascript. For example, for Javascript, there is http://www.mozilla.org/rhino/ for Java apps. So typically you don't need to actually invent a new language, you would just provide a custom API for a language that already exists.
first you need a lexical parser like lex, then a syntax parser like bison.
then you can work with the syntax parser to create an interpreter to 'execute' the syntax results.
that's how the most scripting languages do.
p.s: another way is to practice by writing shells - shell scripts (bash, csh, or sh) are highly simplified scripting languages.
Some terminology is in order. You may be talking about a domain-specific language.
The two basic ways to transform a text file into an "executable": a compiler or an interpreter. An interpreter fits the scripting concept better, as it is easier to build and executes lines one at a time. Note that beyond a very simple language both writing a decent parser or a decent interpreter are non-trivial. The classic work on interpreters is SICP, but this is quite a hard book for beginners.
Scott Hanselman mentioned in his latest hanselminutes podcast that integrating IronPython to allow scripting of an existing application was very easy to do.
If you're interested in the end target of having your application be scriptable, then you should definitely consider using an existing language rather than attempting to write your own.
If you are more interested in the educational experience of writing your own scripting language, then you should go for it!
There's no need to create a new scripting language there are several eg. Rhino which is a widely used embeddable javascript (http://www.mozilla.org/rhino/) or Jscript from MS, that you can use directly in your product.
I've gone the way that you are asking - I once created my own scheme interpreter. This worked really well, but we re-invented a lot of technology and didn't really get a lot of additional benefit. We would have been far better off just using one of the scheme's that were available. I would not make that decision again even though it was fun and successful.

Resources