4 ms·
What do others think of "SQL as a very functional language?" The insight that businesses decouple data from procedures is right. But SQL has poor support for f
by millstone 8y ago
What do others think of "SQL as a very functional language?"
The insight that businesses decouple data from procedures is right. But SQL has poor support for functional hallmarks such as recursion, functions as first-class values, etc. SQL is not functional but declarative: it's less Haskell and more Prolog.
- haolez 8y agoI agree with your assertion and I think that SQL is a fantastic language, regardless of which implementation we are dealing with.
- whackjob123 8y agoI completely lost him at that point. Like you said, SQL is more like prolog. To boot, it's a language designed to mutate data, using a sequence of commands. Not very functional in my mind. I think the whole article suffers from a poorly defined notion of what functional exactly means, and what OOP exactly means, and I think the next step would be to stop thinking in terms of OOP and functional because most industry languages tend to blend elements of both now, so it is better to break it down into the features that you find useful and analyze them one by one such as, can functions be values, is there immutability support, pattern matching, types of polymorphism, generic data, etc etc
- sidcool 8y agoIn my opinion, SQL is a good mixture of DSL/Declarative & Functional paradigms. It enables programmers to specify operations to perform without worrying about the 'How'.
- pdonis 8y ago> What do others think of "SQL as a very functional language?" I think the author is using "functional" in a different sense from its usual use nowadays. Basically I think he just means that with SQL, you focus on the operations you're performing (i.e., functions), and the functions are only loosely coupled to the actual data, since you can write many different functions (SQL statements) on the same database, and the same SQL statement can be applied to many different databases with different underlying storage architectures. But of course, as you note, SQL being "functional" in this sense does not mean it supports more recent features associated with functional programming.
- joe_the_user 8y agoThe idea of functional programming is much older than this article. I learned the principles of functional programming in the 90s at San Francisco State University, on a language actually called "FP"[1]. Similarly, SQL has been known as a logic/declarative language since it's start and these two paradigms have been known to be different for a long time. I don't think you can get away from a situation where the author is abusing the concept and terminology. Edit: the argument seems especially galling given that logic languages seldom get credit as "industrial strength" and functional programming has a huge following of "language geeks" when a logic programming language is what works-with a broad swath of regular languages. [1]Also, John Hughs' manifesto, Why Functional Programming Matters published in 1990. https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.p...
- coldtea 8y ago>I think the author is using "functional" in a different sense from its usual use nowadays. Basically I think he just means that with SQL, you focus on the operations you're performing (i.e., functions), and the functions are only loosely coupled to the actual data, since you can write many different functions (SQL statements) on the same database, and the same SQL statement can be applied to many different databases with different underlying storage architectures That's called "declarative" -- not "functional".
- pdonis 8y agoHuh? To me, "declarative" means focusing on just stating what you want the result to look like, not what operations need to be performed to obtain the result. I agree that SQL could be considered declarative as well as functional, since an SQL statement has aspects of both. But I don't see how "focus on the operations" is declarative.
- coldtea 8y ago>To me, "declarative" means focusing on just stating what you want the result to look like, not what operations need to be performed to obtain the result And that's exactly what SQL does. You specify what the result should be like "I want the result to have those two sets common elements, but only items where this column is larger than 10, and I want it grouped by these 2 columns and ordered by this over column", and now how to get to it (e.g. open these files, read those indexes, load a hash table with matches, iterate over them to find those where column > 10 etc). GROUP BY x and WHERE X > 10, etc. are not "the operations performed to obtain the result", are high level descriptions of the result we want. In fact in CS courses, SQL was one of the canonical examples of declarative programming (despite some nits to the premise, e.g. the ability to specify use of indexes etc).
- slifin 8y agoYeah I'm learning Datomic's datalog and I can see how it solves a number of things in my SQL solutions, that I didn't even realise were problems