Difference between a scripting language vs programming language? [duplicate] - scripting

This question already has answers here:
Scripting Language vs Programming Language [closed]
(14 answers)
Closed 11 months ago.
Please, can anyone explain to me the diff between these two types of language?
And, can one language be these two types at the same time?

Basically, most scripting languages are programming languages, but not all programming languages are scripting languages.
The theoretical difference between the two is that scripting languages do not require a compilation step and are instead interpreted. For example, a C or C++ program normally needs to be compiled before running, whereas a scripting language like JavaScript or PHP does not need to be compiled.
Here are some of the main differences between scripting languages and programming languages.
Programming language code, when compiled, creates executable files in binary code, also called .exe files, which take up memory, whereas scripting languages do not create executable .exe files.
User interface design and graphical design are often partially supported by programming languages, whereas user interface design, data types, and graphical design are all greatly facilitated by scripting languages.
Programming languages are designed to facilitate full-fledged software development, while scripting languages are used to assist programming languages and make coding easier and faster. Scripting languages are generally used for open source projects and web development.
Programming languages are self-executable while scripting languages require a host.
Programming languages are compressed into small packages that do not need to be interpreted by another language or application, while scripting languages are written in one language and interpreted in another program. For example, JavaScript must be embedded in HTML, which is then interpreted by a web browser.

Related

Embedded SQL directly vs calling as an API

Most database applications require a host programming language to use
SQL to communicate with the database. A wide range of programming
languages can be used with SQL, from traditional languages such as
COBOL, FORTRAN, and Assembler to more modern languages such as C/C++,
Java, and Visual Basic. Your choice of host programming language can
impact the way you will have to code SQL. For example, SQL is embedded
directly into a COBOL program, whereas a language like C requires an
API like ODBC to issue SQL statements.
source: Craig S.Mullins-Database Administration The Complete Guide to Practices and Procedures
What is the difference between embedding SQL directly in the host programming language and calling as an API?
Convenience, that's all. What Mullin's comment leaves out is that COBOL language doesn't understand SQL statements so a preprocessor is used to strip them out of a program prior to compiling and replaces them with, you guessed it, API calls. I believe preprocessors exist for C as well as other languages so I don't really see where he's coming from.

What are the similarities between scripting language and programming language?

By searching I have found a similarity that is both import libraries. But unable to point out any other similarities, as everywhere I can see only differences.
Scripting languages are programming languages. Most of the programming languages in use today that once deserved the "scripting" label are complete programming environments from the syntactically, semantically, and library-wise.
At some point "scripting language" may have been used for languages that were suitable only for writing short scripts, but today any language that doesn't require a complex compilation step to run and that provides a read–eval–print loop (REPL) is considered good enough for scripting.

Are there any C-like (in syntax) scripting languages other than JavaScript and PHP?

I am looking for a general-purpose (considering PHP is actually made and initially meant (I understand they are be used different ways some times) for server side Web and JavaScript for client-side web) with C/C++/C#/Java-like syntax. Do you know of such?
Mythryl is a general-purpose scripting languages deliberately designed around C syntax.
Perhaps Pike with Fins
There's also Ch, an embeddable C/C++ interpreter.
Just look through the Comparison of programming languages, and see which ones fit your needs best. You might look at the language with dynamic Type Systems, because those are scripting languages. Hyped languages include Scala, Ruby (with the Ruby on Rails web framework), Groovy and others, if you need a start.
In general, Wikipedia's C language entry lists many: "C has directly or indirectly influenced many later languages such as Java, Perl, Python, PHP, JavaScript, LPC, C# and Unix's C Shell"
Specifically, for general-purpose "scripting" language that is very similar to C, I would strongly recommend Perl which fits the bill perfectly.
Perl's syntax (or at least a sub-set of it) is VERY C-like (to the point that ex-C programmers starting in Perl are unfortunately known to code in "C-ish Perl" style which is pretty much straight up C).
In additional to general syntax ideas, Perl supports a vast majority of C system functions and many other C-isms (e.g. fully functional printf, process control and IPC).
Perl these days is definitely a general purpose language - it is used for anything from web development (including modern frameworks like Catalyst MVC, Plack etc...), to enterprise software development including full blown servers, to system administration scripting and general "scripting" glue tasks.
In addition, it supports both Object Oriented programming (either using classic Perl OOP or using modern Moose), as well as functional programming.
Please note that when evaluating Perl, you should not rely on the numerous myths that exist out there - most of these are due to either people not being sufficiently familiar with Perl, or judging Perl based on a large mass of poor-code-quality dirty scripts written by system administrators who weren't software developers, or judging Perl based on its features in Perl versions that were popular 15 years ago (e.g. any criticism of Perl OOP circa 1998 is pretty much useless unless the person doing it is closely familiar with Moose).
P.S. Since your questions seems to be in "...coming from PHP" context, you should also note that PHP is in fact very similar to a subset of Perl - by design. To quote from php.net:
The syntax itself was similar to that of Perl, albeit much more limited, simple, and somewhat inconsistent.
Matter of fact, PHP started out as a collection of Perl CGI scripts.
I am currently working on a new project called Cpy, using Python's execution engine, but wrting codes in C-syntax. It is built with ANTLR and Python. Take a look at it: http://www.ideawu.com/cpy/
Pawn. Not general purpose (depending on your definition) but very good as a small embedded language.

