If declarative programming is possible at the instruction/action level?

I am considering what the possibilities are with declarative programming. I have a firm understanding of how to use declarative programming in practice, but, short of having examples, I don’t know if it’s possible to 100% use declarative programming all the way down to the machine code (theoretically).

Standard QA sites like this says stuff like:

it means describing the problem to be solved, but not telling the programming language how to solve it

A typical example is a SQL query which uses a where clause to define the query rather than implementing the query it step-by-step using something like an iterative loop.

An example I am interested in is an even higher level abstraction than a SQL query: defining an HTTP server. You can define the server and all of it’s GET handlers (if we just limit it to that for now) in a completely declarative way, as seen by many declarative frameworks. The declarative frameworks that do similar stuff to this are the ones like Terraform or SaltStack that define machine configurations/states. You are basically defining the state the machine should look like, and the system takes your “definition” and makes it happen.

For the HTTP server you can do like in React:

<Route path='/' component={Home}>   <Route path='/about' component={About}>   <Route path='/terms' component={Terms}>   ... </Route> 

This then automagically gets wired up into a listening server for these changes, and renders the components (this API may not be exact, just pseudocoding it ftm).

In fact, there is a lot that can be done declaratively. HTML and CSS together form an animatable graphics display and is completely declarative. You can define servers, machines, parsers (PEG parser generators), graphics… I don’t know what else.

That’s mainly what my question is, what can be done declaratively. More specifically, what cannot be done in a declarative fashion. The stereotypical example I am thinking of is simply defining a step-by-step sequence of actions of some sort, but in a declarative, non-iterative way. Is it possible?

Here is my attempt…. Say we are describing some automation steps for interactively going through and clicking around a website. Here is the iterative way:

Visit "/" Click on "Button 1" Wait "2 seconds" Click on "Button 2" For each "Input" in "Fields"   Type into "Input" Click on "Button 3" Wait "2 seconds" ... 

This is similar to assembly instructions like mov. But can this be done in a declarative way (that is also readable and easy to understand)? Does functional programming offer any insight? Maybe one could show how to do this in a functional programming paradigm, or even a logic (prolog-ish) way, if that would help illuminate how it’s done. My attempt at declarative is like this:

Current State should be "/" Button is not clicked Button has been clicked 2 seconds have passed ... 

Basically, just stating the “states” before and after each step sort of thing. That makes it harder to read, and it feels like you are trying to hack around having to build some iterative code anyways. It’s like it has to be iterative. Is that so? Is there any way to make this non-iterative and so it still makes sense?

To me, currently, it seems that you can use declarative programming for like 80-90% of things, but then you inevitably need “parsing” code which will take those declarative statements and interpret them, converting them into some iterative sequence. But what I’m left wondering is, can that 10-20% that seems to have “iteration” as a requirement be instead written declaratively? Can you take that 10-20% remaining iterative code and make that declarative too? If so, how would that look or what is the technique?

Is relational algebra a procedural, imperative, and/or declarative language?

In Database System Concepts 6ed,

6.2 The Tuple Relational Calculus

When we write a relational-algebra expression, we provide a sequence of procedures that generates the answer to our query.

The tuple relational calculus, by contrast, is a nonprocedural query language. It describes the desired information without giving a specific procedure for obtaining that information. A query in the tuple relational calculus is expressed as: {t | P(t)}. That is, it is the set of all tuples t such that predicate P is true for t.

Does the above mean that relational algebra is a procedural language?

Is relational algebra a declarative language?

Is the tuple relational calculus a declarative language?

Is the tuple relational calculus more declarative than relational algebra is?

Is a procedural language an imperative language? (This is always what I heard, but I also heard that SQL is a declarative language (so is relational algebra) so is not imperative.)

What is the correct or most reasonable or most accepted definition of procedural languages, imperative languages, and declarative languages?

Thanks.

Magento 2. Declarative Schema. How to uninstall a patch without uninstalling the module?

