SQL : CSV :: GraphQL : JSON :: React : HTML SQL : CSV :: GraphQL : JSON :: React : HTMLSELECT CASE WHEN employee.type = 'contract' THEN salary CASE WHEN employee.type = 'full-time' THEN salary + benefit_costs END CASE FROM employee
Tell me how is this declarative?
-SQL is functional -CSV is not a language, it's a data format -GraphQL, im not familiar -JSON is literally executable javascript code, arguable -React is a javascript framework, binding is a declarative nature (if it has it, i dont know it too well), but it is not a language, it's a framework -HTML is absolutely, 100% declarative, yes
when you create html, you dont care how the rectangle is drawn, you focus on defining the result itself.
if sql was declarative, than the code of the SQL above would be: GIVE ME ALL THE COST OF THE EMPLOYEES --, I DONT CARE ABOUT THE DETAILS
the details, which in this example the difference between fulltime/contract employees would be handled by the framework (SQL server) which would already has a concept of two kind of employee like in HTML can have rounded tips of rectangle or angular tips, because the framework already understand these ideas
an SQL query itself (if no structured language used) is just a big function applied on a set. It has never have a concept of the things you do, like building an accounting solution to a company. HTML has the concept of paragraphs, button, etc etc, all the things you wanna do. but with SQL you step by step define what you want by conditions and transformations.
or another way to separate them -imperative is a combination of -sequence/condition/loop
-function -no loop (cardinality is always multiple) -sequences is encoded as data -conditions <- yes it has conditions
This is exactly what SQL is. There are exceptions, but they're exceptions.
> an SQL query itself (if no structured language used) is just a big function applied on a set.
I don't think you have a correct model of SQL. SQL is a language that expresses definitions, not functions. It is absolutely declarative.
Some extensions of SQL can provide functional capabilities, yes, but they are exceptional.
no, i meant the query is literally this: GIVE ME ALL THE COST OF THE EMPLOYEES
or if we want to formalize more: ALL COST OF ALL EMPLOYEES
the point here that in a declarative mindset EMPLOYEE is a word that SQL server understands, like HTML understand paragraph <p> or table with rows and cells <table><tr><td>
>I don't think you have a correct model of SQL. SQL is a language that expresses definitions, not functions. It is absolutely declarative.
that just not true. without defining the how through transformations and conditions, the only thing you get out of the sql server is a table how it is stored. until you reach a certain complexity you are true, it can be seen as declarative, but my point here, is the approach of problem solving is the separation here. you dont even have to speak about computers:
cooking recipe VS assembly lines in factories VS a robot with ai, which can do whatever is programmed to, but in certain cases work out the details by itself when not given specifically (not the best example, but started to get exhausted)
Also how would you say that by nature HTML and SQL is the same?
I dont think html is anything like sql (only in the sense that all markup languages are also declarative) but a comprable situation would be if you were trying to render some ascii art in html and had to use pre tags in order to tell the layout engine how to show it.
You are describe here the abstraction you create on a primitive (related to the system you design) system, and introduce ideas like "employee" "unions" etc If you do good job, when you programming you combine generic purpose systems and introducing new ideas in a way that another human can understand (words), but in certain way you "made the computer system understand" those things too. That's your job. So basically you teach SQL server that a union employee is a thing with the dbo.IsEmployeeUnion function.
In case of html you are not introducing new things. You actually can, because the browser is really flexible (like i make a non-functional quasi elements a lot, to make the html code itself more understandable), but HTML is not designed for you to introduce new elements/ideas (originally, nowadays kinda with CSS). Anyways this is how you see the difference in another way.
I try to tell all of you how the technical details, the implementation does not matter, only just the language itself, when we speak about paradigms, but it seems i'm failing.
By the way, i think training AI models does not fit to any of the paradigms we have here, it's gonna be (or it is?) a new way to solve problems, and that also has nothing to do with files, or any kind of implementation. The important is what you see on the screen, and what you do.
<script> is Javascript, not html (I mean what's inside), they just smashed together.
>specifies an specific output
That specific output definition is really different.
Consider this:
-task: give me even numbers
-imperative approach:
for i=1 to 100
result += i * 2
next-functional approach
return [1,2,3,...].select(x=x * 2)
-declarative approach (not possible, but for the sake of example)
EVEN NUMBERS = NUMBERS LIKE 2,4,6 AND CARRY ON <-this requires a framework, which understand every word i wrote there.
What i wanna ask you to re-explain these examples with your understanding of classification, but using the same task.
>Reality is that declarative languages would be little more than file formats without access to computation.
That what HTML is. A declarative language and a file which requires a framework.
> Your earlier example of SELECT (1+3); is something that can be done in HTML (many different ways), too.
No, not with strictly sticking to the standard and not use any trickery. HTML was not designed to do any kind of calculation. That's why javascript came later.
I thought you would go here, and I understand where you are coming from: Declarative language != file format and declarative is not a paradigm like functional, procedural, object-oriented.
Every useful declarative language allows for some level of computation. Take a template language - YAML + some template tags. Aside allowing variable substitution, every time, the language grows a way to make those substitutions more useful, so you get things like:
{{ variable_containing_a_date + interval(days=1) }}
Back to functional, oo, procedural: some declarative languages import a paradigm.
Back to the script tag:
Even though it was added after the original spec, <script> is part of the standard for HTML and is one of the reasons it pushed many other formats to the side and the web won. I would submit that HTML+JavaScript is the platform, not just HMTL. One can write declarative code in an imperative language, and the reverse is true.
I do really appreciate you thinking on this, but I think we're best to use the existing definition and example of declarative languages, and not just banish declarative to static file formats.
That's right, in practice everything is more like a mishmash of everything. Your function library could be seen as a declarative language over the top of a generic language.
I agree, and will die on this hill :-)
A "case" statement in SQL (or an "iif") is still declarative, how else would you express specific cases when necessary?
iif and case by itself is not declarative or imperative. only an entire language can be described as such
Imperative programming: really detailed cooking recipe
Functional programming: assembly line of a car factory
Declarative programming: a robot what can do what is programmed for, and sometimes can work with really unspecific instructions (like this one line in a file "Hello world" is not a valid HTML, but the browser still renders it)
"functional programming, but that doesn't change the fact that SQL is a declarative language for describing recordsets"
ok, im describing recordsets for you: this set has 4223 records. I'm thinking of something else, but i can't really describe a recordset with anything else. Describing is not what you do when you create a software. You have a problem and you literally write a solution like an author write a book. And as you said, with SQL, you use a functional approach, how you do it when you use lambda or LINQ. Therefore SQL is functional.
SQL is turing complete with the structured extensions, so in that way can be general purpose, but something is general purpose or not does not decide the paradigm. Usually languages are more restrictive moving to the declarative side of things, but that is by design. The point is that you write less text.