Vous êtes sur la page 1sur 4

1.1.1 Natural language vs.

programming language
We've met here to show you what the C++ language is and what we use it for.
Now once we have installed the programming environment allowing us to write, run
and compile C/C++ programs (chapter 0 of this course), let us consider for a
moment, what language itself is, not only C++, but any language people use. We
will try not to resort to scientifically sounding definitions and speaking informally, we
can say that a language is a tool for expressing and recording human thoughts. In
other words, it's a mechanism known to us and to our partners, allowing us all to
understand and to be understood. We can use our language for speaking, writing,
reading, listening, thinking and many others purposes.
At least one language accompanies us throughout our whole lives - it's our native
language, our mother tongue, which we learn almost unconsciously at the very
beginning of our programming career. We will learn other languages, mostly as a
result of a conscious decision, forced by social conditions or business needs. Such
languages, which we use to communicate with other people, are called natural
languages. They were created over the centuries and still are subject to change. If
we ignore languages that have been created artificially, such as Esperanto or even
Quenya (the language used by elves in Tolkien's world), their development is almost
independent and takes place naturally, in a way that gives us little or even no
control over it.
However, there are languages whose creation and development were and continue
to be dictated by the specific needs while the development is fully subject to control
by very wide groups of people, like international committees and work groups. The
shape of these languages is defined by international standards and although they
are understood by many people, the exchange of thoughts between human-beings
is not their most important application.
Such languages are, among others, programming languages. You are probably
familiar with this concept already. A programming language is defined by a set of
certain rigid rules, much more inflexible than any natural language. For example,
these rules determine which symbols (letters, digits, punctuation marks, and so on)
could be used in the language. This part of the definition of the language is called
lexicon. Another set of rules determines the appropriate ways of collating the
symbols - this is the syntax of the language. We would like to be able to recognize
the meaning of every statement expressed in the given language and this is what
we call semantics. Any program written by us must be correct in these three ways:
lexically, syntactically and semantically. Otherwise, it will neither run nor produce
acceptable results. You can be sure that you will experience all of the described
errors, as to err is human and these humans write computer programs.
The expressive power of programming languages is much, much weaker than those
offered by natural languages. We will not be able (although we can try) to use such
a language to express human emotions and it is hard to imagine a declaration of

love encoded in the programming language. It is a simple consequence of the fact


that the message embedded inside a computer program is not intended for a
human but for a machine.
Some would want to ask why there is a need for using a programming language. It's
a good question. We will try to answer it.
1.1.2 Natural language vs. programming language

A computer, even most technically sophisticated, is devoid of even a trace of


intelligence. You could say that it is like a well-trained dog - responds only to a
predetermined set of known commands. The recognized commands are very
simple. We can imagine that the computer responds to orders like take that
number, add to another and save the result. A complete set of such well-known
commands is called an instruction list, sometimes abbreviated to IL. Different types
of computers may vary depending of the size of their ILs and the instructions
themselves could completely differ in different models.
The IL is in fact an alphabet of a language, which is commonly known as a machine
language. This is the simplest and the most primary language we can use to give
commands to our computer. We can say, it's a computers mother tongue.
Computer programming is an act of composing the selected commands
(instructions) in a proper order that will cause a desired effect. The effect itself could
be different in every specific case it's up to the programmer's imagination,
knowledge and experience.
It is possible and often used in practice for a computer program to be coded directly
in machine language using elementary instructions (orders). This kind of
programming is tedious, time consuming and highly prone to a programmer's
mistakes. At the early stages of computer technology it was the only available
method of programming and very quickly revealed its serious flaws. Programming in
machine language requires full knowledge of a computers hardware design and its
internal structure. This also means that replacing the computer with one that differs
in design from the previous one used can make the programmer's entire knowledge
unusable. Also the old programs could be completely useless if the new computer
used different IL. Thus, a program written for a specific type of a computer could
be also completely useless for other computers and vice versa. Secondly, programs
written in the machine language are very difficult to understand for humans,
including experienced programmers. It is also common that developing programs
written in a machine language takes a lot of time, is very costly and cumbersome.
All those circumstances created a need for some kind of a bridge between the

people's language (natural language) and a computer language (machine


language). That bridge is also a language an intermediate common language for
both humans and computers working together. Such languages are often
calledhigh-level programming languages.
Such a language is at least somewhat similar to a natural language, uses symbols,
words and conventions readable to humans. This language enables humans to
express complex commands for computers.
You can ask how to persuade computers to understand programs written in this
way. Encouragement will not work, but you can just translate your program into the
machine language. Moreover, the translation can be done by a computer, making
the whole process fast and efficient.
Notice how many benefits you can get from such a course. There is no need to
learn many different machine languages it's enough to know one high-level
programming language. If there is a translator designed for a specific computer,
your program could be run without any problems. In other words, the programs
written in high-level languages could be translated into any number of different
machine languages and thus make them able to be used on many different
computers. This important and useful feature of high level programming languages
is called portability.
1.1.3 Natural language vs. programming language

