-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Number.range(to) equals Number.range(0, to) #18
Comments
I think we should require both arguments. Being explicit seems strictly better to me. |
Python works like this, and its |
I also like |
As a child, I wanted to but was never able to. I just never had the patience. |
We have an issue that says |
It is generally impossible to design APIs such that no group of humans will ever end up being confused. The fact that Python has been using these semantics for many years without many people tripping over this shows that not all that many people will be confused, I think rather conclusively. |
Impossible yes, but we can at least try not to make it worse, right? |
One of the possible use case of that is you use the infinity sequence as a source of real numbers and you filter some out to generate another sequence of infinity numbers |
I do not think that copying the semantics of one of the most widely-used operations in one of the most widely-used languages, which causes very little evident confusion there, will make it perceptibly worse. |
That seems to assume that the sensibilities and intuition of Python users will overlap with that of JS users, which I don't think is necessarily true. |
I would say that python has done a great many things right and a great many things wrong (much like we have), and that arguing about which things go in which category is probably not a great way to make our decisions. If there are concrete usability concerns about requiring both arguments I would be more interested in discussing those instead. |
The up-to range is well established even before Python: https://leancrew.com/all-this/2019/09/making-lists-with-jot-and-seq/. |
I don't suspect that Pythonistas and JSers have a substantially different intuition, as a class, for whether a single-argument range counts to that number from 0 or from that number to infinity. ^_^ In particular, both languages have the same very common use-case of "enumerate all the indexes of a list of length N" which is done by "count to", whereas I've rarely encountered situations where I needed an infinitely-incrementing range. (Not never; I know of one spot in my code where I'm doing exactly that, but I'm using I'll say that I've used the Python range syntax without problem before, and my personal range() function in JS works this way as well. I also suspect that it's safer/better, given a reasonably even choice between creating a finite and infinite iterator, to choose the finite one, and require an author to be more explicit about wanting an infinite iterator. |
We could also just require them to be explicit about both. I really don't understand why we want to make guesses about what people are trying to do. |
I'm not trying to argue about whether Python's design is good or bad. I'm making a more specific argument: the usual reason to prefer being more verbose is to avoid confusing people, but the millions of Python users of the less verbose design who are not confused by it is very good evidence that it is not going to confuse many people. If there is some other reason to prefer to be more verbose, great, we should talk about that. I'm not saying Python's design is necessarily good. But I do think it means we can safely say that the less verbose design is not going to be unduly confusing. (Also, precedent from other languages has weight on its own, in proportion to how common those languages and the portions of them which we're duplicating are.) Edit to add:
We could further require them to be explicit about |
That multiple meanings for the single-arg form have been requested seems motivating enough to me. Even if we're talking about a minority of developers being confused, the majority isn't hurt by making their code more explicit too (In fact I'd argue they're helped).
Maybe. I always put the radix in for Number.parseInt, even when I'm parsing in base 10 |
I successfully did it by using induction. Anyway, I don't feel strongly about whatever we may come up with here, but I'm leaning towards @bakkot's position. |
I think trying to make arguments from a point of |
Another thought, if we choose |
If both are required they'll get an error. |
I would prefer this proposal rather than
|
Umm actually you have to write |
Personally I prefer explicitness. IMO saving And do we have precedents of overloading |
Aside: is there any issue or separate proposal that discusses the possibility of a range literal over a function? |
Yes, #20 but I'd like to avoid to add new Syntax for it |
Neither
This ensures integer ranges end before yielding duplicate values. In the case of small There is no obviously correct default value for the |
This proposal should not be motivated by array key iteration, the appropriate idiom is
|
Um, It does work in the BigInt version. IMO most use case of the infinity range won't really reach the |
Yeah nobody's actually iterating up to MAX_SAFE_INTEGER; using Infinity as a |
I propose that omitting both arguments default to |
But it still needs to be specified and something like iteration from |
I'd prefer explicit methods like |
If we go with that, maybe we need to rename it to |
I'll close this issue for now for housekeeping. On today's TC39 meeting, delegates are generally satisfied with the status quo API. It's still possible to add this shortcut in the future if there is a very strong need. |
I saw this raised as a question in the README, but couldn't find an issue about it.
Personally, I like the idea of supporting the Number.range(to) form. It's common in other languages and will be common in JS; I think it's quite unambiguous.
(Related discussion: #14)
The text was updated successfully, but these errors were encountered: