\chapter*{Preface} 
\label{preface}

Congratulations!

Now, I'll bet you are thinking that the reason I'm congratulating you is
because you've chosen to learn one of the most elegant, powerful
programming languages out there.  Well, that indeed calls for
celebration, but the \underline{real} reason I'm congratulating you is
that, by virtue of actually bothering to read a book's preface (this
one), you obviously belong to that very rare breed of readers---the
thoughtful, discerning and creative ones!

So, here in this preface I will lay out what Python is, what I am aiming
to accomplish in this book, and how to use the book.

\section*{What Are Scripting Languages?}

Languages like C and C++ allow a programmer to write code at a very
detailed level which has good execution speed (especially in the case of
C).  But in most applications, execution speed is not important---why
should you care about saving 3 microseconds in your e-mail
composition?---and in many cases one would prefer to write at a higher
level.  For example, for text-manipulation applications, the basic unit
in C/C++ is a character, while for languages like Python and Perl the
basic units are lines of text and words within lines.  One can work with
lines and words in C/C++, but one must go to greater effort to
accomplish the same thing.  So, using a scripting language saves you
time and makes the programming experience more pleasant.

The term {\it scripting language} has never been formally defined, but
here are the typical characteristics:

\begin{itemize}

\item Very casual with regard to typing of variables, e.g. little or no
distinction between integer, floating-point or character string
variables.  Functions can return nonscalars, e.g. arrays.  Nonscalars
can be used as loop indexes, etc.

\item Lots of high-level operations intrinsic to the language, e.g.
string concatenation and stack push/pop.

\item Interpreted, rather than being compiled to the instruction set of
the host machine.

\end{itemize}

\section*{Why Python?}

The first really popular scripting language was Perl.  It is still in
wide usage today, but the languages with momentum are Python and the
Python-like Ruby.  Many people, including me, greatly prefer Python to
Perl, as it is much cleaner and more elegant.  Python is very popular
among the developers at Google.

Advocates of Python, often called {\it pythonistas}, say that Python is
so clear and so enjoyable to write in that one should use Python for all
of one's programming work, not just for scripting work.  They believe it
is superior to C or C++.\footnote{Again, an exception would be
programs which really need fast execution speed.}  Personally, I believe
that C++ is bloated and its pieces don't fit together well; Java is
nicer, but its strongly-typed nature is in my view a nuisance and an
obstacle to clear programming.  I was pleased to see that Eric Raymond,
the prominent promoter of the open source movement, has also expressed
the same views as mine regarding C++, Java and Python.

\section*{How to Use This Tutorial} 

\subsection*{Background Needed}

Anyone with even a bit of programming experience should find the
material through Section 1.6 to be quite accessible.  

The material beginning with Section \ref{oop} will feel quite
comfortable to anyone with background in an object-oriented programming
(OOP) language such as C++ or Java.  If you lack this background, you
will still be able to read these sections, but will probably need to go
through them more slowly than those who do know OOP; just focus on the
examples, not the terminology.

There will be a couple of places in which we describe things briefly in
a Linux context, so some Linux knowledge would be helpful, but it
certainly is not required.  Python is used on Windows and Macintosh
platforms too, not just Linux.  (Most statements here made for the Linux
context will also apply to Macs.)

\subsection*{Approach}

{\bf \large My approach here is different from that of most Python
books, or even most Python Web tutorials.}  The usual approach is to
painfully go over all details from the beginning, with little or no
context.  For example, the usual approach would be to first state all
possible forms that a Python integer can take on, all possible forms a
Python variable name can have, and for that matter how many different
ways one can launch Python with.  

I avoid this here.  Again, the aim is to enable the reader to quickly 
acquire a Python foundation.  He/she should then be able to delve directly
into some special topic if and when the need arises.  So, if you want to
know, say, whether Python variable names can include underscores, you've
come to the wrong place.  If you want to quickly get into Python
programming, this is hopefully the right place.

\subsection*{What Parts to Read, When}

I would suggest that you first read through Section 1.6, and then give
Python a bit of a try yourself.  First experiment a bit in Python's
interactive mode (Section \ref{interactive}).  Then try writing a few
short programs yourself.  These can be entirely new programs, or merely
modifications of the example programs presented
below.\footnote{\label{exs} The raw {\bf .tex} source files for this
book are downloadable at
\url{http://heather.cs.ucdavis.edu/~matloff/Python/PLN}, so you don't
have to type the programs yourself.  You can edit a copy of this file,
saving only the lines of the program example you want.

But if you do type these examples yourself, make sure to type exactly
what appears here, especially the indenting.  The latter is crucial, as
will be discussed later.} 

This will give you a much more concrete feel of the language.  If your
main use of Python will be to write short scripts and you won't be using
the Python library, this will probably be enough for you.  However, most
readers will need to go further, acquiring a basic knowledge of Python's
OOP features and Python modules/packages.  So you should next read
through Section \ref{except}.

The other chapters are on special topics, such as files and directories,
networks and so on.

Don't forget the chapter on debugging!  Read it early and often.

\section*{My Biases}

Programming is a personal, creative activity, so everyone has his/her
own view.  (Well, those who slavishly believe everything they were
taught in programming courses are exceptions, but again, such people are
not reading this preface.)  Here are my biases as relates to this book:

\begin{itemize}
 
\item I don't regard global variables as evil.

\item GUIs are pretty, but they REALLY require a lot of work.  I'm the
practical sort, and thus if a program has the required functionality in
a text-based form, it's fine with me.

\item I like the object-oriented paradigm to some degree, especially
Python's version of it.  However, I think it often gets in my way,
causing me to go to a very large amount of extra work, all for little if
any extra benefit.  So, I use it in moderation.

\item Newer is not necessarily better.  Sorry, no Python 3 in this book.
I have nothing against it, but I don't see its benefit either.  And
anyway, it's still not in wide usage.

\item Abstraction is not necessarily a sign of progress.  This relates
to my last two points above.  I like Python because it combines power
with simplicity and elegance, and thus don't put big emphasis on the
fancy stuff like decorators.

\end{itemize}

