Declarative programming and compulsory programming

I study two main programming paradigms, the declarative and imperative paradigm. It’s hard for me to follow the ambiguous statements made in my textbook and Wikipedia, for example:

declarative: - focuses on what the computer should do. - no side effects "- no control flow

imperative: - focuses on how the computer should do this. - how to do it in terms of sequence of actions

how would you differentiate two programming paradigms? If you could expand on the statements made above, this will be very helpful.

+3
source share
3 answers

SQL - : : " , " ( , , , ), , , , .

, C, SQL- :

while (another row to process)
    read row from disk
    for (every test)
        if (test fails)
            continue to next row
    add row to result-set

, , : while, for if. .

+7

, .

java:

Customer customer = null;

// first create a customer and have the variable reference it
customer = new Customer(); 
// the state of the customer variable has changed

// set the id on whatever object is *currently* being referenced by the variable
customer.setId(1);
// the state of the Customer object has changed

customer.setFirstName("Bob");
customer.setLastName("McBob");

, , :

Customer customer = null;
customer.setFirstName("Foo");   // the customer variable is still null at this point
customer = new Customer();   // too late!

, .

: xml :

<NewCustomers>
  <Customer>
    <Id>1</Id>
    <FirstName>Bob</FirstName>
    <LastName>McBob</LastName>
  </Customer>
</NewCustomers>

, , . , .

+5

HTML - , . HTML ( CSS) - - -, , . , <h1>My title</h1> -, , - " " - , .

-, , . , .

+3

Source: https://habr.com/ru/post/1718408/


All Articles