The translation we are referring to is made by a specialized computer program


called compiler. The process of the translation from a high-level language into a
machine language is called compilation.
Now let's get back to more interesting issues related to the process of creating a
new program. We already know that the main task is to write the program in
accordance with the rules of the chosen programming language. Such a program
(which in fact is just a text) is called source code or simply source while the file
which contains the source is called source file.
To write the source code you will need a text editor that allows you to manipulate
text without any formatting information (for this reason Microsoft Word isn't a good
choice, in contrast to the Notepad). This code is placed in a file and the name of the
file should imply its content. For example, is common that a file containing the
source code in the C++ language to have its name ending with the suffix .cpp ,
so if you wrote a computer program and decided to name it "proggie" it would be a
purposeful and reasonable idea to put the source code into a file named
proggie.cpp. Some platforms my prefer other suffixes, like cc, cp, cxx, c++

or even C (note: this is a capital letter). Please, consult your compiler


documentation for details.
Next, your source code should be compiled. To do this you run an appropriate
compiler, instructing it where you stored the source code that you want to be
translated into the machine language. The compiler reads your code, makes some
quite complex analysis and its first goal is to determine whether or not you made
any errors during the coding. These analyses are very insightful, but remember that
it is made by a machine, not a man and you should not expect too much from them.
OK, if your mistake was that you tried to add up two numbers using # instead of
+, the compiler will kindly ask you to be aware of that. However, if you have typed
a "-" instead of a "+", the compiler will no longer be able to guess that your
intention was to add two numbers, rather than to subtract them. Do not expect that
the compiler will think for you. You have no reason to express regret about it thanks to that, developers are still needed.
If the compiler does not notice mistakes in your source, the result of its work will be
a file containing your program translated into the machine language. That file is
commonly called an executable file. The name of the file depends on the compiler
you use and the operating system you are working with. For example, most
compilers designed for Unix/Linux system create an output file named a.out by
default. Compilers designed for use in MS Windows, can name this file just the
same as the source file, only changing the suffix from .cpp to .exe.
We should admit that the whole process is actually a bit more complicated. Your
source code could be comprehensive and divided among several or even dozens of
source files. It may also happen that the program is written not by you only but by a
team, in which case the division of sources into multiple files is simply a must. In
such a case, the compiling splits into two phases - a compilation of your source in
order to translate it into machine language and joining (or gluing) your executable
code with the executable code derived from other developers into a single and
unified product. The phase of gluing the different executable codes is commonly
known as linking while the program which conducts the process is named linker.
What is the most common use of C++? It is the so-called object programming
language, i.e., suitable mostly for large, complex applications, especially those
working in graphic environments. We can assure you that knowing the C++
language is very helpful if you want to learn C# or Java. The conceptual apparatus
used by the C++ language is common for all object programming languages as
C++ is one of the oldest languages of that class.