Deno by Example
examples.deno.land
examples.deno.land
Still don’t fully understand what ‘runtime’ means in this context. It’s not the parser, interpreter, VM, GC I think, because that is the V8 part. It’s not a runtime compiled into an executable like Haskell or Go.
Is it the term used here for a set of standard libraries? Or maybe in interaction layer with the operating system underneath, or the package/build system? Or an umbrella term for all of this?
I’ve been doing all kinds of JavaScript and TypeScript for a long time now without a runtime (I think) so pretty curious.
Node and browser are both runtimes for your JS code.
A browser does all that, so that's the runtime. Similarly for Node's import resolution and its API's for doing I/O.
You could think of it as all the code in the 'deno' or 'node' command other than V8 itself.
Deno doesn’t use it, though. They use Rust ecosystem libraries like tokio. [2]
[1] http://docs.libuv.org/en/v1.x/ [2] https://choubey.gitbook.io/internals-of-deno/architecture/to...
In the (pretty weird, IMHO) JS world, this notion of "runtime" amounts largely to what magical global variables are available. And then, what language features are available.
Deno (properly, IMLHO) hides most of its "nonstandard" features behind one magic global variable: Deno. The rest of what it offers is "standard" which Deno (and all sane persons IMNSHO) interprets as "what the browser supports".
Even that's fucked, in JS-world, because there are a bunch of browsers, and each one of them is like "yea woo I love standards, but fuck that standard". But browsers have a standard, more or less, it's just that all browsers implement only a subset of it. Still, to me, that's "the standard".
So Deno implements its own subset of that standard (but they seem to try hard to implement as much as possible), and then it adds its own "Deno" global object for everything else (like local filesystem access, key-value database, etc that browsers don't support).
An execution environment like Node hasn't traditionally prioritized compatibility with "the browser" and so instead it offers a bunch of top-level built-in things like "fs" or whatever, that you "require()" and then you can use them. And standard things that exist in al(most al)l browsers, like TextEncoder or BroadcastChannel or many other things, don't exist in Node. So one nice thing about Deno is that almost all the code you write for Deno will also work in a browser (unless you use "Deno.launchDroneAndFetchCoffee()" or whatever.
I dismissed Node because it was a super-manual process and experimental.
Bun had some crazy bugs around handling environment variables where they were sort-of baked in at build time instead of evaluated at runtime but only used in some circumstances. I never got to the bottom of it but it was weird enough to put me off Bun because there was clearly something very wrong there and the documentation wasn’t helpful.
Deno worked great. There was one bug I experienced caused by inheriting a node_modules directory that caused it to crash while building, but the fix was released a few days after it was reported.
It’s definitely not as mature as Node, but it’s good enough that I would try it by default for new projects now.
[0] https://twitter.com/deno_land/status/1562771000802279425
I wouldn't pin this on the language, see TigerBeetle as a counter example.
For example, TigerBeetle follows NASA's The Power of Ten Rules for Safety-Critical Code. We require that memory allocation failure be explicitly handled in the control flow, and that no dynamic memory allocation be used after initialization, that all resources (including memory) be explicitly limited, with no hidden allocations.
Our language choices then came down to C or Zig. Zig made most sense.
Zig's correctness philosophy (e.g. extremely explicit control flow) may be different to other languages. But Zig resonated with our own philosophy—in addition to the big examples already given above, we also noticed the little things (e.g. checked arithmetic enabled by default in safe builds).
Their compatibility is getting better and better, so I'm confident Deno will eventually be a clear "better Node".
[0] https://docs.deno.com/runtime/manual/basics/modules/private
//npm.pkg.github.com/:_authToken=${AUTH_TOKEN}
@myEmployer:registry=https://npm.pkg.github.com/
My impression is that the document you've linked isn't related to their NPM compatibility, but perhaps I need to look more into it.Of course there's a lot of other databases, but we programmers forget that for beginners it is setting up the DB which is the barrier to entry.