News for hackers. Stuff that matters.
Re:Deno 1.9 by maga on Tuesday April 13, 2021 @04:24PM (#26798730)
The often overlooked selling point of Deno that I find most compelling is the (re)use of web APIs. As a full-stack dev writing isomorphic code and libraries, dealing with ideosincracies of nodejs has been a pain.
Re:Deno 1.9 by paxys on Tuesday April 13, 2021 @04:56PM (#26799184)
When Node first released its biggest selling point was being able to reuse web APIs. It also filled in gaps for APIs that weren't standard in browsers. Then browsers started to add these APIs, and some of Node's implementations naturally diverged (aka the idiosyncrasies that you mention).

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?

Re:Deno 1.9 by brundolf on Tuesday April 13, 2021 @05:12PM (#26799388)
JavaScript itself has gone through about a 10-year transition period from a toy language for writing quick scripts to a full-on general-purpose programming language. It didn't even have a module system when Node launched.

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.

Re:Deno 1.9 by girvo on Wednesday April 14, 2021 @01:29AM (#26803258)
Part of me almost misses `browserify` -- the heady days of "Node modules are the One True Way", with all the constraints that implied. Got a lot done with it and related tooling back then!
Re:Deno 1.9 by brundolf on Wednesday April 14, 2021 @11:22AM (#26808365)
CommonJS worked well enough for lots of things, and it was neat that it was so simple (no new syntax!)

But it had limitations, chiefly that imports/exports were not static. Things got imported at runtime when they got reached, etc. This meant that things like browserify were fudging the semantics in some ways, and it also made it impossible to properly do tree-shaking. The stricter semantics of ES modules are better IMO, despite the pain of transitioning.

Re:Deno 1.9 by bijection on Tuesday April 13, 2021 @05:06PM (#26799319)
You could argue that the apis in question are more mature now than when Node was first released.

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.

Re:Deno 1.9 by the_duke on Tuesday April 13, 2021 @05:40PM (#26799699)
The selling point was being able to write server code in Javascript and potentially share code between UI and server.

Node never implemented any of the essential browser APIs like XMLHttpRequest or later fetch, localStorage, etc.

Re:Deno 1.9 by halfmatthalfcat on Tuesday April 13, 2021 @05:57PM (#26799872)
Nope, that’s why there’s a million node-fetch, isomorphic-fetch, etc variants
Re:Deno 1.9 by maga on Tuesday April 13, 2021 @05:15PM (#26799421)
Indeed. I remember that, I have been using node since the very early days, and switched to it for precisely that reason--that I could use the same language through my web application. Nevertheless, when we did get those modern web API, Node was slow to change or adapt them, although, it's doing its best now.

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.

Re:Deno 1.9 by eyelidlessness on Tuesday April 13, 2021 @09:06PM (#26801795)
Overall this is true. And beyond that the TypeScript team is heavily involved in TC39, and quite a lot of TC39 proposals are specifically designed to be enhanced by TS. That said...

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.

Re:Deno 1.9 by folkrav on Tuesday April 13, 2021 @10:24PM (#26802267)
> enums [...] everybody but me hates them

Hmm, what did I miss, why do people hate them exactly?

> 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.

Maybe I'm a bit masochist, but I can't say I feel a lot of compassion for people using experimental features in missing-critical production code.

Re:Deno 1.9 by lobstrosity420 on Tuesday April 13, 2021 @10:42PM (#26802352)
>Maybe I'm a bit masochist, but I can't say I feel a lot of compassion for people using experimental features in missing-critical production code.

To be fair, decorators are an experimental feature in name only at this point. A lot of libraries force you to use it, including Microsoft's own tsyringe and the beyond popular TypeORM. NestJS is a reasonably popular framework that will codegen services with decorators in them. As the OP of this thread said, the toothpaste is out of the tube now.

Re:Deno 1.9 by folkrav on Tuesday April 13, 2021 @10:43PM (#26802365)
Fair point.
Re:Deno 1.9 by lygaret on Wednesday April 14, 2021 @02:18AM (#26803571)
the entire angular2+ ecosystem as well
Re:Deno 1.9 by tengbretson on Wednesday April 14, 2021 @10:50AM (#26807887)
> Hmm, what did I miss, why do people hate them exactly?

They operate in a weird gray-zone between being just compile-time types vs. an actual readonly object in the runtime. I don't think I've seen a use case for them yet that wouldn't have been better accomplished with a union type of string literals and using const string literals in the code.

Re:Deno 1.9 by folkrav on Friday April 16, 2021 @12:05PM (#26835627)
Say all you need is a fixed set of strings that get reused everywhere. What is better accomplished by defining a union type AND consts literals rather vs creating a single string-based enum and using that everywhere? I feel like I'm misunderstanding...
Re:Deno 1.9 by mssundaram on Thursday April 22, 2021 @01:23AM (#26899052)
You don't even need the const literals.

    type Color = "red" | "blue" | "green";
Re:Deno 1.9 by pierreyoda on Wednesday April 14, 2021 @04:19AM (#26804380)
> Hmm, what did I miss, why do people hate them exactly?

In my experience, enums are far less type safe and convenient (usage in switch for instance, combined with a linter) than union types.

Re:Deno 1.9 by flyingchipmann on Wednesday April 14, 2021 @11:26AM (#26808414)
The thing is enum and union type have different use cases. Union type cannot be used to check against incoming data. It's a lightweight type level feature. There is no way for compiler to identify the unknown data object from the network. Enum is essentially an object in memory which can be used in this case.
Re:Deno 1.9 by hayd on Tuesday April 13, 2021 @05:35PM (#26799624)
There's the web APIs which are tested against https://github.com/web-platform-tests/wpt (albeit without full coverage), and there is ffi/plugins - for deno specific things like readFile.

I don't know the history of Node... but why would there need to be a diversion?

Re:Deno 1.9 by tracker1 on Monday April 19, 2021 @03:14PM (#26866801)
Because CJS's "require" is synchronous and was never implemented IN the browser... Deno is close to standards compliant syntax, so much closer to what's in the browser (TypeScript being a super-set). You can use most JS written for Deno in the browser without having to re-write or create odd shims.
Re:Deno 1.9 by dwaite on Wednesday April 14, 2021 @12:40PM (#26809544)
There is a tremendous amount of overlap between the Web and Node API creators, but there has been push-back and slowness to adapt many of the Web APIs in Node by the same group. For example, the delays in adopting ECMAScript modules in node, or the lack of first-party API for fetch.
Re:Deno 1.9 by tkzed49 on Tuesday April 13, 2021 @05:02PM (#26799265)
How do you actually go about writing isomorphic libraries for browser/deno? It seems like for frontend code you'll have some build system that resolves imports to node_modules, whereas deno code imports from e.g. deno.land. How do you write library code with dependencies that can support that and the other differences in the module systems?
Re:Deno 1.9 by sjy on Tuesday April 13, 2021 @05:11PM (#26799382)
Deno uses ES6 modules, which are supported by modern browsers. There’s no node_modules. https://deno.land/manual/examples/import_export
Re:Deno 1.9 by tkzed49 on Wednesday April 21, 2021 @05:14PM (#26895529)
Yeah, I guess if you don't use typescript? But isn't that a lot of the appeal of deno? The browser can't import a TS module.
Re:Deno 1.9 by sdfhbdf on Tuesday April 13, 2021 @06:01PM (#26799911)
Just like you did in the browsers back in the day when you imported code from URLs with <script src="">, the "deno way" is supposed to follow browsers in these regards as well.

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...

Re:Deno 1.9 by coolreader18 on Tuesday April 13, 2021 @05:31PM (#26799597)
Maybe there's a bundler/webpack plugin that supports deno's import system, so it just fetches whatever http urls/analyzes the import maps and turns it into a normal web bundle.
Re:Deno 1.9 by IggleSniggle on Tuesday April 13, 2021 @07:13PM (#26800707)
Deno’s import system is just the ecmascript import system. So, it works exactly the same way it does in the browser. Or with curl. Or whatever. You just supply a uri and get the resource at that location. Things like import maps are just a way to make that more convenient during development, but there’s no secret system for pulling these pieces together; it’s just the ecmascript module standard (that didn’t exist until more recently).
Re:Deno 1.9 by eyelidlessness on Tuesday April 13, 2021 @09:09PM (#26801819)
Yes there are plugins for this in pretty much every build tool and for Node. But they all have a bunch of caveats and mutual discrepancies.
Re:Deno 1.9 by zdragnar on Tuesday April 13, 2021 @05:21PM (#26799491)
Snowpack might be an option
Re:Deno 1.9 by eyelidlessness on Tuesday April 13, 2021 @09:15PM (#26801845)
Their companion CDN (and namesake umbrella parent company) is also a first class part of Snowpack.

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.

Re:Deno 1.9 by chris_engel on Wednesday April 14, 2021 @02:44AM (#26803756)
There has always been an extra DNS lookup wirh a CDN. Thats even the point of the CDN since based on where you are, you will be served from a location as physically close to you as possible.

Where did you get the information from that CDNs arent as good as they used to be?

Re:Deno 1.9 by richeyryan on Wednesday April 14, 2021 @03:51AM (#26804206)
Safari and Chrome now use a combined cache strategy using the URL of the resource and the top level domain of the site loading that resource as the cache key.

For scenarios that were previously popular like using the jQuery CDN, you won't get the benefit of the user having jQuery in their cache from another website. You will however still get the proximity benefit you describe. CDNs are obviously still quite useful, just not for getting cache hits on popular libraries.

https://www.stefanjudis.com/notes/say-goodbye-to-resource-ca...

Re:Deno 1.9 by chris_engel on Wednesday April 14, 2021 @02:58PM (#26811475)
Yeah thats true - so you explicitly mean CDNs that serve a single thing only.

Using a CDN for your static files is just as fine as it always has been.

Re:Deno 1.9 by eyelidlessness on Wednesday April 14, 2021 @09:27PM (#26815200)
> Where did you get the information from that CDNs arent as good as they used to be?

The other comment addressed this, but to be clear. One of the common usage of external CDN resources is predicated on a performance benefit: if multiple sites use the same resource, it’s more likely to be cached already and much less likely to be impaired by the drawbacks (DNS hit, external network factors). But since browsers have shipped cache partitioning for very good privacy reasons (as other comment mentions, caches are prefixed by the requesting origin), you get no cache benefit and all of the detriment of a clear cache.

Essentially the only reason to use a CDN for third party resources now is if you can bet the CDN will perform better than your local, already DNS-resolved host.

Re:Deno 1.9 by FractalHQ on Tuesday April 13, 2021 @04:36PM (#26798899)
What do you mean by reuse of web apis? I’m curious to read up on this feature.
Re:Deno 1.9 by monocasa on Tuesday April 13, 2021 @04:39PM (#26798946)
Defaulting to browser based APIs when they exist (like a global 'window' element to access the DOM), rather than reinventing the wheel the way Node did. Although to be fair a lot of Node APIs predate their browser equivalents, and in a lot of ways the browser contains a 2.0 version of a lot of Node APIs.
Re:Deno 1.9 by paxys on Tuesday April 13, 2021 @04:50PM (#26799099)
I can't think of a single case of Node reinventing the wheel with their APIs. Like you said, they were all created to fill gaps in browser JS implementations. It's obviously going to be hard to reconcile the two as browsers themselves increase their API surface, but then Deno is going to run into the same problem eventually.
Re:Deno 1.9 by jonny_eh on Tuesday April 13, 2021 @07:34PM (#26800987)
Node introduced the "global" object instead of using the existing "window" object the pre-existed in all browsers.
Re:Deno 1.9 by sdfin on Tuesday April 13, 2021 @09:23PM (#26801890)
At least whe have "globalThis" now.
Re:Deno 1.9 by IggleSniggle on Tuesday April 13, 2021 @07:15PM (#26800736)
I think that depends on how much deno commits to following the web APIs with each release.

Actually, nodejs has really done a lot of catching up with deno in this regard. It just has to support both the “legacy” way and the “forward looking” way where deno does not.

Re:Deno 1.9 by rektide on Tuesday April 13, 2021 @08:15PM (#26801398)
node actually invented a lot of wheels. node was first with promises (a couple major iterations!), streams, uhh I dunno what else. file access (we're just getting that now in the browser after some old ill supported early attempts). modules.

the web reinvented many of these wheels.

Re:Deno 1.9 by eyelidlessness on Tuesday April 13, 2021 @09:20PM (#26801876)
Node didn’t introduce the Promise API. Although it definitely instigated it. Node, with its async IO model, was just littered with callbacks. There were a zillion different approaches to async APIs that could ease that. Promises were, well, the most promising. But years of iteration and competing standards came and went before Node adopted them as the preferred API. And they did so right along with browser vendors and web standardization bodies.
Re:Deno 1.9 by rektide on Tuesday April 13, 2021 @10:35PM (#26802328)
I was referring to node <0.1.30[1] which did have promises for a while. largely from jQuery deferred, which were ungood in a couple ways I don't remember. but also remarkably similar.

I still largely think kris kowal building the "Q" promise library is what made promises interesting, what surfaced the idea that we might want to first-class our completeablea/futures. I know kris had some specific inspirations but I forget what.

pains me somewhat to this day that promises ultimately became somewhat un-value like, that handlers don't get to see what it was resolving. all the chain/spawn discussion, the functional promise folk: they got rolled by those insisting we had to target only the lowest rings of the developership, and that allowing more potent systems was unacceptable. wish I could find those es-discusa threads, for the powerful sorrow of the afteath, what we are stuck with, in it's so lites form, haunts me. especially as we double back a decade latter & invent controllers & signals toanage our promises. which we would have had for free.

way off topic now. forgive me my late night ramblings.

[1] https://github.com/nodejs/node-v0.x-archive/blob/v0.1.30/Cha...

Re:Deno 1.9 by maga on Tuesday April 13, 2021 @04:52PM (#26799130)
This. I started tinkering with node shortly after I heard Ryan introduce it at JSConf EU, and it was a very different world, not much for Node to draw from on the browser side, no modules, no promises, not even TypedArrays IIRC.
Re:Deno 1.9 by tehbeard on Tuesday April 13, 2021 @04:38PM (#26798935)
Things like ArrayBuffer/view, fetch(...) and worker threads being the same spec/interfaces as the browser implementations rather than homegrown stuff like Buffer, child_process and any number of npm wrappers around the http module in node.
Re:Deno 1.9 by TechBro8615 on Tuesday April 13, 2021 @05:01PM (#26799254)
Hopefully the story is the same in five years after Deno and browsers have both had time to evolve. Are there plans in place for tracking future updates to Web APIs in Deno?
Re:Deno 1.9 by mark_and_sweep on Tuesday April 13, 2021 @07:12PM (#26800696)
I believe so. Recently Deno started running a subset of the Web Platform Tests to test compatibility.

See: https://deno.land/manual/contributing/web_platform_tests

Re:Deno 1.9 by tengbretson on Tuesday April 13, 2021 @04:40PM (#26798953)
Things like using UInt8Arrays instead of Node's homemade Buffer class, fetch, using WHATWG's implementation of Streams, Blob, WebWorker, etc.
Re:Deno 1.9 by austincheney on Tuesday April 13, 2021 @05:25PM (#26799533)
Node's homemade Buffer class uses UInt8Arrays. https://nodejs.org/dist/latest-v15.x/docs/api/buffer.html#bu...
Re:Deno 1.9 by bavell on Tuesday April 13, 2021 @08:39PM (#26801571)