Declarative versus Imperative


I responded to a recent discussion Declarative vs imperative programming on the Types mailing list, but my post was rejected because of a bad mail header. By the time I got around to fixing it, the discussion was old. But for what it's worth, here are my thoughts:
------
I have been thinking about the use of the words "declarative" and "imperative" for some time. This is my understanding of how they are commonly used in computer science today:
Declarative: describing "what" is to be computed rather than "how" to compute the result/behavior
Imperative: a description of a computation that involves implicit effects, usually mutable state and input/output.
As others have pointed out, our usage originally came from the distinction between imperative and declarative statements in natural languages. However, I think that our usage has diverged significantly from this origin, so that the words no longer form a dichotomy.
For example, one might argue that a finite state machine is both declarative and imperative in the computer science senses. I think Uday made a similar suggestion. There is also Wadler's classic paper on "How to declare an imperative".
Another hint that "declarative" and "imperative" are not antonyms is that the definitions don't have any significant words in common. The antonym of "imperative" in common usage is "pure functional". I don't know of a widely-used word that acts as an antonym for "declarative", although "operational" might work. It may be that "imperative" has a connotation of "step-by-step", which hints at it being the opposite of "declarative", but this connotation is fairly weak at this point. If we wanted to we could try to force “declarative” and “imperative” to be antonyms, possibly by redefining what we mean by “imperative”, but I'm not sure that would be an improvement.
I agree with those who say that "declarative" is a spectrum. For example, some people say that Haskell is a declarative language, but I my view Haskell programs are very much about *how* to compute a result. It is true that many details about how are left out (memory management, order of operations, etc). But if you compare a Haskell program with a logical specification (pre/post conditions), they are quite different. Thus while I would say Haskell is more declarative than many other programming languages, Haskell is not a declarative language in the strongest sense of the word. Haskell programs are not specifications, they are computations, in the sense that they say how to compute and answer.
Here is a quick shot at a spectrum between "how" and "what". Each level has a quick summary of the "how" that is involved, and it also includes all the "hows" listed below them. I suspect that many of you might disagree with the placement or absence of various languages, so I cannot claim that this list is definitive.
 More "How"
How the machine works
   Assembly
How memory is managed
   C, C++, etc
Order of operations
   Java, Smalltalk, Python, Ruby, etc
How data flows (with issues like nontermination and cut)
   Haskell, Prolog, Lambda Calculus (in various forms)
----split between Programming and Specification Languages---
Restricted Specification Languages
   BNF, SQL, Excel, Statecharts
Logical specification languages
   VDM, Z, B, Alloy
 More "What"
The idea that a specification language (by definition) cannot be executed is widely held but false. I consider BNF to be a simple counter example. BNF is clearly a specification language, and it clearly has efficient execution (parsing) strategies.
As for the objects/type distinction that sparked this discussion, I think the discussion was pretty reasonable, and I would like to thank Jonathan for presenting my views so articulately.
I agree with Uday that we need to get our own house in order. These kinds of discussions are a good start.

16 comments:

Anonymous said...

It's worth noting that it's been a long time since assembly has actually been "how the machine works". Assembly doesn't reflect anything to do with pipelining, branch prediction, hyperthreading, virtualization, multi-level caches, or any of the other 101 tricks that hardware folk use to make our machines work. For that matter, most C usage (including the standard library) is a _long_ way from how memory actually works in modern machine.

Sean McDirmid said...

Imperative + declarative is a conceivable combination; consider putting your imperative program in an infinite loop! The effects are applied continuously and time-based ordering is eliminated as a concern.

I'm of the opinion that objects naturally have identity and encapsulated state, and are therefore support imperative forms of programming. They might support declarative programming also, but this is orthogonal.

SayCheese said...

The more a programming language interfaces with the machine, the more imperative it is.

The more it interfaces with algorithms, the more declaritive it is.

Anonymous said...

I think that the most accurate definition of declarative is:
A language L has a declarative semantics iff there is an interpretation of L in terms of sets of individual terms (aka values).

I.e., there is a model theory for the language.

Kowalski's dual interpretation of logic programming was exactly that the same formula can have an interpretation as a program and as a formal over sets of individuals.

James Rise said...

