Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7828909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:32:07+00:00 2026-06-02T10:32:07+00:00

I have a question regarding declarative programming, to see how well I understand the

  • 0

I have a question regarding declarative programming, to see how well I understand the concept. I have an assignment stating I should make a sudoku puzzle solver in Java in a “declarative way”. Looking up what that means I found a lot of ambiguous definitions stating the program should be written in such a fashion that is describes what has to be done instead of specifying how. Looking around, I found an interesting example of someone explaining it with a list, specifically filtering the odd numbers of a list.

Imperative style (called function):

List resultList = new List()
foreach element in startlist
    do if element % 2 == 1
        do add element to resultList
        od
    od
return returnList

Declarative style (calling context):

newList = startList.filter(num -> num%2 ==1)

So in the declarative style, it is specified what elements we want to keep, but the way the list is made is not specified. This is abstracted into the API of the list.

My simple question then is: doesn’t this approach mean the library of the lists is NOT declarative, because the algorithms are moved there? In that case, the term “declarative” applies to the part of the program making calls to this library. Hence, isn’t it impossible for a program to be 100% declarative, as (of course) somewhere will need to be an algorithm specifying how things are done? Please correct me if I’m wrong here because this would be at the heart of my understanding of the declarative concept.

In any case, I was thinking of writing the sudoku solver as a combination of my own libraries (containing all the “imperative” logic, wrapped in “declarative” function programming style) and a specification of the steps that should be taken to solve the sudoku, as calls to these libraries. I was also thinking I could use the Command pattern as a wrapper to a way to pass functions as arguments in Java, as to further make the solver classes more “declarative”. I’ve already experimented with this and tried something along the lines of newList = startList.filter(new OddNumberCommand()), with OddNumberCommand a command that has the execute function, taking an element from the list as argument and returning true or false if the element is to be kept or discarded from the result list.

Anyway, this is all just the way my mind spins and I wanted to turn to the help of others that understand this concept better in order to make sure if I’m heading down the right or wrong path. Please let me know where I’m wrong and what’s right in my reasoning so I can learn to use declarative programming properly.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:32:08+00:00Added an answer on June 2, 2026 at 10:32 am

    As a commenter said, your example is more functional programming than declarative programming, although the two are similar in some respects. In real declarative programming, you’d be more results oriented — you’d be specifying what to do with the interesting elements in the list, rather than transforming the list for its own sake. A rule engine like Jess is an example of a declarative programming system (disclaimer, I’m the author of Jess.)

    To answer your one simple question: yes. All functional or declarative programming systems involve a runtime system that has to be implemented on the real computer the program is running on. Since the real computer is invariably an imperative von Neumann machine, that runtime system has to be written imperatively. It is therefore an additional layer of abstraction between your program and the hardware.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have question regarding polymorphism about its assignment statement, for Example this is The
I have a question regarding building dynamic PDF documents with ABCPDF.dll. I understand the
Hi I have question regarding cin and buffer. I want to make a simple
I have question regarding the SQLAlchemy. How can I add into my mapped class
I have question regarding the use of function parameters. In the past I have
I have question regarding disabling browser caching. I have already found few solutions, and
I have a question regarding dependency injection. say i want to create a class
I have a question regarding static function in php. let's assume that I have
I have a question regarding the onkeypress event on JavaScript. Is it possible to
I have a question regarding the integration of business objects developed using Linq To

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.