6 ms·
You tell SQL what you want, not how to get it. That's declarative. SQL : CSV :: GraphQL : JSON :: React : HTML
by mLuby 4y ago
You tell SQL what you want, not how to get it. That's declarative.
SQL : CSV :: GraphQL : JSON :: React : HTML
- spamtarget 4y agoReally? 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
- preseinger 4y agoDoes the presence of conditional expressions mean that the language which permits them is necessarily not declarative?
- spamtarget 4y agono, 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
- preseinger 4y ago> 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.
- spamtarget 4y ago>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?
- gfody 4y agoit 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.
- deleted 4y ago[deleted]
- indymike 4y agoI’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.
- spamtarget 4y agoSQL does not make sense as a declarative language to me. How you can say that SQL and HTML is the same by nature? Also I can't see why we can't argue about this against the literature. Saying "you are wrong because 20 years old textbook say you are wrong" is not an argument for me
- indymike 4y ago"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.
- spamtarget 4y agoI 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.
- gfody 4y agoI'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?
- spamtarget 4y agoOh, 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
- gfody 4y agoSQL 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).
- spamtarget 4y agoYou 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)
- gfody 4y agoI 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.