News for hackers. Stuff that matters.
Re:Ask HN: How do you test SQL? by mLuby on Tuesday January 31, 2023 @06:17PM (#34603780)
You tell SQL what you want, not how to get it. That's declarative.

  SQL : CSV :: GraphQL : JSON :: React : HTML
Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @06:57PM (#34604184)
Really?

SELECT 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

Re:Ask HN: How do you test SQL? by indymike on Tuesday January 31, 2023 @07:37PM (#34604569)
I’ve not encountered your definition of declarative before. SQL is often cited in cs texts as an example of a declarative language. That said, SQL does have a lot of imperative features, but those features are used to declare the result of the sql dml query.
Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @08:05PM (#34604878)
SQL does not make sense as a declarative language to me. How you can say that SQL and HTML is the same by nature?
Re:Ask HN: How do you test SQL? by indymike on Wednesday February 01, 2023 @11:14AM (#34612615)
"Declarative language" does not mean "free of computation". It does mean the language generally specifies an output. HTML does have computation in the form of <script> tags. What makes HTML and SQL declarative instead of imperative is that in both SQL and HTML the document specifies an specific output that is wanted from the browser (in HTMLs case) or database (in SQLs case). Your earlier example of SELECT (1+3); is something that can be done in HTML (many different ways), too. Reality is that declarative languages would be little more than file formats without access to computation. For example, it would be impossible to write a query that always returned results for the interval of last week, without having to change the query every time you run it without the now and interval commands.
Re:Ask HN: How do you test SQL? by spamtarget on Wednesday February 01, 2023 @07:43PM (#34620427)
I never meant "free of computation", I actually mentioned a lot that forget computers and softwares, and focus on languages.

<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.

Re:Ask HN: How do you test SQL? by indymike on Friday February 03, 2023 @03:26PM (#34647242)
> 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.

Re:Ask HN: How do you test SQL? by indymike on Wednesday February 01, 2023 @02:56PM (#34616638)
Further, another way to look at it is, declarative languages specify output, imperative languages focus on the steps to generate outputs. In imperative code, I'm worrying about how instead of what. In declarative code, I'm worried about what instead of how. As in all things, neither of these statements will be absolutes - there are situations and times where a declarative language user will worry about how the query planner will execute, and there are times where an imperative language user will write very much declarative code.
Re:Ask HN: How do you test SQL? by spamtarget on Wednesday February 01, 2023 @08:07PM (#34620627)
>neither of these statements will be absolutes - there are situations and times where a declarative language user will worry about how the query planner will execute, and there are times where an imperative language user will write very much declarative code.

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.

Re:Ask HN: How do you test SQL? by indymike on Friday February 03, 2023 @03:47PM (#34647514)
> That's right, in practice everything is more like a mishmash of everything.

I agree, and will die on this hill :-)

Re:Ask HN: How do you test SQL? by preseinger on Tuesday January 31, 2023 @07:09PM (#34604294)
Does the presence of conditional expressions mean that the language which permits them is necessarily not declarative?
Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @07:20PM (#34604401)
no, the approach makes the difference.

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

Re:Ask HN: How do you test SQL? by preseinger on Tuesday January 31, 2023 @07:49PM (#34604693)
> 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

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.

Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @08:16PM (#34604973)
>This is exactly what SQL is. There are exceptions, but they're exceptions.

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?

Re:Ask HN: How do you test SQL? by gfody on Tuesday January 31, 2023 @09:18PM (#34605486)
it is possible to reduce your query w/case statements to essentially "all cost of all employees" if you would model every type of employee and cost relationally (and then some view for all-employees which is the union of each type projecting the approptiate cost and so on) then your query gets to just ask for records again without having to "tell how" those things are to become records.

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.

Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @10:18PM (#34605887)
It is not possible, but it is the future, you already have a glimpse with chatgpt creating sql for you. Now that is real, 100% declarative SQL, no debate on that, as everything will be some-when in the future.

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.

Re:Ask HN: How do you test SQL? by preseinger on Tuesday January 31, 2023 @09:22PM (#34605524)
You do not understand SQL. HTML and SQL are essentially unrelated. It would be to your benefit to spend some time reading and learning on these topics.
Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @10:02PM (#34605782)
Of course they are, however they are both languages. And you classify them into the same category, so it should have some similarities, right?
Re:Ask HN: How do you test SQL? by preseinger on Friday February 03, 2023 @03:06PM (#34647009)
I am not classifying them into the same category. I am explicitly doing the opposite. SQL is declarative, HTML is a markup language, they are categorically different.
Re:Ask HN: How do you test SQL? by gfody on Tuesday January 31, 2023 @07:46PM (#34604656)
I'm not the person you were replying to but you've misunderstood their comment - they were saying that CSV is to SQL what JSON is to GraphQL (and HTML to React) these being declarative languages for records, objects, and markup

A "case" statement in SQL (or an "iif") is still declarative, how else would you express specific cases when necessary?

Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @08:02PM (#34604854)
Oh, i see, i did not get it. However i don't understand how "You tell SQL what you want, not how to get it. That's declarative" related to that list

iif and case by itself is not declarative or imperative. only an entire language can be described as such

Re:Ask HN: How do you test SQL? by gfody on Tuesday January 31, 2023 @08:20PM (#34605003)
SQL is declarative in the sense that you dont specify the strategy to employ in retrieving the data (ie which index to access and how, whether to sort and merge or build a hash table etc etc) however you DO need to specify how to represent your data as records (which could entail specific cases for when certain values go in the same cell as you pointed out).
Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @08:29PM (#34605083)
You don't care about how the SQL server gets the data the same way how you don't care about what is happening in the background when you use File.ReadAllText The technology behind does not define the programming paradigm. You can speak about these paradigms without computers.

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)

Re:Ask HN: How do you test SQL? by gfody on Tuesday January 31, 2023 @09:01PM (#34605343)
I think what you're saying is accurate for describing what style of programming you might be doing, afterall we can write C++ in a declarative style. if you're coding in SQL then you're doing functional programming, but that doesn't change the fact that SQL is a declarative language for describing recordsets. you wouldn't refer to SQL as a functional programming language because it's not general purpose.
Re:Ask HN: How do you test SQL? by spamtarget on Tuesday January 31, 2023 @09:55PM (#34605727)
No, programming style can be "hacky", "script kiddie" or "architect kind design" or whatever. I'm speaking about "programming paradigms".

"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.