[Tutor] what is the difference between a scripting and object oriented programming language?

Magnus Lyckå magnus@thinkware.se
Tue Jun 3 06:45:25 2003


At 15:41 2003-06-02 -0600, Nick Jensen wrote:
>I dabbled in Java just a little bit so I have an idea of what object 
>oriented programming is although I'm not good at it. I know that python is 
>a scripting language, but I'm not sure what that means exactly as opposed 
>to OOP.

Putting labels on things is always risky...

Python is just as OO as C++, i.e. OO is supported, but not mandatory.

>What is the definition of a scripting language?

A problem with the term "scripting language" is that it's very
poorly defined. Some equate it with interpreted languages, but many
interpreted languages have never been called scripting languages.
See for instance http://c2.com/cgi/wiki?ScriptingLanguage for some
discussions on what it might possibly mean.

Some characteristics of traditional unix scripting languages such
as korn shell or bourne shell are that they are:
   * More abstract and high level than C, Java etc. You don't
     need to write so many lines of code, and you don't need
     to declare all variables etc.
   * Mainly used for small "scripts" that typically call
     external programs that get the hard work done, i.e. the
     script "glues" a number of programs together.
   * Interpreted as you go. No compilation takes place.
   * What you execute is actually the source code. Since there
     is no compilation, you don't get any binary file.

Perl tried to be some kind of unix super script that did all
that korn shell etc did, but also did a lot of the things that
korn shell scripts would call external programs like awk to do.

Python was initially intended to serve more or less the same niche,
but it's grown a lot since then, and it is certainly more like Java
than like Korn Shell. It never "imitated" the unix shell scripts, but
got it's influences from other languages (ABC, Modula-3, C etc).

It's like shell scripts in that it uses a higher level of abstraction.
You get more done in fewer lines. Also, like in shell scripts, you don't
*see* any compilation, since that it done automatically when you import
a python module, but just like Java, Python is compiled to byte code.
The code is *not* interpreted line by line.

You can distribute and run either a source file (.py) as you would with
shell scripts, or a byte compiled file (.pyc) as you would with Java.

Unlike shell scripts, Python programs don't usually contain a lot of
calls of external programs. Instead, it has a very rich standard library.

Like shell script, python statements can be run interactively in an
interpreter, but the Python interpreter is not intended to be a working
interface (shell) to the operating system that you use to start various
programs etc in.

Object-oriented programming is an approach to organizing code and data
structures in a program. It does not have anything to do with scripting
or not.

Dividing programming languages into: Procedural, Functional, Scripting
and Object-oriented, is a bit like dividing my thing into Red Things,
Small Things, Hard things and Wet Things.

>Does it relate to scripts at all like those that you'd run on a server for 
>instance to automate certain tasks? I'm actually a network admin and use 
>scripts sometimes, but was curious how that ties in with python.

Well, as you probably understand by now, the relation to unix bourne
shell scripts and windows batch files is fairly thin.

Many people do use Python for system and network administration. You
should note that Python is *not* shell though. For instance, in a unix
shell you can "source" scripts, so that they are executed in the same
process as the interactive shell. That means that they can change the
environment of the shell. Python scripts can't do that.

>Also, what are the benefits and drawbacks to a scripting language as 
>opposed to OOP languages?

Never mind scripting languages and OOP languages. What you are
asking is like: "Are red things better than heavy things?"

Python is a much better language than Java, in most regards.

This doesn't mean that Perl is better than C++ or anything like
that.


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language