The official docs say this.

Revertable data patch – A patch that can be reverted as a module or patch is uninstalled or deleted.

I know that Revertable patches must implement Magento\Framework\Setup\Patch\PatchRevertableInterface and when a module is un-installed the logic in the revert() method is called.

How can one revert a Patch without uninstalling the module

Declarative schema: Incorrect Foreign Key Diff

We created a new table using M2’s declarative scheme like this:

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">     <table name="company_quote_item_original_sku" engine="innodb" resource="default" comment="">         <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true" comment=""/>         <column xsi:type="int" name="quote_item_id" padding="10" unsigned="true" nullable="false" comment=""/>         <column xsi:type="varchar" name="original_sku" nullable="true" length="255" comment=""/>         <constraint xsi:type="primary" referenceId="PRIMARY">             <column name="entity_id"/>         </constraint>         <constraint xsi:type="foreign" referenceId="FK_QUOTE_ITEM_ID" table="company_quote_item_original_sku"             column="quote_item_id" referenceTable="quote_item" referenceColumn="item_id"             onDelete="CASCADE"/>     </table> </schema> 

This worked great. Then we tried to add another table by updating the schema, like so:

<schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xsi:noNamespaceSchemaLocation="urn:magento:framework:Setup/Declaration/Schema/etc/schema.xsd">     <table name="company_quote_item_original_sku" engine="innodb" resource="default" comment="">         <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true" comment=""/>         <column xsi:type="int" name="quote_item_id" padding="10" unsigned="true" nullable="false" comment=""/>         <column xsi:type="varchar" name="original_sku" nullable="true" length="255" comment=""/>         <constraint xsi:type="primary" referenceId="PRIMARY">             <column name="entity_id"/>         </constraint>         <constraint xsi:type="foreign" referenceId="FK_QUOTE_ITEM_ID" table="company_quote_item_original_sku"             column="quote_item_id" referenceTable="quote_item" referenceColumn="item_id"             onDelete="CASCADE"/>     </table>      <table name="company_order_item_original_sku" engine="innodb" resource="default" comment="">         <column xsi:type="int" name="entity_id" padding="10" unsigned="true" nullable="false" identity="true" comment=""/>         <column xsi:type="int" name="order_item_id" padding="10" unsigned="true" nullable="false" comment=""/>         <column xsi:type="varchar" name="original_sku" nullable="true" length="255" comment=""/>         <constraint xsi:type="primary" referenceId="PRIMARY">             <column name="entity_id"/>         </constraint>         <constraint xsi:type="foreign" referenceId="FK_ORDER_ITEM_ID" table="company_order_item_original_sku"             column="order_item_id" referenceTable="sales_order_item" referenceColumn="item_id"             onDelete="CASCADE"/>     </table> </schema> 

This triggered the following error:

General error: 1826 Duplicate FOREIGN KEY constraint name 'magento2/COMPANY_QUOTE_ITEM_ORIGINAL_SKU_QUOTE_ITEM_ID_QUOTE_ITEM_ITEM_ID'  ALTER TABLE `company_quote_item_original_sku` MODIFY COLUMN `entity_id` int(10) UNSIGNED NOT NULL  AUTO_IN CREMENT COMMENT "", MODIFY COLUMN `quote_item_id` int(10) UNSIGNED NOT NULL   COMMENT "", MODIFY COLUMN `original_sku` varchar(255) NULL  COMMENT "", ADD CONSTRAINT `COMPANY_QUOTE_ITEM_ORIGINAL_SKU_QUOTE_ITEM_ID_QUOTE_ITEM_ITEM_ID` FOREIGN KEY (`quote_item_id`) REFER ENCES `quote_item` (`item_id`)  ON DELETE CASCADE, COMMENT='' 

It looks like Magento is incorrectly diffing my existing table and the new schema-generated table. It should do a REMOVE before it does the ADD on the constraint, but it doesn’t.

Has anyone seen this before?