274 lines
6.2 KiB
HTML
274 lines
6.2 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<HTML
|
|
><HEAD
|
|
><TITLE
|
|
>How do computer languages work?</TITLE
|
|
><META
|
|
NAME="GENERATOR"
|
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
|
|
REL="HOME"
|
|
TITLE="The Unix and Internet Fundamentals HOWTO"
|
|
HREF="index.html"><LINK
|
|
REL="PREVIOUS"
|
|
TITLE="How does my computer store things on disk?"
|
|
HREF="disk-layout.html"><LINK
|
|
REL="NEXT"
|
|
TITLE="How does the Internet work?"
|
|
HREF="internet.html"></HEAD
|
|
><BODY
|
|
CLASS="sect1"
|
|
BGCOLOR="#FFFFFF"
|
|
TEXT="#000000"
|
|
LINK="#0000FF"
|
|
VLINK="#840084"
|
|
ALINK="#0000FF"
|
|
><DIV
|
|
CLASS="NAVHEADER"
|
|
><TABLE
|
|
SUMMARY="Header navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TH
|
|
COLSPAN="3"
|
|
ALIGN="center"
|
|
>The Unix and Internet Fundamentals HOWTO</TH
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="left"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="disk-layout.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="80%"
|
|
ALIGN="center"
|
|
VALIGN="bottom"
|
|
></TD
|
|
><TD
|
|
WIDTH="10%"
|
|
ALIGN="right"
|
|
VALIGN="bottom"
|
|
><A
|
|
HREF="internet.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
></TABLE
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"></DIV
|
|
><DIV
|
|
CLASS="sect1"
|
|
><H1
|
|
CLASS="sect1"
|
|
><A
|
|
NAME="languages"
|
|
></A
|
|
>11. How do computer languages work?</H1
|
|
><P
|
|
>We've already discussed <A
|
|
HREF="running-programs.html"
|
|
>how programs
|
|
are run</A
|
|
>. Every program ultimately has to execute as a stream of
|
|
bytes that are instructions in your computer's <I
|
|
CLASS="firstterm"
|
|
>machine
|
|
language</I
|
|
>. But human beings don't deal with machine
|
|
language very well; doing so has become a rare, black art even among
|
|
hackers.</P
|
|
><P
|
|
>Almost all Unix code except a small amount of direct
|
|
hardware-interface support in the kernel itself is nowadays written in a
|
|
<I
|
|
CLASS="firstterm"
|
|
>high-level language</I
|
|
>. (The ‘high-level’ in this term
|
|
is a historical relic meant to distinguish these from
|
|
‘low-level’ <I
|
|
CLASS="firstterm"
|
|
>assembler
|
|
languages</I
|
|
>, which are basically thin wrappers around
|
|
machine code.)</P
|
|
><P
|
|
>There are several different kinds of high-level languages. In order
|
|
to talk about these, you'll find it useful to bear in mind that the
|
|
<I
|
|
CLASS="firstterm"
|
|
>source code</I
|
|
> of a program (the human-created, editable
|
|
version) has to go through some kind of translation into machine code that
|
|
the machine can actually run.</P
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="compilers"
|
|
></A
|
|
>11.1. Compiled languages</H2
|
|
><P
|
|
>The most conventional kind of language is a <I
|
|
CLASS="firstterm"
|
|
>compiled
|
|
language</I
|
|
>. Compiled languages get translated into
|
|
runnable files of binary machine code by a special program called
|
|
(logically enough) a
|
|
<I
|
|
CLASS="firstterm"
|
|
>compiler</I
|
|
>.
|
|
Once the binary has been generated, you can run it directly without looking
|
|
at the source code again. (Most software is delivered as compiled binaries
|
|
made from code you don't see.)</P
|
|
><P
|
|
>Compiled languages tend to give excellent performance and have the most
|
|
complete access to the OS, but also to be difficult to program in.</P
|
|
><P
|
|
>C, the language in which Unix itself is written, is by far the most
|
|
important of these (with its variant C++). FORTRAN is another compiled
|
|
language still used among engineers and scientists but years older and much
|
|
more primitive. In the Unix world no other compiled languages are in
|
|
mainstream use. Outside it, COBOL is very widely used for financial and
|
|
business software.</P
|
|
><P
|
|
>There used to be many other compiler languages, but most of them have
|
|
either gone extinct or are strictly research tools. If you are a new
|
|
Unix developer using a compiled language, it is overwhelmingly likely
|
|
to be C or C++.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="interpreters"
|
|
></A
|
|
>11.2. Interpreted languages</H2
|
|
><P
|
|
>An <I
|
|
CLASS="firstterm"
|
|
>interpreted
|
|
language</I
|
|
> depends on an interpreter program that reads
|
|
the source code and translates it on the fly into computations and system
|
|
calls. The source has to be re-interpreted (and the interpreter present)
|
|
each time the code is executed.</P
|
|
><P
|
|
>Interpreted languages tend to be slower than compiled languages, and
|
|
often have limited access to the underlying operating system and hardware.
|
|
On the other hand, they tend to be easier to program and more forgiving of
|
|
coding errors than compiled languages.</P
|
|
><P
|
|
>Many Unix utilities, including the shell and bc(1) and sed(1) and awk(1),
|
|
are effectively small interpreted languages. BASICs are usually
|
|
interpreted. So is Tcl. Historically, the most important interpretive
|
|
language has been LISP (a major improvement over most of its successors).
|
|
Today, Unix shells and the Lisp that lives inside the Emacs editor are
|
|
probably the most important pure interpreted languages.</P
|
|
></DIV
|
|
><DIV
|
|
CLASS="sect2"
|
|
><H2
|
|
CLASS="sect2"
|
|
><A
|
|
NAME="pcode"
|
|
></A
|
|
>11.3. P-code languages</H2
|
|
><P
|
|
>Since 1990 a kind of hybrid language that uses both compilation and
|
|
interpretation has become increasingly important. P-code languages are
|
|
like compiled languages in that the source is translated to a compact
|
|
binary form which is what you actually execute, but that form is not
|
|
machine code. Instead it's
|
|
<I
|
|
CLASS="firstterm"
|
|
>pseudocode</I
|
|
>
|
|
(or
|
|
<I
|
|
CLASS="firstterm"
|
|
>p-code</I
|
|
>),
|
|
which is usually a lot simpler but more powerful than a real machine
|
|
language. When you run the program, you interpret the p-code.</P
|
|
><P
|
|
>P-code can run nearly as fast as a compiled binary (p-code interpreters
|
|
can be made quite simple, small and speedy). But p-code languages can keep
|
|
the flexibility and power of a good interpreter.</P
|
|
><P
|
|
>Important p-code languages include Python, Perl, and Java.</P
|
|
></DIV
|
|
></DIV
|
|
><DIV
|
|
CLASS="NAVFOOTER"
|
|
><HR
|
|
ALIGN="LEFT"
|
|
WIDTH="100%"><TABLE
|
|
SUMMARY="Footer navigation table"
|
|
WIDTH="100%"
|
|
BORDER="0"
|
|
CELLPADDING="0"
|
|
CELLSPACING="0"
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="disk-layout.html"
|
|
ACCESSKEY="P"
|
|
>Prev</A
|
|
></TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="index.html"
|
|
ACCESSKEY="H"
|
|
>Home</A
|
|
></TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
><A
|
|
HREF="internet.html"
|
|
ACCESSKEY="N"
|
|
>Next</A
|
|
></TD
|
|
></TR
|
|
><TR
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="left"
|
|
VALIGN="top"
|
|
>How does my computer store things on disk?</TD
|
|
><TD
|
|
WIDTH="34%"
|
|
ALIGN="center"
|
|
VALIGN="top"
|
|
> </TD
|
|
><TD
|
|
WIDTH="33%"
|
|
ALIGN="right"
|
|
VALIGN="top"
|
|
>How does the Internet work?</TD
|
|
></TR
|
|
></TABLE
|
|
></DIV
|
|
></BODY
|
|
></HTML
|
|
> |