News for hackers. Stuff that matters.
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @06:46AM (#29538738)
Hey - I am Luca Casonato, Deno's new delegate at TC39. I am happy to answer any questions you all might have :-)
Re:Deno Joins TC39 by benjaminjackman on Monday December 13, 2021 @08:52AM (#29539550)
Hi Luca - congratulations! I have a quick question, have their been any proposals to add Subresource Integrity hashes (https://developer.mozilla.org/en-US/docs/Web/Security/Subres...) to the import syntax? I think this effects Deno more acutely than other projects since Deno supports / (encourages?) directly importing from a url with a precise version number encoded in the url. It would be nice to add another layer of safety on top and be able to assert that the module received is exactly as expected. Thanks!
Re:Deno Joins TC39 by gecko on Monday December 13, 2021 @09:07AM (#29539662)
You can do that right now, albeit not directly in the import: it's done via an explicit `lock.json` file (https://deno.land/[email protected]/linking_to_external_code/in...). I'm tempted to agree that having some ability either to directly import, or even just to have that better integrated (right now, you have to ask for the lockfile to be used and pass an explicit path), would probably be a good idea.
Re:Deno Joins TC39 by benjaminjackman on Monday December 13, 2021 @09:35AM (#29539915)
Ok that makes a lot of sense, the link you shared helped explain things in denoland quite well (and reminds me that I really need to give it another go).

From the link I see this example:

    in src/deps.ts

    // Add a new dependency to "src/deps.ts", used somewhere else.
    export { xyz } from "https://unpkg.com/[email protected]/lib.ts";

    Then essentially a create/update lock-file command is run. 

    Then the lock file is checked into version control. 

    Then another developer checks it out and runs a cache reload command.
As you mentioned in practice it's definitely a bit too manual, but should be one of those things that can be automated so it's not the end of the world.

Having said I think having it in the import syntax would provide a few benefits:

1. No extra steps need to be run & hopefully IDEs could auto-complete the hash.

2. Would hopefully be standardized with the browser allowing for native browser support as well (or perhaps lock.json could be standardized with something like import maps)

3. Having it right there provides an extra level of assurance that the integrity hash is going to be used (especially in files intended to be used in the browser and in deno ... not sure how common that is though).

Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @09:25AM (#29539816)
I am not aware of any specific proposals right now. There was some talk a while back about supporting SRI hashes inside of an import map, but that sorta dissolved. For Deno at least you can use a `lock.json` file with the `--lock` and `--lock-write` flags: https://deno.land/manual/linking_to_external_code/integrity_...
Re:Deno Joins TC39 by inbx0 on Monday December 13, 2021 @10:15AM (#29540282)
There's an issue for that to be added as part of import assertions https://github.com/tc39/proposal-import-assertions/issues/11...
Re:Deno Joins TC39 by spankalee on Monday December 13, 2021 @12:01PM (#29541452)
I don't think that's going to fly because it's in-band.
Re:Deno Joins TC39 by spankalee on Monday December 13, 2021 @12:00PM (#29541438)
SRI really, really should be out of band, otherwise SRI digest changes invalidate the entire module graph (and import cycles become a major pain).

I think they're much better as a part of import maps, and later fetch maps so they can apply to non-JS resources like CSS.

Re:Deno Joins TC39 by benjaminjackman on Monday December 13, 2021 @12:18PM (#29541720)
I don't think it's clear cut that it should be out of band 100% of the time. I think there are use cases where inline is useful.

Cycles are definitely an issue, I am not sure there is even way to work around that, except to pull the cycles apart (which may not always be possible but is usually not a bad programming practice when it is). However at the library level, libraries tend not to circularly import each other. If it's being done at the inside a project level the build tool would be generating it so dealing with the module graph being invalidated may not be a hassle (or even necessarily a bad thing), in that case it could modify the files or it could be generating a lock file / import map (which I agree has benefits at that level of not forcing every source to be transpiled, but some of that probably still has to happen for module reloading e.g. appended search parameters to the module path for cache invalidation / module reloading during development like vite.js does for example, and realistically given the nature of the ecosystem some transpilation is going to have to happen either because of .ts or just because of browser differences).

For a top-level deps.ts / dep.js file pattern there probably won't be any cycles. That pattern is to declare a root deps.js file for your project that locks things down and re-exports from third party libraries a use the exports from that as the basis for other imports. For this pattern I think SRI would be extremely helpful and add enough benefit to justify it (even though SRI may not be used in the cases you listed).

Also for smaller projects or main modules having the SRI hash inline is really helpful.

Re:Deno Joins TC39 by hajile on Monday December 13, 2021 @09:52AM (#29540064)
Are you going to push for records and tuples?

Eich was pushing for them in 2011 and they still haven't arrived.

https://brendaneich.com/2011/01/harmony-of-my-dreams/

Re:Deno Joins TC39 by frutiger on Monday December 13, 2021 @10:26AM (#29540393)
He doesn’t need to, the authors of the proposal are on the committee and are planning to see it through.

The proposal is humming along through the stages at a good pace.

Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @12:25PM (#29541804)
Exactly. I am very much in favor of them though. They would be a great addition to the language.
Re:Deno Joins TC39 by BrendanEich on Monday December 20, 2021 @06:31PM (#29631884)
Yes, Bloomberg has a big JS investment due to the Terminal (20MLOC of JS last I heard) and they have employed the records and tuples champions.
Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @11:29AM (#29541084)
I haven’t read the full post, but what’s the benefit of adding language support for records and tuples at this point? My understanding is that engines already optimize the objects/arrays version of those concepts pretty well, and TypeScript enforces the semantics on the dev side.
Re:Deno Joins TC39 by Zababa on Monday December 13, 2021 @11:53AM (#29541345)
> My understanding is that engines already optimize the objects/arrays version of those concepts pretty well

They don't, using libraries that guarantee runtime immutability has a heavy performance cost in JS currently.

Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @12:14PM (#29541666)
By “object approach” I just meant “making a bunch of objects with the same shape”. I’ve read that V8 can optimize these into flat structs.

Is immutability part of the proposed standard? And if so, what’s the benefit over using Object.freeze?

Re:Deno Joins TC39 by Zababa on Monday December 13, 2021 @12:17PM (#29541709)
Immutability is the whole point of records and tuples. You can read more about them on the proposal: https://github.com/tc39/proposal-record-tuple.
Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @12:35PM (#29541933)
Ah so these are actual persistent data structures. Got it, that makes more sense.

The use of the term "tuple" here is odd; I've only ever seen it used to describe fixed-width, non-homogenous sequences. These look more like immutable lists (though I guess they can serve both purposes).

Re:Deno Joins TC39 by Zababa on Monday December 13, 2021 @02:39PM (#29543507)
> I've only ever seen it used to describe fixed-width, non-homogenous sequences.

That's what they are here. Array are heterogenous in JS, and tuples are too. And since they're immutable, their size is fixed.

Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @04:14PM (#29544729)
Technically. I guess what I’m getting at is these are separate use cases that happen to be served by the same data structure in some languages, and “tuple” to me refers to the much less important/powerful use case, which is why I didn’t realize what the term referred to when I first heard about this proposal.

For instance: Rust has tuples that are fixed-length heterogenous sequences, but you can’t actually work with them as sequences in any meaningful way; you can’t map or loop or filter over them. The term “tuple”, to my mind, refers to that “multivalue” or “unlabeled-struct” kind of use case. The fact that we use arrays for that in JS always seemed to me like a historical accident/convenience.

Re:Deno Joins TC39 by dten on Monday December 13, 2021 @11:43AM (#29541237)
Record and Tuple are actively being worked on: https://github.com/tc39/proposal-record-tuple -- currently Stage 2.
Re:Deno Joins TC39 by adamddev1 on Monday December 13, 2021 @10:51AM (#29540658)
Or how about TCO (tail-call optimization)? Please pretty please!
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @11:01AM (#29540752)
TCO is something that specific JS engines need to implement. It is implemented in JSC (Safari), but not in V8 or SpiderMonkey. Also see https://v8.dev/blog/modern-javascript#proper-tail-calls.

As this is an engine feature rather than a spec thing, there is nothing me (or any other TC39 delegate) can do.

Re:Deno Joins TC39 by adamddev1 on Monday December 13, 2021 @11:27AM (#29541059)
Oh yes, I see, that's true. Thanks for the explanation.
Re:Deno Joins TC39 by hajile on Monday December 13, 2021 @11:37AM (#29541179)
Proper tail calls are ALREADY part of the spec.

Google and Mozilla simply chose to ignore the spec.

Re:Deno Joins TC39 by Scarbutt on Monday December 13, 2021 @12:21PM (#29541753)
More like Google, Mozilla just waits to see if Google is going to implement it since they can't think for themselves.
Re:Deno Joins TC39 by adamddev1 on Tuesday December 14, 2021 @01:49AM (#29548955)
It would be so nice to have it though! It could do a lot popularize recursive problem-solving and function writing, without having to go into modifying these functions to make them stack-safe.
Re:Deno Joins TC39 by mschuetz on Monday December 13, 2021 @07:40AM (#29539021)
What are your thoughts on the do expressions proposal? Cause I think they'd be awesome for cleaner scoping of temporary variables.
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @07:55AM (#29539113)
I think they are great! Especially in combination with pattern matching (https://github.com/tc39/proposal-pattern-matching), or when using JSX.
Re:Deno Joins TC39 by nicoburns on Monday December 13, 2021 @08:57AM (#29539594)
Do you have any insight into how the TC39 process works, and how one might drive this work forwards? I feel like expression-orientation is the main thing missing from JavaScript at this point, and I'd love to contribute. But it's not at all clear to me how to actually do so.
Re:Deno Joins TC39 by spmurrayzzz on Monday December 13, 2021 @09:15AM (#29539729)
The TC39 process is well-documented, you can check out the stages and guidance for providing input here: https://tc39.es/process-document/

The do expression proposal is currently stage 1, so its very early. You can check out the issue tracker there to see some of the related discussion. Standards work can be deceptively hard, even for simple things. I think the do expression proposal is a good example of that.

Edit: forgot to link to the issue tracker I referenced above https://github.com/tc39/proposal-do-expressions/issues

Re:Deno Joins TC39 by benmccann on Monday December 13, 2021 @01:00PM (#29542235)
Do you have a link to the proposal?
Re:Deno Joins TC39 by mschuetz on Monday December 13, 2021 @01:03PM (#29542289)
https://github.com/tc39/proposal-do-expressions

Allows you to contain temporary variables to where they are needed, rather than having them remain active through the remainder of the current scope. You could do that with immediately invoked function expressions, but they are too verbose to be really viable for this. You could also use extra functions, but extra functions don't always make sense. Currently I'm frequently doing this:

Without do expression:

    let result;
    {
        let tmp = 123;

        result = tmp * 2;
    }

With do expression it would become this:

    let result = do {
        let tmp = 123;
     
        tmp * 2;
    }
Re:Deno Joins TC39 by SiVal on Monday December 13, 2021 @07:29AM (#29538966)
Will there be a Deno equivalent of Electron?
Re:Deno Joins TC39 by AaronO on Monday December 13, 2021 @07:48AM (#29539065)
Aaron@Deno here, we've been exploring something with the Tauri team but don't have a concrete release on the roadmap since we're focusing on other priorities.

I believe an Electron alternative is an important part of the Deno stack, so hopefully we'll ship a first iteration next year.

Re:Deno Joins TC39 by SiVal on Tuesday December 14, 2021 @07:48PM (#29560459)
Thanks, Aaron. I think people who have been using Node for years are skilled at the old Node ways and have huge inertia in their skills, their own code, and others' Node code. For them, the ideal platform would be Node plus some upgrades. I'm guessing they would rather extend their inertial frame of reference than leave it behind.

Then there are others of us who have been saying no to Node and legacy JS for years. We have no such legacy to maintain and no intention of ever creating any. But some of us (at least I) would reconsider platforms built from scratch on a new TypeScript foundation rather than layered on a pre-ES6 foundation. That would include a Deno-based Electron. You might have more luck converting people who don't use Node than getting Node users to abandon their legacy.

The state of cross-platform desktop apps is terrible. All attention is on mobile, and desktop OS makers have almost zero interest in supporting cross-platform desktop apps. (MS cares a little more than zero, Apple less than zero and barely tolerates their own Mac-only developers.) Only something browser/Chromium based seems realistic for the next few years.

On the server, there are a lot of alternatives to Node that are considered better by (and very popular with) large segments of the market. Deno will be one of them, I think. But for cross-platform desktop apps, Electron would be rejected completely if the alternatives weren't so bad and unlikely to get better. A better Electron, despite its inherent problems, could end up more popular than server-side Deno. Just a thought.

Re:Deno Joins TC39 by mattlondon on Monday December 13, 2021 @08:51AM (#29539544)
Glad to hear this is still on the table! I have been very keenly watching this space waiting for this to land here :)
Re:Deno Joins TC39 by spankalee on Monday December 13, 2021 @12:01PM (#29541473)
Why not PWAs?
Re:Deno Joins TC39 by jerrygoyal on Monday December 13, 2021 @08:11AM (#29539229)
As modern JS is getting closer to typescript in terms of new methods, latest syntax etc. What is the future of TS? will it be there for just type checking?
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @08:12AM (#29539236)
Yes.
Re:Deno Joins TC39 by egeozcan on Monday December 13, 2021 @09:10AM (#29539686)
could you imagine that some JS proposal adds the ability to ignore TS-like type annotations to the engines, so we don't even have to strip them?

this may help development heavily, also making the browser and deno nearly identical environments.

Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @09:26AM (#29539831)
Yes, this would be great, and it will probably happen eventually. This is something we want to work on soon - expect something in the coming weeks.
Re:Deno Joins TC39 by ducaale on Monday December 13, 2021 @11:22AM (#29540987)
Since TS/Deno has native support for JSX syntax, do you think Browsers will eventually support it as well?
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @12:06PM (#29541549)
No, I don't think so. JSX is too proprietary and not specified well enough. It is also rather ambiguous.

If you want a "no compile" JSX:

```jsx

const x = <div color="red">hello</div>;

// is the same as

const x = h("div", { color: "red" }, "hello");

```

Re:Deno Joins TC39 by eyelidlessness on Monday December 13, 2021 @12:48PM (#29542102)
This is more true as a mental model/to the type system, but slightly more complicated when compiled.

First, there’s the “new JSX transform”, which involves auto-imports, has a different function signature, and defines fallback behavior for certain circumstances.

Second, JSX is only specified as a syntax extension. Some implementations—like SolidJS and its underlying dom-expressions compiler—don’t compile to hyperscript at all.

Re:Deno Joins TC39 by brundolf on Monday December 13, 2021 @01:27PM (#29542616)
It’s always been there just for type checking, hasn’t it?
Re:Deno Joins TC39 by speedgoose on Monday December 13, 2021 @11:15AM (#29540924)
Do you have discussions about not adding too many features to JavaScript? It's already quite complex for beginners.
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @12:07PM (#29541566)
This is always a consideration when adding new features. It is however also important to keep the language up to date with other modern languages. If you don't innovate, you die. There is always a cost/benefit calculation to be made.
Re:Deno Joins TC39 by phist_mcgee on Monday December 13, 2021 @07:26AM (#29538949)
Hey luca,

Huge fan of the achievements that Deno has made in recent years. Several questions:

How do you aim to promote Deno as a viable alternative to node, considering it's significant network effect and legacy?

Do you believe that Deno's 'more sane' defaults for security will appeal to developers in the long term? Do you think that the front end community will be receptive to these defaults?

Choosing TS as your language de jure, do you think that you will alienate any dyed in the wool JS devs? Can we expect that TS is now effectively the superset of JS going forwards?

Do you believe Deno's lack of support for NPM style package management will result in cleaning up the frontend community's over reliance on 'leftpad' style packages? Do you think that Deno's approach to dependencies fosters a more considered approach to transitive dependency bloat?

Again, huge fan of Deno, and happy to hear about this announcement.

Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @07:49AM (#29539072)
> How do you aim to promote Deno as a viable alternative to node, considering it's significant network effect and legacy?

This is a great question, but not one I can answer in a small HN comment :-). I may write a blog post about it one day. The core of the argument is that Deno can save you an insane amount of time / discussion (OOTB linting, formatting, testing, standard library, etc). It aims to unify the ecosystem into a single style, like in Go.

> Do you believe that Deno's 'more sane' defaults for security will appeal to developers in the long term? Do you think that the front end community will be receptive to these defaults?

I think many developers do not care about permissions, and also will not in the future. This is a problem, but not something that can be tackled overnight. Security is often not emphasized enough in our industry unfortunately. Because of this I think sane defaults and opt ins are good - they push people to think about security at the most basic level. Maybe the log4shell attack also shows people that it is a good idea to sandbox server side scripts aggressively (something we have been pushing for), to prevent large scale system takeovers through a single vulnerable entrypoint.

> Choosing TS as your language de jure, do you think that you will alienate any dyed in the wool JS devs? Can we expect that TS is now effectively the superset of JS going forwards?

There is work being done on this. I don't have too much to share right now, but expect some updates on this early next year. JS has to evolve to support some form of type annotations first class to stay relevant.

> Do you believe Deno's lack of support for NPM style package management will result in cleaning up the frontend community's over reliance on 'leftpad' style packages? Do you think that Deno's approach to dependencies fosters a more considered approach to transitive dependency bloat?

Maybe, maybe not. I think it is still to early to tell. I do think that so far it is looking like it. People seem to be doing less weird stuff like "leftpad" with Deno so far. Ideally all these little helper modules should just be part of JS directly (hit me up with suggestions!)

> Again, huge fan of Deno, and happy to hear about this announcement.

Thanks, glad you like it :-)

Re:Deno Joins TC39 by Vinnl on Monday December 13, 2021 @07:55AM (#29539110)
> JS has to evolve to support some form of type annotations first class to stay relevant.

What are you thinking in this regard? Just to define type annotations that can be made but will not necessarily be type-checked at runtime? To have them serve as inputs to the interpreter for optimisations? Or even breaking at runtime if types don't match their annotations?

Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @08:00AM (#29539153)
I don't want to go into details right now. Expect more in a couple of weeks :-)
Re:Deno Joins TC39 by deepstack on Monday December 13, 2021 @07:47AM (#29539057)
Personally front end developers need to step up their games learn how to develop or else don't think they have business developing software front-end or back-end. This whole idea of bring in as much developers as possible at cost of developer competency has being harmful for developer and tech community.
Re:Deno Joins TC39 by asoneth on Monday December 13, 2021 @09:09AM (#29539682)
In my opinion, what has been most harmful for evolution of the software engineering profession is the tendency to blame individual developers for not being infallible instead of fixing chronic failures in tooling, processes, and funding.

The medical profession, aviation, even rail transportation [1] have all progressed past the point where avoidable failures are entirely the responsibility of the individual.

Of course, there was resistance in those fields as well because some considered themselves an "above-average" doctor or pilot who didn't need safeguards, checklists, union rules, or laws. But it empirically improved outcomes.

[1] https://www.youtube.com/watch?v=A3AdN7U24iU

Re:Deno Joins TC39 by andrewflnr on Monday December 13, 2021 @10:24AM (#29540356)
While I agree in this case: at the edges, there still exist people who just should not be allowed to be doctors or engineers. The main difference with software is that the stakes tend to be drastically lower...
Re:Deno Joins TC39 by asoneth on Monday December 13, 2021 @11:46AM (#29541280)
The stakes could be drastically lower or drastically higher depending on what the software is used for.

For example, we might want to make sure software used in avionics, aerospace, weapons systems, voting machines, medical devices, cryptography, power plants, policing, finance, etc is carefully engineered. But I agree with your main point that there's still a baseline of competence necessary -- we need both good tooling and good people.

That reminds me of a lament from a friend at the Software Engineering Institute that the profession missed the boat on the kind of licensure most engineering disciplines have. (That is, any software developer can refer to themselves as an "engineer" without taking any tests, accepting any liability, or meeting any other legal requirements.)

Re:Deno Joins TC39 by robertvh on Monday December 13, 2021 @07:06AM (#29538822)
Congrats! Can you extend on your ideas for async iteration?
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @07:12AM (#29538863)
Mainly pushing proposals like https://github.com/tc39/proposal-iterator-helpers that make it easier to work with (async) iterators.
Re:Deno Joins TC39 by bartq on Monday December 13, 2021 @11:08AM (#29540834)
When cross platform windowed WebGPU on Deno? It would be interesting for many kinds of apps.
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @12:08PM (#29541583)
We are not sure about windowed WebGPU right now. We will try to come up with some form of "Deno Desktop" next year, but I have no real ETA for that.
Re:Deno Joins TC39 by Vinnl on Monday December 13, 2021 @07:42AM (#29539024)
Hey Luca! What does

> Better support for explicit resource management

refer to?

Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @07:59AM (#29539143)
Things like https://github.com/tc39/proposal-explicit-resource-managemen.... Essentially better language level support for objects which represent some IO resource that should be reliably closed when a user is done with it. Something like the `defer` statement in Go is really missing from JS.
Re:Deno Joins TC39 by baybal2 on Monday December 13, 2021 @08:27AM (#29539371)
What you think of more *-Scripts built on top of JS keeping coming? Are you not afraid of TypeScript following the CoffeScript into obscurity because of WebDev community keeping chasing the new thing?

This is all when vanilla JS keeping very energetically absorbing new features from *-Scripts thanks to TC39 seemingly intentionally picking them?

Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @08:34AM (#29539427)
No, I think this will eventually stop. JavaScript is getting more mature. I would not be surprised if the TypeScript syntax will be legacy in a few years, because JS caught up.
Re:Deno Joins TC39 by megaman821 on Monday December 13, 2021 @08:54AM (#29539560)
Is there some proposal for making the type syntax valid? No type checking just JavaScript parsing code with types and ignoring it.
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @09:27AM (#29539843)
No such proposal exists right now, but this will be a point of immediate focus for me.
Re:Deno Joins TC39 by pier25 on Monday December 13, 2021 @11:50AM (#29541313)
How will Deno react if that happens?
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @12:00PM (#29541443)
Deno will behave just like Chrome or Firefox would: we ignore the checks when running your code. We would have a `deno check` subcommand to perform a typecheck. You could optionally run this automatically before a `deno run` by passing a `--check` flag.
Re:Deno Joins TC39 by j-krieger on Monday December 13, 2021 @07:24AM (#29538944)
Congrats on your new role! Currently, I feel like addition to JavaScript is a lot slower than new CSS features, for example. What do you think are the chances that JS will one day get a larger batch of STL functions, instead of about a dozen each year?
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @07:39AM (#29539011)
I hope the pace will accelerate. The real questions is what functions we need though. Some candidates that I would love to see are better helper functions on iterators, and Uint8Array<->base64/hex. Most of the "standard library" in most languages is related to IO, and for JS is dependant on the host (the web, Deno, Node) so not something TC39 will touch directly. Do you have ideas for standard library functions that you think are missing?
Re:Deno Joins TC39 by FragenAntworten on Monday December 13, 2021 @08:57AM (#29539590)
'enumerate', as in Python.

'clamp' and 'sortBy', as in Lodash.

Set methods for union, intersection, difference, etc.

Re:Deno Joins TC39 by tempodox on Monday December 13, 2021 @11:12AM (#29540895)
Re set operators: For completeness' sake there would have to be a way to specify how set elements are to be tested for equality.
Re:Deno Joins TC39 by amitport on Monday December 13, 2021 @07:42AM (#29539030)
'range' a-la python
Re:Deno Joins TC39 by wruza on Monday December 13, 2021 @05:27PM (#29545492)
Range a-la python is a generator and is pretty straightforward in js as is. There is no need for a complicated solution and/or as part of stdlib, imo:

  function* range(x, y) {
    while (x <= y) {yield x++}
    // or ‘<‘ if you want half-open one
  }

  for (let n of range(3, 5)){
    console.log(n)
  }

  array = [...range(3, 5)]
  console.log(array)
Re:Deno Joins TC39 by amitport on Tuesday December 14, 2021 @04:00AM (#29549684)
It's also straight forward to implement in python. It is common enough to be standard so people won't reinvent the wheel. And it should be available to people learning the language before they learn generators.

Array.prototype.indexOf is also pretty simple as are many core functions.

Re:Deno Joins TC39 by wiredearp on Monday December 13, 2021 @09:27AM (#29539837)
Immutable data structures are on the agenda over in https://github.com/tc39/proposal-record-tuple and I would vote for that in Deno while I have the chance.
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @12:26PM (#29541817)
Yup, we'll ship them once they go Stage 3/4 (when Chrome ships them in stable).
Re:Deno Joins TC39 by Zababa on Monday December 13, 2021 @08:55AM (#29539570)
I often miss map, reduce and filter on iterators, though this is already a stage 2 proposal: https://github.com/tc39/proposal-iterator-helpers.
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @12:10PM (#29541605)
This is definitely something I am interested in pushing too. Iterators have not gotten the love they deserve.
Re:Deno Joins TC39 by Zababa on Monday December 13, 2021 @12:12PM (#29541637)
That's great to hear! Congratulations and thank you for your work.
Re:Deno Joins TC39 by tarjei_huse on Monday December 13, 2021 @09:25AM (#29539818)
I miss being able to create a hash from an array in a quick way. You always end up with

let bar = [{id: zz, }, {id: y},...]

let foo = {}

bar.forEach(v => foo[v.id] = v)

I'd love to have something like:

let foo = bar.toMap(v => [v.id, v])

Re:Deno Joins TC39 by keville on Monday December 13, 2021 @10:05AM (#29540193)
const foo = bar.reduce((hash, item) => { hash[item.id] = item; return hash; }, {});
Re:Deno Joins TC39 by wiredearp on Monday December 13, 2021 @09:30AM (#29539879)
new Map([[k1,v1], [k2, v2]]) can do that. Or Object.fromEntries with the same argument.
Re:Deno Joins TC39 by tarjei_huse on Monday December 13, 2021 @09:42AM (#29539980)
Thanks!

You still need to create the middle datastructure ( [[k1,v1], [k2, v2]] ) but it is an improvement :)

Re:Deno Joins TC39 by wiredearp on Monday December 13, 2021 @10:03AM (#29540179)
Ah yes, true, you always need to map the things ID to the thing itself, so that middle data structure is actually quite annoying :)
Re:Deno Joins TC39 by runarberg on Monday December 13, 2021 @11:23AM (#29541005)

    let foo = Object.fromEntries(bar.map((v) => [v.id, v]));
Re:Deno Joins TC39 by keville on Monday December 13, 2021 @05:15PM (#29545387)
It is not necessary to create any extraneous data structures to do OP's one-liner. This creates n+1 new arrays that must be garbage-collected.
Re:Deno Joins TC39 by runarberg on Monday December 13, 2021 @06:09PM (#29545934)
Object.fromEntries takes iterable, so if you have a map from a handy iterator library you could get rid of the parent array returned from `bar.map`.

    import { map } from "my-iter-lib";
    
    Object.fromEntries(map((v) => [v.id, v], bar));
Or with the proposed iterator-helpers:

    Object.fromEntries(
      Iterator.from(bar).map((v) => [v.id, v]),
    )
However the inner arrays are harder to get rid of... In fact even OP’s oneliner defines the inner arrays. I would hope there were some engine optimizations though which could minimize their footprint.
Re:Deno Joins TC39 by keville on Monday December 13, 2021 @09:06PM (#29547318)
Please see my other comment in this thread for the `reduce`-based solution that requires no extra data structures. They're not that hard to get rid of!
Re:Deno Joins TC39 by amitport on Monday December 13, 2021 @07:47AM (#29539058)
'zip' a-la python
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @07:52AM (#29539095)
I have often needed this too. Noted.
Re:Deno Joins TC39 by amitport on Monday December 13, 2021 @07:47AM (#29539055)
'reversed' a-la python
Re:Deno Joins TC39 by lucacasonato on Monday December 13, 2021 @07:51AM (#29539088)
Currently in stage 2 as `Array.prototype.toReversed`: https://github.com/tc39/proposal-change-array-by-copy
Re:Deno Joins TC39 by amitport on Monday December 13, 2021 @07:56AM (#29539119)
Nice, I didn't know about that, but in any case note that IMO it should be part of the Iterable protocol. Also note that the proposal above creates a copy on reverse AFAIKT.
Re:Deno Joins TC39 by aadams on Monday December 13, 2021 @09:56AM (#29540108)
Please have someone on your team take a good hard look at the current proposal-pipeline-operator: https://github.com/tc39/proposal-pipeline-operator

It started as a Function Composition proposal (using the pipe operator |>) but after a change of leadership it has turned into something much different. We might need another perspective on the current trajectory of this proposal, as in its current form it seems to many in the community it might take JS in the wrong direction.

Thanks!

Re:Deno Joins TC39 by wruza on Monday December 13, 2021 @06:01PM (#29545855)
If you want a feedback, I do not find |> versions much (if at all) easier to read. The noise is as high as in a regular function-based chaining:

  await chain(
    Object.keys(envars)
      .map(envar => `${envar}=${envars[envar]}`)
      .join(' '),
    text => `$ ${text}`,
    text => chalk.dim(text, 'node', args.join(' ')),
    colored => console.log(colored),
  )
I don’t want to sound too negative, but this seems like a pointless extension only to bring the burden of support for some syntactic flavor.

React example is special though. It feels like very helpful in expr-only context, but in-array ifs and fors would do better there:

  <ul>
    {[
      for (v of vs) {
        const text = foo(v)
        yield <li>{text}</li>
      },
      if (vs.length == 0) {
        yield <li>No items</li>
      },
    ]}