Why are the interpreters of all popular scripting languages written in C (if not in C at least not in C++)?

I recently asked a question on switching from C++ to C for writing an interpreter for speed and I got a comment from someone asking why on earth I would switch to C for that.
So I found out that I actually don't know why - except that C++ object oriented system has a much higher abstraction and therefore is slower.
Why are the interpreters of all popular scripting languages written in C and not in C++?
If you want to tell me about some other language where the interpreter for it isn't in C, please replace all occurences of popular scripting languages in this question with Ruby, Python, Perl and PHP.
C is a very old language, and is thus supported on pretty much every system available. It is therefore a good choice for any project that needs to be ported everywhere.
Ruby dates back to 1995. If you were writing an interpreter in 1995, what were your options? Java was released in the same year. (And was painfully slow in v1.0 and in many ways, not really worth using)
C++ was not yet standardized, and compiler support for it was very sketchy. (it had also not yet made the transition to the "modern C++" that we use today. I think the STL was proposed for standardization around this time as well. It didn't actually get added to the standard until years later. And even after it was added, it took several more years for 1) compilers to catch up, and 2) people to get used to this generic programming style. Back then, C++ was an OOP language first and foremost, and in many cases, that style of C++ was quite a bit slower than C. (In modern C++ code, that performance difference is pretty much eliminated, partly through better compilers, and partly through better coding styles, less reliance on OOP constructs and more on templates and generic programming)
Python was started in 1991. Perl is even older (1987)
PHP is from 1995 as well, but additionally, and importantly, was created by a guy who knew virtually nothing of programming. (and yes, of course this has shaped the language in many important ways)
The languages you mention were started in C because C was the best bet for a portable, future-proof platform back then.
And while I haven't looked this up, I'm willing to bet that apart from the PHP case, which is shaped by incompetence more than anything, the language designers of the other languages chose C because they *already knew it. So perhaps the lesson is not "C is best", but "the language you already know is best"
There are other reasons why C is often chosen:
experience and accessibility: C is a simple language that is fairly easy to pick up, lowering the barrier of entry. It's also popular, and there are a lot of experienced C programmers around. One reason why these languages have become popular might just be that it was easy to find programmers to help developing the interpreters. C++ is more complex to learn and use well. Today, that might not be so much of a problem, but 10 or 15 years ago?
interoperability: Most languages communicate through C interfaces. Since your fancy new language is going to rely on components written in other languages (especially in early versions when the language itself is limited and has few libraries), it's always nice and simple to call a C function.So since we're going to have some C code anyway, it might be tempting to go all the way and just write the whole thing in C.
performance: C doesn't get in your way much. It doesn't magically make your code fast, but it allows you to achieve good performance. So does C++, of course, or many other languages. But it's true for C as well.
portability: Practically every platform has a C compiler. Until recently, C++ compilers were much more hit and miss.
These reasons don't mean that C is in fact a superior language for writing interpreters (or for anything else), they simply explain some of the motivations that have caused others to write in C.
I'd guess it's because C is pretty much the only language that has a reasonably standard compiler for almost every platform in existence.
I would hazard a guess that it's in part due to 1998 C++ not being standardized until 1998, making achieving portability that much harder.
All those languages you list were developed before that standardization.
Why are the interpreters of all popular scripting languages written in C and not in C++?
What makes you think that they are written in C? In my experience, the majority of implementations for the majority of scripting languages are written in languages other than C.
Here's a couple of examples:
Ruby
BlueRuby: written in ABAP
HotRuby: JavaScript
Red Sun: ActionScript
SmallRuby: Smalltalk/X
MagLev: Ruby, GemStone Smalltalk
Smalltalk.rb: Smalltalk
Alumina: Smalltalk
Cardinal: PIR, NQP, PGE
RubyGoLightly: Go
YARI: Io
JRuby: Java
XRuby: Java
Microsoft IronRuby: C#
the original IronRuby by Wilco Bauwer: C#
Ruby.NET: C#
NETRuby: C#
MacRuby: Objective-C
Rubinius: Ruby, C++
MetaRuby: Ruby
RubyVM: Ruby
Python
IronPython: C#
Jython: Java
Pynie: PIR, NQP, PGE
PyPy: Python, RPython
PHP
P8: Java
Quercus: Java
Phalanger: C#
Perl6
Rakudo: Perl6, PIR, NQP, PGE
Pugs: Haskell
Sprixel: JavaScript
v6.pm: Perl5
Elf: CommonLisp
JavaScript
Narcissus: JavaScript
Ejacs: ELisp
Jint: C#
IronJS: F#
Rhino: Java
Mascara (ECMAScript Harmony Reference Implementation): Python
ECMAScript 4 Reference Implementation: Standard ML
The HotSpot JVM is written in C++, the Animorphic Smalltalk VM (from which HotSpot and V8 are derived) is written in C++, the Self VM (on which the Animorphic Smalltalk VM is based) is written in C++.
Interestingly enough, in many of the above cases, the implementations that are not written in C, are actually faster than the ones written in C.
As an example of two implementations that are written in C, take Lua and CPython. In both cases, they are actually written in a small subset of a very old version of C. The reason for this is that they want to be highly portable. CPython, for example, runs on platform for which a C++ compiler doesn't even exist. Also, Perl was written in 1989, CPython in 1990, Lua in 1993, SpiderMonkey in 1995. C++ wasn't standardized until 1998.
The complexity of C++ is great compared to that of C - many people consider it one of the most complex and error prone languages in existance.
Many of the features of C++ are problematic as well - the STL was standardized many years ago and it still lacks one great implementation.
OOP is certainly great, but it does not outweigh C++'s deficiencies in many scenarios.
Most known compiler books are written with examples in C.
Also two of the major tools lexx (builds a lexer) and yacc (Translates a grammar to C) have support for C.
If the question is about why C and not C++ the answer comes down to the fact that when you implement a scripting language the C++ object model comes into your way. Its so restricted that you will not be able to use it for your own objects.
So you can only use this for the internals and they there you usually do not get enough benefits from C++ over the much simpler C language, which makes it easier to port and distribute.
The only problem when implementing a script language in C are missing coroutine support (you have to switch your stack pointer in some way) and most important there is no way to do exception handling without a lot of overhead (compared to C++).

Is Objective-C a 3GL or 4GL?

I'm having a little debate with a friend about Objective-C being a 3GL but he believes it is a 4GL because descriptors make the language english like.
I disagree with this and I know it is sometimes a fine line.
Is Objective-C a third generation language or a fourth generation language?
References to support your answer will be appreciated.
According to the wikipedia definition of a 4gl language:
"A fourth-generation programming language (1970s-1990) (abbreviated 4GL) is a programming language or programming environment designed with a specific purpose in mind, such as the development of commercial business software[1]. In the evolution of computing, the 4GL followed the 3GL in an upward trend toward higher abstraction and statement power. The 4GL was followed by efforts to define and use a 5GL."
Objective-C is definitely not 4gl. It is a superset of C with full object oriented support and dynamic binding. Although mainly used to develop on OS X systems it can be used on *nix as an alternative to c++.