Compilers Are Databases [video]
youtube.com
youtube.com
- every non-trivial software is a compiler
- every non-trivial software is a database
Every non trivial software have to read/parse/manipulate/store a lot of data. I think it ultimately permit to simplify thinks to just admit that we are doing a specialized database/compiler. The fact that input data are coming from file, database, network, command line or the code itself and are going to files, database or network is just an implementation detail.
Actually this is even more true than you probably think it is.
The solution is to design your software as a compiler from the start.
Too bad. It's an interesting talk on the architecture of an ambitious compiler redesign. The title is a simplification for the sake of being a keynote.
There was a lot of interesting comments yesterday on a post called "Presumption of stupidity" (https://news.ycombinator.com/item?id=10034883). This could also applied to comments: Do not assume the worse you can imagine by default.
And yes, it's indeed a very interesting talk.
He was talking about how deep the transformation pipeline in scalac is, compared to javac.
I would say that something close to the opposite statement is justified: databases are interpreters, e.g. sqlite is certainly an interpreter with a storage layer.
I didn't watch enough of it to see why he thinks that compilers are databases. Where's the storage layer? I'm interested in compilers and databases, but TBH I am not that interested in Scala, so I stopped watching.
It's misleading to say that compilers are databases if they're not anything like databases people use and know. Probably a more accurate title would have been "Compilers are like functional databases".
Storage is obviously an important part of database architecture. If a compiler doesn't deal with storage, there's only so much resemblance that a compiler and a database can have.
There was an early slide that explicitly said FRP and functional databases were inspiration for the compiler design, but I do agree that the title should have reflected that fact.
The compiler is a database in the sense that it has a memory across incremental invocations. So the 'storage' happens to be in memory but could be on disk.
A database is an interpreter because it has a lexer, parser, byte code compiler, optimizer, interpreter loop, etc. It also has a storage layer (i.e. the B-tree implementation, paging, etc.).
A compiler (like javac) or interpreter isn't a database because it doesn't have a storage layer.
Even a "functional database" has to have a storage layer!
Not that compilers can be used as a general DBMS. I think.
http://openjdk.java.net/projects/mlvm/jvmlangsummit/agenda.h...
And there is an You Tube playlist for the talks already
https://www.youtube.com/playlist?list=PLX8CzqL3ArzUo2dtMurvp...
It strikes me that bringing functional programming to the JVM can / has been done simpler: Clojure being the obvious one, but F# on the CLR is another good template.
Third, Frege is a Haskell implementation for the JVM which to my mind is a much better long-term bet than Scala: it's already a tried-and-tested language, and the work involved in the translation has taken an order of magnitude less time.
It's all very well having some new great language on the JVM, but simplicity is a huge virtue if you want people to build an ecosystem around it.
Scala's FP is more expressive than all of them, by a large margin. Additionally, Scala also supports an useful OO system, unlike for instance the stuff F#/OCaml/... ships.
> It's all very well having some new great language on the JVM, but simplicity is a huge virtue if you want people to build an ecosystem around it.
You realize that Scala has probably the largest, and most meaningful ecosystem of all (non-Java) JVM languages, and is driving a lot of the changes in the Java and JVM space? (Reactive streams, value types, specialied generics, ...)
I expect you're right about the expressiveness, although I don't really know exactly what you mean by this. The "buffet of abstractions" available in Scala actually put me off it. For me, there are too many options available to expect to have readable, maintainable code at the end of it all, especially if you work in a team which regularly creates almost wilfully hard-to-comprehend java.
This video is 2 years old now, but I think it marked the point when I stopped investigating scala. https://www.youtube.com/watch?v=TS1lpKBMkgg&feature=youtube_...
If you watch the presentation by Odersky you'll find that the new compiler addresses most if not all the things that Paul Philips mentioned.
For instance the new compiler has 5 phases. Just like javac.
(A general observation, what you say here is totally fair.)
Of course the video is about Scala, but the problems mentioned are widespread throughout the industry.
What most of those people miss is the fact that Scala is sometime light years ahead of figuring out hard problems. The things considered to be an issue in Scala is often stuff that hasn't even been considered elsewhere.
The video is now 2 years old, and in terms of Scala, that's a lot of time. The strength of the language and the community is that it can adapt pretty fast, and many issues have been/are being addressed.
There are plenty of libraries out there which experiment with different approaches to collections, there is a new, faster and cleaner backend, the new compiler is shaping up nicely, the new IR will solve a lot of binary compatibility/cross compilation/Scala<->Scala.js issues, and scala.meta seems to become one of the best metaprogramming abstractions in languages.
Things are working really well in Scala, so if you have any question or concerns, feel free to voice them, and I'll give you my 2 cents about what's happening in that space! :-)
> Clojure being the obvious one
Clojure, to be honest, is an example of a very convoluted, not very well thought out compiler design.
Disclaimer: I know nothing about the actual Scala compiler passes, just commenting on the number of passes as a proxy for complexity.
EDIT: There's one thing I did not stress in the talk and that makes Nothing a more attractive choice than Top: We want to do copy on write on these trees. I.e. if we transform an untyped tree to a typed one using "withType", we want to be able to reuse the untyped tree and just set the type (unless somebody else had already added another type). If the tree is of type Tree[Nothing], we can do that safely, even if there are still shared references to the same node as an untyped Tree. Getting the type of the shared untyped tree will give a Nothing, and nothing can be done with it. But if the type would be a Top, we would be able to apply some operations on it, so the copy on write would be unsafe.
Yes, compilers indeed have a lot in common with databases. Datalog (and therefore a relational algebra) is a very powerful tool for implementing compiler passes, for asking questions about the AST or various IRs.
EDIT: I'm talking about things like this: http://people.csail.mit.edu/mcarbin/papers/aplas05.pdf
Good paper BTW, though I wish you hadn't prefaced the post by calling people post-literates. This paper deserves more reads.
P.S. I'm really getting tired of the ever growing proportion of video vs. text in the otherwise valuable content. I'm genuinely interested in the topic but there is no way I can watch it. Dreaming of a service which would transcribe arbitrary videos for a tiny fee.