What’s the difference between command, instruction and code?

Asked

Viewed 587 times

13

  • What is the difference between them in the context of programming?

  • I can use these terms interchangeably?

  • If they are different, what is the correct term to define what we write?

  • Related: https://answall.com/q/261818/8063

2 answers

16


People use them interchangeably in many cases, but they should not because precise meanings are not the same thing, and it is even difficult to define them clearly, at least in Portuguese.

Obviously the important thing most of the time is to be understood, if you have no ambiguity you can use.

Code it should be something broad, but there are many people who use it as if it were something specific, call it something smaller, something that is an excerpt, something that can be an instruction or command, but it should only be used formally for the whole.

Strictly speaking instruction is only used in low level code and refers to the smallest possible command that the processor can perform, it is a simple operation that it can do, such as doing arithmetic or relational operation, carry data in the registers or memory or control the code execution flow.

But there is some informal use when it comes to high-level languages. If used correctly the term instruction should be for something minimal, a simple operation that the language or library has to execute, even if there already has a large abstraction. Some people use as exact synonym for command.

The commando is a middle ground, it is not even something more complex, it determines something greater to be executed, although it may eventually be a simple instruction, but only because everything that the command wants to do is really simple, but it is not the whole.

The term is a bit controversial and we actually use it to translate statement which is actually just a statement, but not just a variable or function statement, is the intention statement of whatever the computer runs.

If you are speaking in this context it would be this, in other contexts it may not even have to do with code but with architecture or general engineering.

The question linked in the above comment has response using statement as declaration same, which I think was even the intention of the question, but anyway. I’m using statement like statement.

And precisely because it creates this confusion is common we prefer to call command (which in English should be command). I said it was confusing at first :)

if (x == 1 && y > 0) return;

I put in the Github for future reference.

There is one (excerpt from) code, which is a commando, composed of instructions (if, x == 1, y > 0, the condition composed by these 2 related to && and the return). Since at a high level it is not customary to use instruction, some may understand a little differently and may even speak informally that this whole code is an instruction.

Then the command can be considered everything that is on a line (even if it has visual line break, but it is still a line in the direction of execution).

Remembering that I’m using the terms very informally, but it was popularized like this.

3

According to the Wikipedia:

A machine code program consists of a sequence of bytes that correspond to instructions to be executed by the processor. [...] A machine code instruction consists of a sequence of bytes, where each byte means something to the processor.

It is therefore understood that a code is a set of instructions. Again, according to the Wikipedia:

In computer science, an instruction is a single operation executed by a processor and defined by a set of instructions. In a broad sense, an "instruction" can be any representation of an element in an executable program, such as a bytecode.

And according to the Anhanguera de Niterói:

A machine instruction is the formalization of a primitive instruction that the machine can directly perform.

An instruction is the smallest action that can be done on a computer using programming. It would correspond to a low-level action, such as an assembly instruction, or even a binary instruction written in machine language.

Still, according to the Wikipedia:

Computer command is the atomic and elementary representation of a computer action, which can be invoked by user, application systems or programs.

Although it is used in everyday context as a function or operation (e.g.: goto, do...while, etc.), the most "correct" concept of a command, according to my understanding, is similar to that of instruction: a single, indivisible command. The smallest thing that can be done in a program.

Related:

Browser other questions tagged

You are not signed in. Login or sign up in order to post.