Yahoo Mail is one of the exceptional email services that have attracted the users to a large extent. The powerful features of Yahoo mail are highly suggested for official purposes and it has gone through a lot of upgradation in its specifications, features, looks, versions, and much more. May times, people have talked about the shortcomings regarding Yahoo mail error code 475 and they went through the troubleshooting tips to resolve the issue. However, if you aren’t satisfied with the tricky steps, or you have other similar problems for which you need assistance, you can feel free to talk to the professional’s and get the issue fixed immediately.

Dyna N said...

The ESPN channel offers live tv programmings also 24/7 live sporting series and full repeat telecast, sports news, clips and game trending highlights.
https://espncomactivate.co/
https://denialmart.medium.com/how-to-activate-espn-espn-on-roku-tv-727581674d
https://sites.google.com/view/espncomactivaterokutv/home
https://sites.google.com/view/how-to-reactivate-espn-plus/home
https://sites.google.com/view/espn-plus-login/home
https://denialmart.medium.com/how-to-install-activate-roku-on-tv-activate-espn-on-roku-19d095d0203e
https://denialmart.medium.com/how-to-reactivate-espn-account-activate-espn-roku-15dcf8e11a7e
https://espncomactivate.blogspot.com/2020/12/how-to-activate-espn-on-roku-tv.html

James Rise said...

Many a time, issues in outlook search not working Mac indicating a serious concern. But don’t worry, sometimes, it gets resolved within few seconds. However, If the issue of doesn’t get resolved by following the uncompromising guidelines, you can reach the experts for help and get it fixed as soon as possible.

Alice Brown said...

Thank you for sharing the information. I like your blog post. It is quite informative and helpful. If you are looking to solve att email issues, then Open your AT&T Mail in a different web browser. For example, if you normally use Google Chrome, try Firefox. Verify that your browser accepts cookies. Then, clear your cookies and cache. You’ll find this info in your browser's Preferences, Settings, or Options menu. Enable JavaScript, and make sure it’s up to date. You’ll find it in your browser settings or options. Disable browser tools or add-ons to see if they’re causing issues with email access. To resolve ATT Email not Working, enable Adobe Flash Player, and make sure it’s up to date.

james said...

Bellsouth is a company known for many of its services. It also offers email services and many other features like sorting what you want. We all know that every business book plays an important role. In this case, we can say that the implementation of these questions about how we communicate with our customers is important, the use of your Bellsouth email address can be much more efficient.

bellsouth email login
bellsouth mail sign in
bellsouth login

james said...

AOL Mail is one of the oldest but most reliable databases, providing a wide range of users for different types of services. Whether it's email, news, or social media, AOL is the same for everything. If you want to take advantage of their services, contact a team of experts and do whatever it takes. The team is qualified with a range of knowledge that includes reporting, repairing, and resolving an error message. For more information on AOL Sign in, you can choose to contact an AOL expert.

My AOL Mail Login Screen Name and Password

AOL Mail Login Screen name

james said...

Best Search Engine Optimization Service
Search Engine Optimisation Agency
Search Engine Optimization Packages

Social Media Optimisation Agency
Social Media Optimization in Digital Marketing
Social Media Optimization Expert
How to do Social Media Optimization

iOS Development Agency
Apple App Development
iPhone App Development Agency

Android App Development Company in USA
Mobile App Development Agencies
Android Application Development Agency

Website Design And Development Services
Web Development Solutions
Web Designing Solutions

james said...

Top Digital Marketing Services New York
Best Digital Marketing Services In USA
Social Media Optimization Tools
Social Media Optimization in Digital Marketing
Android App Development Company in USA
Best Android App Development Company

Customer Service Directroy said...

thanks for sharing your post

How to fix century link email not working
How to Resolve CenturyLink Email Login Issues
Fix CenturyLink Email Issues
My CenturyLink not loading: Issues with My CenturyLink
My CenturyLink Problems & Troubleshooting – solutions
CenturyLink Email Errors after ios14 Update
Causes and Ways To Fix CenturyLink Email Issues

Al Mamzar Rent a car said...

Good article. Renting a car in Abu Dhabi www.autorent-me.com

Real Estate Company in Vijayawada said...

Real Estate Agency in Vijayawada www.saipragathi.com

Amora Devid said...

Hats off to the author for this insightful blog post! The depth of knowledge examination here is genuinely admirable. The writing style is engaging, making complex ideas accessible to a broader audience. I appreciate the effort put into creating such a well-crafted piece.

Mern Stack Development Company!