Clear Filters
Clear Filters

Does matlab have any declarative programming paradigm version?

51 views (last 30 days)
Is matlab a purely imperative programming paradigm? Would it be possble to write some declarative or functional goal based code piece in some way?

Answers (1)

Shubham
Shubham on 10 Oct 2024 at 4:17
Edited: Shubham on 10 Oct 2024 at 4:20
Hey @ENRICO,
As per my understanding, Imperative and Declarative Programming Languages have some key differences:
  • Imperative programming languages focus on describing how to achieve a result by specifying a sequence of commands, while Declarative programming languages focus on describing what the desired outcome is without specifying the steps to achieve it.
  • Imperative programming languages involve explicit control flow management through loops and conditionals. They also involve changes in program’s state through assignments and updates. However the declarative languages provide abstraction from control flow and state changes.
  • Imperative programming languages example: C++
  • Declarative programming languages example: SQL
However note that every programming language would be imperative under the hood, because eventually the entire code would be converted to a set of simple instructions after compilation.
So essentially declarative languages are just highly abstracted imperative languages.
To answer your query, we can indeed write declarative code in MATLAB. For instance, using MATLAB’s Symbolic Math Toolbox, we can define and solve equations without detailing the solution steps. Example:
syms x
eqn = x^2 - 4 == 0;
solutions = solve(eqn, x);
disp(solutions);
I hope this helps!
  2 Comments
ENRICO
ENRICO on 10 Oct 2024 at 7:19
In spite of the fact you're actually right, and in the end every code, whateverr language used, is converted into a set of instructions (so let's say is in imperative form, as well it is for every turing or von Neumann machine), we shall remark distinction between imperative and declarative paradigms rely on user side perspective, or in different words on way we formulate and solve problems. And that's not a secondary difference! For instance every mathematical problem is well formulated in declarative language rather than imperatiive language.
Declarative language is furthermore more close to human language and way people define their goals, problems and solutions too, consequently more close to AI field too.
My guess, since Matlab is strongly oriented to mathematical and technical problem formulation, coping, and solutions, it would me quite spontanously benefit of a declarative approach much more than a traditional programming language, neither excluding use of imperative languages used as subset language. Indeed one can think imperative form statements as a constrained set of declarative statements.
Resulting code would be:
  • More general
  • More abstract
  • More flexible
  • More reusable
  • Easier to customize
  • More natural (for scienties, technicians and common people)
  • Easier to learn (maybe except for programmers!)
  • Would not limit chances to write imperative statements
I think most of peple would be seriously ineterested in such an option. Concern would exist about code efficiency, but we're actually moving toward new computation paradigms making burden a secondary issue. By the way most of modern algorithms are adopting operations intensive process in spite of load required, thu repute this point of lower relevance.
I'm actually working with symbolic toolbox, as you observed, is closest example to what I'm arguing of, but as you pheraps know, there are considerable limitations, I think could be overcomed in many situations using a declarative language as ground rather than exception.
Is like to say every animal is made by cells, but for sure there's much more in a human than in an ameba.
ENRICO
ENRICO on 10 Oct 2024 at 7:21
In addition you remarked as database language is naturally inclined to declarative.Since use of dabase as support elements is spreading out, and technical tools (think to big data applications) would not be left aside, I guess integrations with these tools would be easier.

Sign in to comment.

Categories

Find more on Programming in Help Center and File Exchange

Tags

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!