25 ms·
Deno 1.14
- qsort 5y agoOnly tangentially related, but what's the point of a static class block? What problem does it solve that's not covered by either the class constructor or a static const? Doesn't it introduce a weird (stateful!) computation that's hard to reason about? There's probably a use-case I'm missing, because intuitively I'd automatically classify it as bad a practice.
- iddan 5y agoModifying class static private properties
- crabmusket 5y agoIt might be helpful if you have a "registry" of classes. The classes can self-register statically, rather than you having to add separate code which registers the just-declared class. It seems like a minor convenience, but it might play well with inheritance or mixin classes?
- diatone 5y ago> Doesn't it introduce a weird (stateful!) computation that's hard to reason about? Yes and no. For example, maybe you want to initialise a temporary directory on the filesystem for writing files to, for some caching mechanism. The pointer to the cache directory (maybe a const x = {}) can exist anywhere, but spinning up the directory itself in the static class block ensures that it's set up once and only once for all instances of the class. So, any instances get to reuse the directory without worrying about checking for initialisation first. Just another tool in the toolbox, best evaluated on a case-by-case basis
- IshKebab 5y agoThat's a pretty terrible example. No way do you want temporary directories to be created just by loading a class. That violates all sorts of best practices. There's a better example here: https://v8.dev/features/class-static-initializer-blocks https://v8.dev/features/class-static-initializer-blocks You could also use it for initialising generated constants.
- ricardobeat 5y agoWhat’s the difference from declaring the entropy pool in the example outside the class, in the module scope? Still private, still a single shared value.
- IshKebab 5y agoI think just scope (same reason static class members exist).
- officialchicken 5y agoOff the top of my head it's probably useful for implementing The Singleton Pattern, which reduces to one single instance of a class: https://en.wikipedia.org/wiki/Singleton_pattern https://en.wikipedia.org/wiki/Singleton_pattern
- gavinray 5y agoSingletons in JS/TS are done by creating and exporting an instance of a class: class MyClass {} export const myClassSingleton = new MyClass() Static initialization blocks = "Constructors, for static class members/values" Static blocks only run once, like the class declaration itself: class User { constructor(public name: string, public age: number) {} static { console.log("Hello from class User static block") } } const a = new User("a", 1) const b = new User("b", 2) Is transpiled to: class User { constructor(name, age) { this.name = name; this.age = age; } } (() => { console.log("Hello from class User static block"); })(); const a = new User("a", 1); const b = new User("b", 2);
- officialchicken 5y agoThat's pretty close, but you need to add the protections around Object.keys(...) with guards in the getters and setters when using JS/TS. Sealing the entire class static should prevent the need and ability to edit that way.
- jarvuschris 5y agoYou can use it to load or compute derivatives of environmental configuration once
- WorldMaker 5y agoAnother perspective on static blocks is what they replace/help migrate away from. Static blocks are one of the last pieces of the puzzle holding some projects (or at least some particularly old legacy objects in those projects) from migrating to the new class syntax. For better or worse the classic Constructor Function pattern of building objects in JS was full of static initialization code (as it was an easy thing to do in that pattern). Static blocks bring back a way to do that in class syntax while adopting the better scoping rules of class syntax, helping more projects move away from Constructor Functions to class syntax.
- qsort 5y agoYeah, this makes a lot of sense. ES6 classes are restrictive if you look at them from a pre-ES6 perspective. Of course many of those restrictions are "right", but they are restrictions nonetheless. I guess it's a good way to bring back that behavior with the added bonus of being useful by itself in some limited but legitimate cases (sibiling comment mentioned cache initialization, also a good point).
- galaxyLogic 5y agoHere's a pattern I've been using for some time in ES6 JavaScript (on Node.js) : module.exports = class MyClass { // ... static init () { // ... do something, like create and // cache a Singleton etc. return this; } } . init(); The static method init() is executed only once when the class is created and exported. You could add some check to it that causes an error if it gets called more than once. Do static blocks allow me to do something more?
- ravenstine 5y agoFunny, I was just looking into whether I could add a Deno config file to my project. Nice to know this was just made possible!
- maga 5y agoCan you share a bit on the use case, i.e. what do you need configured? Personally, I find Deno's "zero config" approach appealing, although I do have to fight the linter's "ban-types" rule occasionally since suggested type replacements are not equivalent.
- lucacasonato 5y agoPlease open an issue on denoland/deno_lint with examples so we can make the diagnostic messages more useful.
- maga 5y agoThanks, I usually do, but in this case they are typescript issues and have tickets in the ts repo. For example, constructor signature for mixins requires `any` type that conflicts with `no-explicit-any` rule. In another case, `object` cannot be replaced with `Record<string, unknown>` when used with conditional types to mean "any non-primitive value".
- IggleSniggle 5y agoThis comment right here is enough for me to become suddenly much less keen on Deno. If you're somebody who wants to make their ts as close to provable as possible, but also be able to handle dynamic / generative content, then you run into issues of this nature all the time with (for example) linter settings that think they know typescript better than you do, but fail to recognize that there is literally no other way to express some type-concept in typescript without using a larger feature set.
- lucacasonato 5y ago
- siscia 5y agoHow it is the zero-copy ArrayBuffer transfer function implemented?
- lucacasonato 5y agoArrayBuffers are just views on underlying memory owned by the thread a V8 isolate is running on. (Each worker runs on a separate thread, each with its own V8 isolate). When we transfer an ArrayBuffer, we detach the underlying memory from the isolate in the sending thread, and move ownership of the memory area to the receiving thread, where a new JS ArrayBuffer object is created that points to that memory area. TLDR: The memory is never moved, the pointers to it are just detached from one isolate, and instead passed to another.
- csmpltn 5y agoHats off to you, helping Javascript programmers break out of the matrix ;)
- rubyist5eva 5y agoAnyone using Deno in production? Would love to hear how it's going for your team.
- priansh 5y agoWe tried it for a couple months, it was basically a huge hassle getting our stuff to work especially anything that has bindings to CPP (any of the node gyp packages). Also felt like we were putting in a lot more effort to try to get packages with docs for node to work similarly in deno, and weren’t really feeling any value from using deno over node. If you’re a hobbyist or an academic or starting a totally new project that won’t have dependencies/doesn’t need a large community of modules, then I recommend deno. Otherwise I highly recommend sticking to node until deno comes out with something to make the switch more appealing.
- IggleSniggle 5y agoI agree with this entirely. I would absolutely use deno to teach js/ts. I would absolutely use deno in a hobby project. I would absolutely use deno if my requirements were such that I wanted to minimize js dependencies.
- nobleach 5y agoI use when doing DSA/Algorithmic puzzle solving. I typically would use Java for such a thing. TS is pretty nice and when I don't need dependencies.... deno is a nice Typescript first language/runtime/env.
- vorticalbox 5y agoI honestly think the switch (being getting node libraries working in deno) won't happen. I believe it will be a much better if the community puts time into making a larger module pool that is upto the standard of node
- hardwaregeek 5y agoYeah I wonder how this will work long-term. I haven't heard of an ecosystem where they successfully avoided packages. Eventually you need some way of pulling in code that's versioned and has versioned dependencies of its own. Otherwise you end up with implicit versions or rolling your own everything, both of which are less than ideal and not necessarily better than packages. Deno could keep adding stuff to its standard library but I doubt even the largest stdlib could fit all users' needs.
- aikah 5y agoLove Deno and using it as a node replacement. Fantastic work. I encourage anybody who has npm packages to move everything to deno.
- yawaworht1978 5y agoI have 2 projects all in node, using express. Is there an easy way to migrate it? What happens to all the imported modules and dependencies? Can I still use express in Deno the same way?
- andrew_ 5y ago"Easy" is highly subjective. If you're proficient at picking up new architecture paradigms for familiar languages, you're adept with ESM syntax, and refactoring is a skill; then you might consider it easy. It's a paradigm shift, so there's always going to be some friction in migration. For your express needs, check out Oak https://deno.land/x/oak@v9.0.0 https://deno.land/x/oak@v9.0.0
- kroltan 5y agoCould you clarify what is the paradigm shift? Static types? (If so I agree, but using Node does not imply not using TS)
- e12e 5y agoProbably more the removal of nodejs apis in favour of browser apis. For everything. (modules/imports included).
- andrew_ 5y agopackage management, scripts are quite the shift in Deno. there are tools like velociraptor and trex which help bridge the gap, but there's still a lot to learn that's much different than node-world.
- yawaworht1978 5y ago
- benatkin 5y agoDeno is awesome, and it's great to see the WebCrypto additions! My current top feature request is that I wish Deno would have the same permission model for the repl. I highly recommend listening to this recent podcast with Ryan Dahl: https://changelog.com/podcast/443 https://changelog.com/podcast/443
- justshowpost 5y agoThat would make REPL difficult to use, since you would need to know in advance what you want to do to pass the right permission flags. REPL is particularly useful when trying out things "live" as they come into your mind.
- benatkin 5y agoA common use case for a repl is to copy and paste code into it, or to give code to someone and have them run it. It's nice to not have to think about what the code could do to the system before running it.
- justshowpost 5y agoIf you have all code already, just paste into a file and run that file… Otherwise you might want to check out piping support https://github.com/denoland/deno/pull/6130 https://github.com/denoland/deno/pull/6130 Something like `echo "yourcodehere" | deno run -`
- cylde_frog 5y agoI'm convinced to try deno. I only use node for small testing scripts so it should be easy enough.
- sqs 5y agoI tried out Deno last weekend for a fun little hack project (syncing a local Markdown file to a formatted Google Doc), and it was awesome. Writing TypeScript code for Deno feels a lot like writing Go (which is a very good thing to me): - opinionated build/fmt/deps - well-designed stdlib - no need for scaffolding files (.eslintrc, babel.config.js, jest.config.js, mocha.opts, etc.) If that sounds good to you, try Deno!
- kbenson 5y agoI also tried it out recently, because I wanted to make a small utility for myself and liked the idea of it providing a single executable (and bypassing the node/NPM ecosystem for learning a JS/TS based system appealed to me). It delivered on that beautifully, as all I did is switch from running "deno run" as I was for testing to "deno compile" and it delivered to me exactly what I was looking for. A bit large at 57 MB but that's not too bad for a fully bundled JS runtime and no library dependencies except glibc that I could see. As someone that's barely touched node for dev and always been put off by NPM and how that works (and the heavy build chain for some stuff), I find it much more palatable.
- Bilal_io 5y agoThat's interesting. 57mb is big, but not an issue when it's for personal use. Somewhat related, I haven't used rust, but I read that it can produce an executable including the run time for edge that is less than 1mb,. I couldn't find the source, but this article shares how an extension was reduced from 12mb to 4.5mb.
- Bilal_io 5y agoForgot the link https://arusahni.net/blog/2020/03/optimizing-rust-binary-size.html https://arusahni.net/blog/2020/03/optimizing-rust-binary-siz...
- kbenson 5y ago> 57mb is big Honestly, I think most the time you're looking at 10MB+ for interpreted languages that are turned into executables (through a bundling of the runtime and scripts, that is, not through compiling to something else which is likely much smaller if offered). The complexity and size of the runtime is going to necessarily influence that size. V8 is fairly complex compared to most runtimes I think, with the JVM and maybe Mono being notable exceptions, and if you were to bundle the JVM with an app instead of just expecting them to have it installed, I imagine that would be quite large as well. > Somewhat related, I haven't used rust, but I read that it can produce an executable including That's actually the other thing I wanted to do with the project I built in Deno. Since it was very simple, but actually useful for me, I was also going to implement it in Rust. I've played with it a few times over the years, but never really had anything real that needed to be built in it, so this seemed like a good chance to build something real in it. In case anyone is wondering because I mentioned it twice, the project is just reading an ini file which defines browsers, pattern matches to apply to URLs to determine which browser to load based on the URL, and a default browser. The idea being that I can send work URLs to the browser I dedicate to work that's proxied through a SOCKS connection, and other URLs get handled automatically by the browser I use for personal stuff, and I can just make the application my default URL handler. Dead simple, but very useful for my current workflow.
- sgtnasty 5y agoHow many runtimes are there for JS? They seem to pop up once a week...
- singularity2001 5y agofollow up question: how many different incompatible ways to require(), import … are there?
- RobertKerans 5y agoTwo (import + require, which, as import didn't exist, was necessary). Most current tooling is built to handle both (Deno draws a line under it by disallowing the older one)
- RobertKerans 5y agoPractically, number of browsers + 2 (Node and Deno, and Deno is stretching the definition of practical at this early stage). Edit: + Electron + the JS runtime used for Windows ecosystem based on Chakra (not sure if that's still alive though?) + a few other similar ones in that vein for desktop or mobile OS'. + whatever is available for embedded & similar devices, (I guess there will be a few but I know little about that area). + various [highly] specialised business/academic/hobby/PoC/etc runtimes, but they're not realistically things that many people care about.
- simonw 5y agoIt's always worth reading the Deno release notes even if you're not using Deno because it's such a fascinating collection of interesting ideas. I always learn something new from them. In this case it was the existence of the URLPattern web API: https://pr8734.content.dev.mdn.mozit.cloud/en-US/docs/Web/API/URLPattern https://pr8734.content.dev.mdn.mozit.cloud/en-US/docs/Web/AP... Also that Mutual TLS is an alternative term for client authentication.
- alimbada 5y ago> Also that Mutual TLS is an alternative term for client authentication Mutual TLS is where both the server and the client must present certificates and both must verify the others' certificate in order for them to communicate. It's useful for backend server to server communications mainly.
- e12e 5y agoLooks good. Interesting that they are "bringing back" mutual tls (after browsers pretty much axed it..). Is there support on the (deno http) server-side too? Eg: easy to set up mutually trusted, private-/non-ca tls between a deno client and deno server? Perhaps via a self-signed/private CA?
- lucacasonato 5y agoThe server does not support mutual TLS as of yet. Feel free to open an issue on denoland/deno though, so we can look into this :-)
- nexuist 5y agoDoes anyone know if Deno has undergone a security audit yet? I'm interested in using it as a sandbox to run user-submitted JS, and I know its permission model is powerful, but I don't know if it is formally certified (if that's even a thing) and if you can prove that there can't be some exploit that can be used to break out of the sandbox.
- scns 5y agoHas Node undergone such scrutiny? Honest question.
- Soremwar 5y agoYou don't need to test a feature that they don't have
- ricardobeat 5y agoIf you’re thinking of V8 isolates, I believe Cloudflare was running their edge compute product using that.
- nexuist 5y agoOh interesting, do they talk about this somewhere? Is there a conference talk or blog post?
- a5aAqU 5y ago> This release allows deno lint and deno fmt to be configured. That's good news. The main thing holding me back from seriously looking at Deno was the lack of config for the formatting. The default settings weren't right for me, and I tend to avoid projects where you have to fight the tools. I'm going to take another look now.
- scns 5y agoDoes anyone know of providers for running deno FAAS style? Or is a VPS needed?
- up6w6 5y agohttps://github.com/denoland/deno/discussions/11771 https://github.com/denoland/deno/discussions/11771 > NodeJS compatibility, what is our high-level strategy, goals, next steps? > Do we see Node and Deno co-existing, or do we want to think of Node as "legacy"? (Note, there was no clear decision on this question, it was just a conversation) > If we could say "you can run your Express server under Deno faster than Node" would that encourage adoption? No clear answer I really wish they go for a better compatibility with Node and sell themselves as a replacement that is strictly better.
- Mikeb85 5y agoNode is from the days before ES6 and uses a different API. Should just kill it and start fresh. Deno conforms to modern JS standards and is much more pleasant to use in pretty much every way.
- FinalBriefing 5y agoI agree that that's the direction of the future. I wouldn't start a new, important project with Deno just yet. It's still the early days.
- mcguire 5y agoYeah, things like Oracle drivers might be nice.
- galaxyLogic 5y agoNode.js adds new-style APIs all the time. The File-system API now has an async/await version which is a joy to use. When you load a library you can load a newer version or an older one. It's up to you. You can use both.
- justshowpost 5y agoChoose one: 1. Same. 2. Better. You can't have both. Since getting better involves change, which is the opposite of staying the same.
- eins1234 5y agoOne of the most exciting opportunities IMO that Deno opens up, compared to most traditional server-side frameworks, is the possibility for simple url-based live-reload workflows in production. I'd love to be able to develop backend services by pushing source code to some url as I develop, and then have the production instances of the service notified of the changes and reload themselves immediately for a super-tight feedback loop. In theory, building this kind of workflow in Deno should be very feasible, so I'm hoping to give it a shot in the not too distant future, but I'm wondering if anyone else has already tried it?
- tlarkworthy 5y agoI built this https://webcode.run/ https://webcode.run/
- aboutaaron 5y agoThis looks super dope. I also love Observable and have wanted to find more ways to leverage it. This seems perfect!
- tengbretson 5y agoThis is the biggest upside I see for Deno. I imagine a lot of fat could be trimmed in service orchestration with something that simply resembles a headless browser, and all it takes to deploy new code to your running service is giving it the equivalent of an `f5` and you're on your way. Heck lets get this headless browser running in Ring 0 and skip to the end of Gary Bernhardt's dream.
- gavinray 5y agoThis is a really old concept with interpreted languages, Capistrano in Ruby came out in 2006 for this sort of workflow: https://en.wikipedia.org/wiki/Capistrano_(software) 10 year old gist for this exact thing: https://gist.github.com/rchampourlier/1281506/a22148264c457ebb69259261f117548569be6bef Same exists in Node, using PM2 process monitor via rsync/ssh: https://pm2.keymetrics.io/docs/usage/deployment/ Run a command, new code is pushed to server files, you have a file-watcher daemon monitoring the directory and stopping + restarting the app, or you run stop/start as part of the deploy command.
- Zababa 5y agoI know it's a bit superficial, but I love Deno's branding. Their logo is cute and evokes a sense of calm, and the variations on the mascot are nice.
- mastrsushi 5y agoWhy’d they have to give a JS environment the name of a guido.
- IshKebab 5y agoDeno is really awesome for shell scripts. Forget Bash. Forget Python. Deno is way better. You get a fairly sane type system, good performance, easy deployment (it doesn't count as easy if it's a pain on Windows), supports single file scripts with third party dependencies, and no compilation to deal with. There aren't really any alternatives that offer all that as far as I know.
- nikolay 5y agoMy son is 13. He loves Deno. What I don't get is why a 13-year-old can get Deno, and we don't, and it's not as widely popular as it must be for its merits!
- deleted 5y ago[deleted]
- nathanjmorton 5y agoyou got me at no need for scaffolding files babel.config.js