0% found this document useful (0 votes)
10 views5 pages

1.9.1 Computacion C++

The document discusses the differences between natural languages and programming languages, specifically focusing on C++. It explains that programming languages, like C++, are rigid and designed for specific tasks, contrasting with the evolving nature of natural languages. Additionally, it outlines the process of compiling source code into machine language and highlights C++ as a foundational language for object-oriented programming.

Uploaded by

angiepmqz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

1.9.1 Computacion C++

The document discusses the differences between natural languages and programming languages, specifically focusing on C++. It explains that programming languages, like C++, are rigid and designed for specific tasks, contrasting with the evolving nature of natural languages. Additionally, it outlines the process of compiling source code into machine language and highlights C++ as a foundational language for object-oriented programming.

Uploaded by

angiepmqz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.0.

1 Natural language vs programming language

We're here to show you what the C++ language is and what we can use it for.

Let’s consider for a moment what language itself is, not only the C++ language,
but any language people use. We’ll try not to use scientific sounding definitions
and we’ll try to speak informally. We can say that a language is a tool for
expressing and recording human thoughts. We really like this definition. In
other words, it's a mechanism known to us and to our partners, allowing us all
to understand and to be understood. We use language for speaking, writing,
reading, listening and thinking.

At least one language accompanies us throughout our entire lives - it's our
native language (our mother tongue), which we learn almost unconsciously from
the very beginning. Many of us will learn other languages too, mostly as a result
of a conscious decision, forced by social conditions or business needs. The
languages we use to communicate with other people are called natural
languages. They were created over many 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 of their speakers and evolves
naturally, in a way that gives us little to no control over it.

However, there are languages whose creation and development were (and
often continue to be) dictated by some specific needs, and whose development
is fully subject to control by very wide groups of people like international
committees or work groups. The shape of these languages is defined by
international standards, and although they may be understood by many people,
the exchange of thoughts between human-beings is not their priority.
Such languages are, among others, programming languages. You are
probably familiar with this concept already. A programming language is defined
by a certain set of 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
language is called lexicon. Another set of rules determines the appropriate
ways of collating the symbols - this is the syntax of the language. We also need
to be able to recognize the meaning of every statement expressed in the given
language, and this is what we call semantics. Any program we write must be
error-free in these three ways: lexically, syntactically and semantically,
otherwise, the program won’t run, or it will produce unacceptable results. You
can be sure that you’ll encounter all of these errors, as to err is human and it’s
these fallible humans who write the computer programs.

You might be asking yourself why we need to use a programming language at


all, and that's a good question. Let’s try to answer it.

Machine Language
A computer, even the most technically sophisticated one, is devoid of even a
trace of intelligence. You could say that it is like a well-trained dog – it responds
only to a predetermined set of known commands. And sometimes, like a dog,
it just shuts down and refuses to do what it’s told. 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 well-known commands is called an instruction list,


sometimes abbreviated to IL. Different types of computers may vary depending
on the size of their ILs and the instructions themselves can be entirely different
in different models.

The IL is in fact an alphabet that is commonly known as 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 the computer’s mother tongue.
It is possible (and this is often done 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 susceptible to a
programmer's mistakes. During the early stages of computer technology, it
was the only available method of programming, and it very quickly revealed its
serious flaws.

Programming in machine language requires full knowledge of a computer’s


hardware design and its internal structure. This also means that replacing the
computer with one that differs in design from its predecessor can make the
programmer’s entire knowledge unusable. Also, the old programs could be
completely useless if the new computer used a different IL. Thus, a program
written for a specific type of computer could be completely useless to other
computers and vice versa. Secondly, programs written in machine language are
very difficult to understand for humans, including experienced programmers.
It is also the case that to develop a program in machine language takes a lot of
time and is very costly and cumbersome.

All these circumstances lead to a need for some kind of bridge between the
people's language (natural language) and computer language (machine
language). That bridge is also a language – an intermediate common language
for both humans and computers working together. Such a language is often
called a high-level programming language.

A language like this is at least somewhat similar to a natural language: it uses


symbols, words and conventions readable to humans. This language enables
humans to express complex commands for computers.

You may be asking how to persuade a computer to understand programs


written in this way. Try as you might, encouraging the computer is just not
enough, but you can translate your program into machine language. Moreover,
the translation can be done by a computer, making the whole process fast and
efficient.

How great is that? You don’t need to learn a whole bunch of different machine
languages – you just need to know one high-level programming language. If
there is a translator designed for a specific computer, you can run your program
without any problems. In other words, the programs written in high-level
languages can be translated into any number of different machine languages,
and thus enable them to be used on many different computers. This is
called portability.

Compilation
The translation we are referring to is made by a specialized computer program
called a compiler. The process of translating 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 a program in
accordance with the rules of the chosen programming language. Such a
program (which in fact is just text) is called the source code, or simply source,
while the file which contains the source is called the 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 - Notepad is better). This code is placed in a file and
the name of the file should imply its content. For example, it's common for a file
containing the source code in the C++ language to have its name ending with
the suffix .cpp, so if you write a computer program and decide to name it
proggie, it would be a good idea to put the source code into a file named
proggie.cpp. Some platforms may prefer other suffixes like cc, cp, cxx, c++ or
even C (note that this is a capital letter). Please consult your compiler
documentation for details.

Next, your source code needs to be compiled. To do this you need to run an
appropriate compiler and instruct it where you stored the source code you want
it to translate into machine language. The compiler reads your code, makes
some complex analysis, and then determines whether or not you made any
errors during the coding process. If you have, it will tell you. This is not to make
you feel bad - these analyses are very insightful and helpful. But remember that
they are made by a machine, not a human, and you shouldn't expect too much
from them. Okay, if your mistake was that you tried to add up two numbers
using # instead of +, the compiler will kindly inform you of your mistake.
However, if you typed - instead of +, the compiler can't guess that your intention
was to add two numbers, rather than to subtract them. The compiler will not
think for you. But that's okay too. If the compiler did everything, developers
wouldn't have jobs.

If the compiler doesn't find any mistakes in your source, the result will be a file
containing your program translated into 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 the
same name to this file as the source file, while only changing the suffix
from .cpp to .exe.
Of course the whole process is actually a bit more complicated. Your source
code might be huge and divided among several or even dozens of source files.
It may also be that the program was not written by you alone, but by a whole
team, in which case the division of sources into multiple files is simply a must. In
this case, the compiling process splits into two phases: a compilation of your
source in order to translate it into machine language and a joining (or gluing) of
your executable code with the executable code derived from the other
developers into a single and unified product. The phase of "gluing" the different
executable codes is commonly known as linking, while the program that
conducts the process is called a 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. 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.

You might also like