Terminology - What is the difference between instruction and statement?

3

What would be the difference between them?

Instruction would be a line of code representing certain commands / actions passed to the computer to run.

Statement, following logic, would it be a type of statement? Since, as far as I understand, it would be an instruction to declare something (a variable declaration statement, for example).

Is there a difference between these two words?

Thank you all!

    
asked by anonymous 10.12.2017 / 03:18

2 answers

2

Statement is when you declare a variable, function, method, class, or the like.

Instruction is what you instruct the program to perform a certain action.

Statements are not usually considered statements because they say something that explains to the compiler or interpreter where certain data is written or what the format is. It's not usually something to be directly executed and it's going to have some kind of effect somewhere.

The instructions are things to do at certain times and that have some kind of effect: change values of variables, allocate or (depending on the language) deallocate memory, modify the state of the execution stack, perform some type of input or output, etc. Declarations do not do this, as they are not executable, they just name some things.

It's true that you can have something like this, depending on the programming language:

var x = 123;

In this case, the statement is var x and initialization is x = 123 . Initialization is an assignment type that is a type of statement. In this case, this line contains a statement and an instruction. They could be separated with this equivalent:

var x;
x = 123;

In Python specifically, the use of class MinhaClasse: is a class declaration, whereas def meu_metodo(): is a method declaration. Python does not require declaration of variables in other cases, but these are required in other programming languages, especially those that have static typing, such as C, C ++, Java, C #, Pascal, Delphi, Rust among many others. / p>     

10.12.2017 / 03:44
0
  

The question has Python as a tag, but the terminology is, in general,   applicable to all programming languages.

Instruction: request to do something or tell you how to do it.

Declaration: pass, change, or create information.

The second may be contained in the first, since declaring something is still an instruction, although it does not cause any immediate action.

By writing x = true I am declaring to the program that the variable x is true, and I am also instructing the program to treat this variable in this way.

On the other hand, a statement, itself, is like an "order" that the code tells the program to do something, that is, to perform an action or a condition, most of the time, according to the statements that were made.

A simple example would be:

x = 1; // declaração
alert(x+10); // instrução

Another example instruction would be:

if x == 1 then x = x+10

I am instructing the program that if x is equal to 1 , it should be incremented with 10 in its value.

The difference between one term and another is that one is passive, only declares information, while the other executes this information or actions within the program.

    
10.12.2017 / 04:52