3 ms·
Is SQL a declarative language? It requires predicates for everything. Even declaring a schema requires a predicate, which doesn't seem any different than functi
by deckar01 8y ago
Is SQL a declarative language? It requires predicates for everything. Even declaring a schema requires a predicate, which doesn't seem any different than function arguments to me. "select" abstracting the underlying DB engine's "control flow" doesn't seem characteristically declarative. It seems like the same type of standard library that any imperative language would offer for convenience.
Edit: Apparently functional programming is declarative.
- empath75 8y agoIf it's not, then nothing is.
- deckar01 8y agoApparently functional programming is considered a form of declarative programming. That doesn't make much sense to me, but I guess relative to writing assembly or C it is declarative. The distinction seems arbitrary, because even C and assembly contain abstractions for more complex operations taking place in the OS and in the hardware.
- deleted 8y ago[deleted]
- taffer 8y agoThe difference is referential transparency: In declarative programming, an expression always returns the same result, no matter where and in which order you use it. Contrast this with an expression like a += 1; in C, which returns a different result each time.
- rgoulter 8y agoA cliche example is "squares of values". imperative code would be something like: fn squares(array A) array B; for (idx, x) in A { B[idx] = x * x } return B; } (or "B.add" or some other mutating action). whereas 'declarative' code 'declares' what it wants: fn squares(array A) { return A.map { |x| x * x } } I think "declarative" is used more in terms of "declare the result you want, not how you'll get it". It's easier to focus on what the output of the program is with declarative code. Higher-level abstractions are probably necessary, but I don't think it's fundamental to how I'd use the term. :-) Although I wouldn't be surprised to see a variety of ways people use the term.
- jtms 8y agoIs that example code elixir?
- rgoulter 8y agoIt's not anything in particular. Rosetta Code has "apply a callback to an array" example with Elixir. https://rosettacode.org/wiki/Apply_a_callback_to_an_array#Elixir https://rosettacode.org/wiki/Apply_a_callback_to_an_array#El... Enum.map([1, 2, 3], fn(n) -> n * 2 end) Enum.map [1, 2, 3], &(&1 * 2)
- swsieber 8y agoIt is declarative. The db does th query planning, not you. E.g. you don't tell the db whether to do a full row scan or an index scan.
- ako 8y agoYes, as the predicate defines what you want it to do, not how. The database engine will transform your declared goal into an execution plan (query plan), which defines how it will achieve what you want.
- jVinc 8y agoYou can't just blankly state that functional programming is or isn't declarative. sort([42,7,2]) is declarative in that it declares what is wanted not how to do it. But if you write a functional bubble-sort, then that function is not a declaration of intent its a functional reimplementation of a method. Now naturally if your write a Haskel SQL parser/query planner and executor, then you can have a functional implementation of a program that executes a declarative language. And you could easily make a subset of haskel commands that declare your query in a functional manor then, instead of parsing SQL, and that subset, or DSL would be a declarative query language. That does not however make Haskel a declarative language overall. Long story short, an orange isn't a weapon in general, but you can make it into one in specific cases.