Polyglot 101
Traditionally, software is written in just one language at a time: there are JavaScript apps, and Python scripts, and all sorts of other things developers make.
Elide offers a new way to think about software: in multiple languages at once (hence, "polyglot!"). But what does that mean? This guide explains how multiple languages can work in tandem to accomplish amazing things.
Starting Imperatively
Let's start with a simple imperative example of how multiple languages might work together. We could begin with some Python:
Now let's save that file and create a new one. This time, in TypeScript:
We've defined some code in Python, and now we are importing it into TypeScript. This code is runnable with Elide:
But why?
Have you ever wanted to write a Python app which could host a React UI?
There are tons of cases where one language is good at something, another is good at something else, and your app has to do both. Elide is what bridges this gap.
Isn't that inefficient?
Elide outperforms Node, Deno, and CPython. But, since you may be wondering, in the code sample above 👆
There is just one process. No, Elide isn't calling out to Node with your source code, and then to Python, and stitching between with JSON or something. That would be gross. There are systems that do this; Elide is not one of them.
There is just one governing interpreter. Elide uses language implementations from the GraalVM team, built on top of Truffle. Instead of two interpreters (Python and JavaScript, in this case), there's just one, but it speaks both languages.
There is no serialization going on. The
name
value doesn't need to be transformed as it crosses a border between Python and JavaScript. It's just a string; both languages can use it as they would normally.
Skeptical? Good. The best engineers often are. Let's beat the serialization allegations:
And:
Elide will happily run this code. This is impossible with JSON, or Protobuf, or any other trickery on top of Node.js or CPython.
When people see a demo like this, the "polyglot" concept immediately begins to make sense. That's great, but how do 2+ languages interact in one context?
Let's do some exercises
Now that we are thinking in a roughly-polyglot way, let's test the waters with some basics: many applications have to read environment variables or write to a file. You can follow the guides below or skip ahead.
- Exercise: Environment Variables
Read env variables and use Elide's host policy to restrict host env access
- Exercise: Filesystem Basics
Read a file using Node.js built-ins (
node:fs
).- Exercise: Debugging
Step across language boundaries in a debugger
- Exercise: Interop
Get familiar with cross-lang interop
- Exercise: Servers
Writing polyglot servers with Elide
Benchmarking
Elide makes use of language runtimes from the GraalVM team which are benchmarked extensively and continuously. People often ask if they can replicate these benchmarks. The answer is yes, you are encouraged to!
There are some tools we can recommend:
Read more about Elide's Performance