loading...
Cover image for Classification of computer languages (III)

Classification of computer languages (III)

vplentinax profile image Valentina VP Updated on ・5 min read

We have been analyzing the ways of classifying computer languages, today we will continue with the classification by translation and method of execution. If you want to start the thread of these posts, I leave the table of contents here.

Translation and method of execution

The code written for a computer program is known as the source code. This code is saved in a file known as source file and will have to be translated into language machine to be able to run.

Three language groups can be considered programming considering how to translate to machine language and to execute:

  • Compiled languages.
  • Interpreted languages.
  • Managed execution languages ​​or of machine virtual.

Some languages ​​like Prolog can be considered compiled or interpreted since they have compilers and interpreters.

Compiled languages

They have a compiler or program that translates the source code to machine code saving the result in an executable file. This compiled code that is generated is called an object code. With that file you can run the program as many times it is necessary without having to repeat the process, so the waiting time between executions is minimal. At runtime the executable file is launched on the platform for which the compiler was made.

Alt Text

Characteristics
There is an executable file for the real machine.
The translation process is done at compilation time and only once.
Execution is very fast since the executable is in machine language.
The executable only works for the platform it was created for.
The user who executes does not have to know the source code, he only has the executable code that is not easily manipulated to obtain the source code, and as a consequence the programmer has the code most protected source.
The executable will not be generated if there are lexical errors, syntactic or semantic.
Interrupting execution can be difficult for the system operational and may affect the platform.
Modifying the source code implies going back to generate the executable file.

Example: ADA, C, C++, COBOL...

We see them more in desktop software since they require greater resources and access to certain files. Also due to the greater weight that they usually have in their executable files.

Interpreted languages

They execute the instructions directly, without generate object code. They need an interpreter or program in memory to that at runtime the code is translated from source code to machine language. Your instructions or rather the source code, written by the programmer in a high-level language, is translated by the interpreter to a language understandable to the machine step by step, instruction by instruction. The process is repeated every time the program is run, the code in question.

Alt Text

Characteristics
There is no executable file.
The translation process is done every time it is run.
The execution is slow since the execution process the translation has to be added.
The file can be run on different platforms provided there is an interpreter for them.
The user uses the source code to execute program.
Lexical, syntactic or semantic errors can appear in the execution
Interrupting execution normally only affects to interpreter and not to the platform.
Allows dynamic data typing. It is not necessary initialize a variable with a certain data type.

Example: RUBY, PYTHON, PHP, JAVASCRPT, VISUAL BASIC 6 and previous...

They are seen in the development of applications or websites that go accompanied by frameworks that greatly facilitate the programming.

Managed execution languages ​​or machine virtual.

These languages ​​initially need a compiler that in programming time translates the source code to a cross-platform intermediate code, then you need other software that translates that intermediate code to machine code. This is the case of languages ​​like Java or .NET

In the case of virtual machine languages ​​such as Java happens that:

Alt Text

  • At compile time the Java compiler generates the intermediate code called bytecode Java platform independent.
  • At runtime, you need a Java Virtual Machine (JVM) that interprets the bytecode, virtual machine is a software that simulates a machine real with your operating system.
  • It acts as an intermediary with the real machine, so virtual machines are different for Linux, Windows, Mac and Solaris.
  • This scheme provides many of the advantages of compilation and interpretation, getting rid of some drawbacks. Mainly:
Virtual Machine Advantage
Portability and speed: The intermediate code is now free of syntactic errors, and it is a very simple code (in the style of machine code).
Multiplatform: If there is an interpreter for this code in different platforms, the same code can be run on each of them.
Stability: intermediate code is not executed by a CPU directly, but yes by a virtual CPU: really, by the virtual machine interpreter, which is a program and not a real chip It allows greater control over this code, making work easier to prevent uncontrolled code from affecting stability of the current platform.

In languages ​​of managed execution such as Microsoft's .NET platform happens that:

Alt Text

  • At compile time, the compiler generates the CIL (Common Intermediate Language) code of independent platform.
  • To run it is necessary to have on the client computer the version of the .NET Framework (CRL Common Runtime Language - proper execution engine) and the last compilation phase is done, in which the CRL will translate intermediate code into machine code using a JIT (Just In Time) compiler.
  • To directly run a .NET application using the CLR, you need the so called "CLR Hosts". CLR Host is an application responsible for loading the CLR in an operating system process, create the application domains required within that process and run the application inside the application domains.
  • The .Net platform has a common system of types known as CTS (Common Type System). All types of data are collected in the CTS and operations that can be used from a language .Net. It doesn't matter if we use Visual Basic .Net, C #, COBOL, Perl or Pascal. The data set to use is always the same. The CTS also includes the operations that can be done on the data.
  • There is a subset of the CTS made up of data types and operations that all .Net languages ​​must implement to be compatible with the rest. This subset is known as CLS (Common Language Specification).
Common features between managed machine and virtual machine languages
There is an intermediate code that runs on a specific software but not an executable.
The initial translation process is done before execution and the final translation process is done every time running.
Execution is not as fast as in compiled languages ​​but it is faster than in languages interpreted.
The file can be run on different platforms as long as the specific software exists.
The user does not have the source code, only the intermediate code that is not easily manipulated to get the source code, so the programmer has more protected source code.
Lexical, syntactic or semantic errors are detected in the compilation phase, and if they exist they are not will generate the intermediate code.
Interrupting execution normally only affects the interpreter and not to the platform.
Modifying the source code implies repeating the compilation process.

Client-server architecture

Alt Text

The client-server architecture basically consists of a client program that makes requests to a server. It is most useful when the client or the server are communicating through a network, although it can also be apply when they are on the same machine.

It differentiates between languages ​​that are executed:

  • Server-side like PHP, NodeJS...
  • On the client side as Javascript...

These were some of the ways of classifying computer languages, I hope you have learned a lot. See you soon.

Posted on by:

vplentinax profile

Valentina VP

@vplentinax

👩‍💻FrontEnd Developer. 🎨 Graphic Designer. Illustrator. 🎼 Musician. 💞Wife, no mother. ☕️Coffee lover . 👩‍🎓English Student 👩‍🏫 Lover of teaching

Discussion

markdown guide
 

Nice article!

But PHP is more on the line of "virtual machine languages" than "interpreted languages".

PHP is "compiled" to what's called opcodes just once, the first time the program is executed.

After that, the "compiled" opcodes are stored in what we usually call "opcache" and the Zend Engine (PHP's VM) won't need rerecompile the application.

In PHP 7.4 preloading was introduced, making "opcache" even better, saving the compiled code in memory.

PHP 8 will introduce JIT (Just In Time compiler).

This is just an addition to your great article, because PHP doen't do this "translation" or "compilation" everytime it runs.

:-D

I'm sorry. I can give you some links.

Here you can find about the whole preloading feature (it's very interesting):
wiki.php.net/rfc/preload

This is a quite old article, but explains how the opcache itself works:
support.cloud.engineyard.com/hc/en...

A lot of stuff has evolved since then, but this is a good starting point.

My intention was not to say "Go find yourself". I just wasn't sure about how interested you would be in extra info. My bad.

:-)

 

Yes, opcache is persistent.

Each PHP execution is independent: Yes. That's one of the main things that makes it perfect for serverless.

But it doesn't make it impossible to store the "compiled" files.

I invite you to read a bit about opcache, preloading and JIT in PHP.

:-D

Yeah, but PHP isn't run in "CGI manner". Old applications run it with an Apache module, where apache can directly execute PHP.

New applications tend to work with FastCGI (php-fpm). There's no up-to-date method of using PHP in a "CGI manner".

 

Isn't a physical machine just an interpreter for compiled code 🤔

 

Yes. Kinda like .NET or JVM. :-)