670 points · by monstermachine · 5y ago · 236 comments
The standard practice of deps.ts/dev_deps.ts as described in the docs[1] just seems absolutely asinine to me. Importing everything into one scope and then re-exporting from one file just seems like an awful hack.
What do you do if two libraries have functions with the same name? Do you namespace them yourself, or export an object under the name of the library (and therefore give up destructuring?)
The URL thing seems similarly cumbersome and unecessary. Is there something wrong with a configuration file that would map 'package names' to the urls to get them from?, and then import { foo } from "packagename"?
[1]https://deno.land/manual@v1.9.0/examples/manage_dependencies
You can only import a single file per import statement.
Developers create "barrel" files that allow them to re-export all of the important stuff in a folder externally. This allows for namespacing
// foo/index.ts
export * from './foobar'
// main.ts
import * as foo from './foo/index'
new foo.Foobar()
Or use destructured imports to help with static analysis tool that trace imports removing unused references from the final build // main.ts
import { Foobar } from './foo/index'
Node has non standard behaviour where it appends `/index` to the import path if it's a folder allowing you to shorten imports to import {} from './foo'It would be much easier if it was one namespace like in Node.js require. eg. var Foo = await requires("foo", {fs: "/home/user"})
Node.js modules are pretty much perfect besides the security flaws.
You can get around this with a double barrel. In the outer barrel, export your individual things
// index.barrel.js
export * from './foo.js'
Then in your main barrel re-export them under a namespace // index.js
export * as foobar from './index.barrel.js'
Then from you application you are forced to have a named import with the namespace defined // main.js
import { foobar } from './foobar/index.js'
foobar.foo()
You can submit a proposal to introduce namespacing to ES6 importsThis feels to me a bit like if a new browser came around and said "DNS is the root of all evil" and only allowed you to directly type in the IP address of websites.
You can make all kinds of excuses, like "oh, but you can keep a list of your own!" or "hey, you can install this plugin that gives you DNS lookups back", but ultimately as a user I'm gonna say "No thanks, I'll keep using a browser that doesn't needlessly complicate my day."
I'm usually an early adopter for this kind of stuff, and I really like a lot about Deno, which is why this situation just makes me very sad.
export * as Oak from "https://deno.land/x/oak/mod.ts";
export * as Postgres from "https://deno.land/x/postgres/mod.ts";
Then you do this: import { Oak, Postgres } from "./deps.ts";I know you can do this, but then you can't do
import { Function1, Function2 } from "oak";
You could do import { Oak } from "./deps.ts";
const { Function1, Function2 } = Oak;
But that is still an awful workaround. import { Function1, Function2} from "https://deno.land/x/oak/mod.ts";
In the file that needs them? Though then you have a lot of redundant URLs everywhere and god knows how auto-imports could work.Or perhaps you could do
// deps/oak.ts
export * from "https://deno.land/x/oak/mod.ts";
and then you'd do import { Function1, Function2 } from './deps/oak';
I am not a fan of any of these.It updates your dependencies. https://github.com/hayd/deno-udd
There are one or two more feature rich ones. The need for deps.ts can be eliminated with management tools which work with your imports directly.
import { Oak: {Function1, Function2} } from "./deps.ts";
If a server gets hacked those TS can be replaced with malicious versions.
In npm we at least know that a package is immutable once published, someone could publish a malicious version as a newer release but a current release.
Does demo generate some type of file that keeps a hash of all downloaded imports to verify against the next time those imports are downloaded?
The same problem (and solution: package-lock.json or yarn.lock) exists in npm if you use semver version specifiers, or npm itself could be hacked, it’s just a bit more acute in Deno since it’s easy and common to load files from arbitrary hosts that don’t enforce immutable versions.
This is only true as long as you trust NPM. If they were hacked or taken over by a malicious actor, packages could be modified unbeknownst to you.
(If your project only has one module, then you don’t have this problem and don’t need this solution.)
Why not instead create a deps directory, and keep in it one file per dependency? Inside each file, you re-export the library from URL.
This way you can import from files rather than URLs elsewhere in your code, and it should be clear which dependency is being imported from the file name itself.
Perhaps you should be less quick to label anything about it "asinine" or even "awful hack".
No one is infallible. That said, creating Deno after Node doesn't imply that Node was a fail or that Deno will be perfect. Obviously not.
Consider that someone really smart has reasons for doing (or trying to do) things a certain way. Be humble!
I do not understand why deno has gone for this route. It seems primed to produce a package manager eventually, and it seems like a bad idea to leave package manager creation down to whoever makes the first decent tool (which is mostly why npm is the standard for node.)
Deno has the advantage that they are starting from a clean slate without the burden of legacy APIs, but how long will that hold for?
So I strongly doubt the next 10 years will be anywhere near as tumultuous as the past 10. It's very possible that right now is just a much better time to be establishing a JS runtime.
Either way, if Deno is one day replaced by something else, say 'Done' to keep the naming convention, that won't refute the use everyone will have gotten out of Deno in the mean time, in the same way that Deno doesn't refute the use everyone has already gotten out of Node.
Node never implemented any of the essential browser APIs like XMLHttpRequest or later fetch, localStorage, etc.
In case of Deno, I hope they just stick to following the standards and changing with them. They might not, I cannot vouch for them. On the other hand, I was also skeptical about TypeScript following ECMAScript. I though at some point they'll get too much into conflict and MS will refuse to follow, but so far I've been proven wrong. And from the looks of it, TS even deprecates stuff that is likely to conflict with upcoming ES versions.
There are a few longstanding incompatibilities/footguns. And they’re likely to remain due to widespread use, even though most are controversial. Off the top of my head:
- access control annotations (`private` which is compile time only vs `#`). I’m on the fence on this one. I prefer the TS syntax, but obviously not the behavior.
- Enums. Everyone but me hates them. I use them extensively for personal/internal use but try not to force them on others.
- Decorators. This is the big bad ticking time bomb. Last I checked the TC39 proposal has diverged significantly from the TS implementation. And sure it’s marked “experimental” but it’s used a lot and almost guaranteed to be a future conflict. Putting that toothpaste back in the tube is gonna make a lot of people feel a lot of pain.
I don't know the history of Node... but why would there need to be a diversion?
And you can always use `npm`, `node_modules` and `import maps`[0][1][2] to kind of mimic "nodejs way".
[0]: https://wicg.github.io/import-maps/
[1]: https://blog.logrocket.com/es-modules-in-browsers-with-impor...
[2]: https://deno.land/manual/linking_to_external_code/import_map...
However using CDNs in the browser has some big trade offs. Besides obvious concerns sending any data to consolidated third parties, it’s actually a performance detriment now that browsers are caching per origin.
Used to be, using a CDN got you more likely cache hits and better perf on N+1 requests. Now you definitely don’t get that plus you get the extra DNS lookup and whatever performance characteristics of that CDN.
Besides this, it uses the same module system as the browsers do. The JS module system is in my opinion very well designed and intuitive. No need for AMD or CommonJS or Node require's.
Other good things about Deno is that it includes a lot of goodies by default. In that single binary you get in your command line interface:
- A very very decent and fast bundler (bundling in JS is a mess, the Deno is straightforward and needs no config and no hacks, which, surprisingly is unique in the JS bundling scene)
- Testing library
- TypeScript support (for those that like it)
- Documentation generator
- Linter
- Syntax modifier (like prettier)
- Official VS Code plugin
Unlike Node, it uses Rust to bridge the gap between the JS engine and the OS, and leverages on a lot of very cool Rust libraries.
So it's not aiming to be revolutionarily different from Node, rather a second shot at Node.
I also had that question in my mind until I tried deno a couple of weeks ago. There are a few great things I've discovered that IMO makes it a great alternative to node.js:
- Deno + std library has a lot of batteries included. Have you tried creating a web browser project with node.js recently? Just adding a few basic dependecies to compile and bundle your code will leave you with node_modules having hundreds of other dependencies. With recent cases of malware slipping into npm dependencies tree, I'm a bit fearful of starting a new project and infecting my computer (not too crazy imagining that one of the developers of those hundreds of deps will be careless with their SSH keys). "deno bundle" basically solves that for me.
- I can't think of a reason why I would not use typescript these days. Not having to install tsc or create a tsconfig.json is a killer feature for me. Not to mention compiling ts with Deno feels really fast (maybe because they don't have to load the whole typescript compiler into the JS VM on every run?).
- As a consequence of Deno's fast startup + tsc support + great standard library + automatic dependency download, I've found a vastly superior alternative to python for writing quick and dirty scripts for automating various tasks. So for me Deno is not just for writing servers, it is also for using typescript as a script language for automating my desktop and server workflows.
These are just a few things that stand out for me, there's certainty more to Deno than it may initially appear.
* Running a build tool with only file access to the source files
* Trying a cli script without granting it access to everything by just showing the help
In times where a linter has 10000 dependencies, I'm in desperate need of sandboxing.
People on hackernews are easy to judge companies when they leak customer data. But what if we the developers are actually the problem by executing megabytes of foreign code just with faith.
Deno glue code around V8 is written in Rust.
It tries to be as close to the browser API as possible, using ES-Modules instead of CommonJS and doesn't require a package manager.
Also, it compiles TypeScript automatically.
The C++ V8 api is very reasonable to be used in a safe way. So i dont see this as a good point unless of course for people that wan to write some parts that need to be optimized in Rust.
Don't deal with NodeJs that much, but is a lot of node functionality in C++ modules? and if so they are presenting a lot of security bugs in a way that Rust might see appealing?
Because by not having direct access to the V8 api in its native language might limit you, the "glue coder", in the things you really can do.
Maybe this is not the best way of putting it. They use Rust for all the system bits including networking, so it's not like they just wrote some JS to V8/C++ glue code in Rust.
--allow-env allow environment access.
--allow-hrtime allow high resolution time measurement.
--allow-net=<allow-net> allow network access.
--allow-plugin allow loading plugins.
--allow-read=<allow-read> allow file system read access.
--allow-run allow running subprocesses.
--allow-write=<allow-write> allow file system write access.
--allow-all allow all permissions (same as -A)
Node and Deno are dedicated runtimes to run Javascript using the V8 engine. Both provide a standard library of additional functionality to make them worthwhile beyond just browser code.
If so, the introduction of interactive permission prompts is pretty cool.
I see a few comments from more experienced web developers that are quite negative about Deno that seem to generally be centred around the fact it offers very little compared to nodejs, and isn't worth the effort to learn.
Does it have potential as a safer, lightweight Electron alternative? Or are there better options than Deno in that regard?
If they target this, the big chunk of code will still be the same ones on Electron, so i don't think it would get to be safer or lightweight as compared to Electron.
I wouldn't be surprised to see packages developed for a webview but atm demo seems to target server side web platform compatibility... except rendering html!
I wouldn't be surprised to see some packages try to fill the gap, & deno has a much stronger basis for implementation than node (a rpc layer between rust & v8 defines the core character of the project, and an native addon that adds webview methods to the rpc would be natural in Deno, vs a hack in electron).
It's likely you will find some hiccups in latest deno release because it uses rust plug-ins and they are getting overhauled at the moment. Maybe a few more months before getting stabilized.
Maybe I should just hedge my bets and get on the train now even though I don't want to.
You only really "switch" to a new tool if that's what you like the most, not because that's what people like now.
Don't worry, we've all been there.
According to the official Deno releases it's:
"node".split("").sort().join("")
Which makes the pun even wittier.
It runs on the server, it is a typed language, it's faster than v8 javascript (since that is part of the reason for it's existence to eek out more performance)
From what I've seen it can be distributed very as well, and your app is self contained ala Go.
---
So my question is, why don't more people use Dart where they would use a "Node + 'Typescript compiled to JS'" combination, which seems like it has a lot of headaches once your project grows in size
Just scrolling through the list of examples in the Flutter samples directory illustrates this point.
https://github.com/flutter/samples
Use of inheritance seems to be the canonical way of doing things in Flutter and it seems to permeate the code base, both in the use of core Flutter APIs as well as associated library ecosystem. I find them rather hard to read and reason about. It's easy to be a bit confused on encountering a function in an object that inherited the function from a superclass 3 levels up in the hierarchy.
To be clear, I completely recognize that it's unfair of me to attribute to Dart (the language) issues/patterns I see with a library/framework ecosystem (Flutter). But this is mitigated by the fact that Flutter is by far what the lion's share of Dart code is written for today. Please correct me if I'm wrong.
Deno has a partial implementation of Node's API, and even without it it's still the same underlying runtime concepts, so porting is easier than porting to another language like Dart.
As for Deno specifically, it's definitely closer to the "browser" way of doing things than Node is, which is super attractive. The main reason to stick with Node is the huge library ecosystem, but Node itself feels kinda weird & old, since the language has moved in a different direction while Node has remained stagnant (poor support for promises & ES modules, for instance).
Somehow Typescript convinced people from the Javascript side of the fence that they could mix both and eventually upgrade from it. While Dart also tried the same feat, it failed doing so.
Nowadays Dart is only being considered to anything because the team behind it are top-notch and implemented themselves a platform where Dart could be the king.
Giving their talent they were able to create a great platform, where they would made even more success if they used Javascript or Typescript as a development language. But giving they wanted to save all their years of work on Dart, and giving its not a bad technology per-se, it just had a adoption problem, Dart lives on Flutter.
If you want to use Flutter go for Dart, but picking Dart to anything outside Flutter will just alienate the developer crowd as giving even Typescript is some sort of a niche language in terms of adoption, nevermind forcing people to learn Dart.
Dart is doing fine, I'm not sure what race you're talking about?
> If you want to use Flutter go for Dart, but picking Dart to anything outside Flutter will just alienate the developer crowd as giving even Typescript is some sort of a niche language in terms of adoption, nevermind forcing people to learn Dart
Dart is incredibly similar to Javascript/Typescript. You can learn it over a weekend + lookups in Google whenever you see a difference.
Your points are extremely weak.
Dart was heavily marketed as a Javascript successor by Google, this was even before ES5 changes, so Javascript was a even weaker language in terms of design, giving people were doing more and more full applications in the language.
The problem is, Javascript did a catch-up, and the Typescript technique of compiling to Javascript made it more appealing as a successor, not mentioning the design of the language (I know that Dart had this too, but having its own JIT it were more appealing in terms of speed back then).
Meanwhile Google abandoned the project that would allow the Dart VM and bindings to WebKit to coexist with V8. And now that only the Dart-to-JS path could be followed to develop for the Web, Typescript championed this path as it was the only way for them from the beggining.
So if you were following those events, you would know what sort of race i was talking about.
I agree with you that "Dart is doing fine", but is only doing so because of Flutter. As in, people learn Dart to target Flutter, not the other way around.
Im not implying that Dart is a bad language, or technology, because thats not true. Its only a problem of adoption, and it will have a hard time outside of the Flutter bubble.
If it were not for Flutter, Dart would continue is path to a slow death, not because its a bad language or technology, but because of how the events turned out to be, and a little bad luck.
There are a ton of great languages out there, many arguably better than TS in many ways. But for a language to be popular, being great is not enough.
I'm not sure what it is that makes TS so popular, but I am pretty sure that you have to look past mere language qualities for it.
All JS already works inside TS so it's really easy to slowly transition your project over time between the two languages without losing any functionality or needing to take time off to make the transition.
In practice this means, new code can just be written with TS and any existing code updates can be made in TS. After that you can decide whether to even touch the remaining JS which still works.
I think if you want to use Deno, it would have to be from the ground up or a complete rewrite.
import React from "https://esm.sh/react@17.0.2" should work.
For skypack, add ?dts flag at the end to get typescript typing support automatically.
Self hosting is an option too with above.
if you want more npm modules to work with deno, you can contribute to https://deno.land/std/node
Self-hosting seems good, but how does one do that? I didn't see any docs on Skypack's site about self-hosting something that would work as a npm-to-deno-repackaging server.
https://github.com/denoland/deno/issues/9750#issuecomment-79...
Direct link to asciinema: https://asciinema.org/a/9rvK8ANJK0WnQc9nsrFKdC7ir
What's the best path to hosting an API (Fastify-based) on GCP with Deno today?
> The binding improves hello-world throughput by 48% when compared to the std/http pure TypeScript HTTP server.
Nice to read it about Hyper - one of my favorite Rust tools!
Not much right now, aside from 'native' Typescript support and not relying on NPM hell for everything. But as the project matures, it might be useful to take a look at it.
I personally hate having to rely on third party libraries for basic web-server functionalities, so a strong "official ecosystem" with batteries included is an interesting proposition.
If you then scroll to the bottom, the deno tag say "failing".
Just thought I'd share (in case the right people happen to read this).
Currently, I don't see enough reasons to switch to deno for primary projects.
Is there somewhere a getting started with Deno guide, tackling setup of a d velopment environment and some typical use cases as examples?
How would e.g. a company like CloudFlare run Deno instead of v8 for it's serverless infrastructure?
Raptor is an example project which does that: https://github.com/littledivy/raptor
deno_runtime crate provides high level abstractions which you can use to execute code for deno. It is used in the cli. You would still need to bring in your own transpiling layer for typescript support.
As for getting started, you can go through the manual: https://deno.land/manual
They're both built on v8.
Clicking the "deno" name at the top of the linked page takes me to another page that says just "cli" and "deploy". Great!
Clicking CLI (why?) reveals it is a Javascript runtime in Rust. OK, what does one do with that? We know Javascript runtimes come built into browsers. What would I do with one on its own? Anywhere I could run it, I could run code that actually does something, instead.
So I ... run it and use it to run somebody else's JS code? Whose? Or link it into something (what?) that I distribute, that runs somebody else's JS code? Whose? Is this a thing to bolt into an alternative browser, next to a CSS renderer, to compete with Chrome? Or into Chromium, in place of Google's JS engine?
I can guess at answers to these questions, but why make me guess?
These are just release notes, for developers who already know what it is and want to see what's new.
Literally the top result on Google for "Deno":
As far as I understand, you can import packages from anywhere, which is obviously a major concern for anyone behind a corporate firewall
Can we stop implementing JS engines instead of resetting the router?
Does anyone have a short anecdote why I might bother to invest in yet another JS framework?
With that said: I've used it for a couple projects because I'm really interested in its value-proposition, but so far I'm not impressed with the dev experience when it comes to editor integration. It brings its own language server because it has a few tiny caveats, and the language server doesn't work nearly as well as the official TypeScript one. Type changes sometimes don't propagate across files, auto-imports are lacking the file extension (which Deno requires, so you have to go and manually edit them all), etc. Given that frictionless TypeScript support is the major draw, this is a pretty serious issue for me.
I hope it gets there some day, but for me it isn't there yet.
I am curious though: why roll your own? It seems like the only real differences are a) URLs/file extensions in the module names, and b) some type declarations for the system APIs (which I'd think just come down to some .d.ts files, not custom LSP logic). Microsoft's TypeScript language server is a wonder of engineering, and I doubt any small independent team would ever be able to go toe-to-toe with it. Seems like a waste to forego that if there's any possibility of utilizing it. A minimal fork maybe, if nothing else?
Either way, barring your work forcing you to learn something, or you running into a specific problem that requires you to learn something new, you should really treat frameworks/runtimes/languages/etc. the same as TV shows or comics, and I mean this in a very positive way. If you enjoy it and have the bandwidth for it, then of course pick up a new show or comic and invest some time into it! Especially if a trusted friend recommends it to you. It might introduce you to new ideas or give you a different perspective. And most importantly, you probably won't get as much as you would out of it if it doesn't seem exciting. You won't miss out on it if you decide to punt it until later, I promise you. This isn't some Thanksgiving Day sale, if in a year it's more popular than it is today, there'll only be better articles and tutorials that have been written, more bugs having been fixed, and more libraries already existing for it than today. And if it ended up not being that great, you probably won't hear about it in a year anymore, and you will have spent your time on a thing you do enjoy. So don't force it, if it seems cool to you or resonates with you for any reason, try it, otherwise, no big deal!
The point is that "its a runtime not a framework" is not an answer as to why he should learn it or not. At least, not without attaching to it a meaningful explanation as to the benefits he'll get from it because its a runtime, but at that point, we're back where we started: just pitch him on what he'll get out of it, don't correct him on technical terminology.
So in practice: it's super easy to port something, but most of the time you do actually have to port it, unfortunately.
The AWS sdk v3 works really well from Skypack, check out our docs for our Deploy platform, it has an example with DynamoDB https://deno.com/deploy/docs/tutorial-dynamodb#write-the-app...
Deno tries to be as close to the browser API as possible. So it's easier to learn than Node.js if you come from frontend development.
I'm not at that point in my life where new technologies don't excite me. I'm still happy to learn new things. But I fully expect I'm going to get tired of the next wiz bang language, the next gee wow framework, the next hot stuff server. I get it.
There's still value in knowing what you know. I wish people didn't think so much otherwise.
You are basically saying "I feel like I have hit a point in my life where I don't want to learn."
It doesn't matter if it's a framework, language, protocol, specification, book, way of coding, or anything else. Learning is how you gain knowledge and stopping ones desire to gain knowledge is never a "point in ones life". It's just being lazy.
Have some compassion/empathy for those of us that don't have the luxury to be able to constantly keep up with what gets churned out every day.
There is a difference between saying I won't try and convivence me otherwise. Versus saying I can't I don't have the time.
OP is very clearly saying I won't, they have given no indication as to the fact they don't have time to learn.
Never has that been so stark as with Node.js. So many mistakes, mistakes that have been made before. Such a mind boggling lack of purpose. There has never been a need for Node.js - except to play with the cool kids that programme Javascript on the client, server, on any &&^^*!! thing!
I still do not see the need for Javascript anywhere but in a browser, and with Webassembly, most of the impressive things done in the browser do not need Javascript any more.
So my preference is for Javascript to quietly die out in a dignified exit stage left. But I am not always completely correct. So if you must, then use Deno. Node.js is simply awful. Deno is only useless. A vast improvement.
I don't think JavaScript was really the point of it.
(EDIT: but JavaScript having functions as a first-class citizen, and closures, makes it a very good candidate for something that leverages event loops for this kind of thing)
There are many (server-side) things where javascript is not a good choice but "smart-proxies" or micro-service-orchestration kinds of things are definitely super-easy to do in nodejs.
I've also done many languages, like really, and I don't know any better for this task.
What's your choice BTW?
Now, when you filter it all out, it's still not any worse than Python etc - but it's not any better, either.
And to counter on the browser bit, Rust/Go/C/etc can be compiled into Webassembly and yet its not thriving. Similarly on the backends Javascript is thriving too.