WoofJS icon indicating copy to clipboard operation
WoofJS copied to clipboard

range's output should include its second argument

Open hallpell opened this issue 5 years ago • 3 comments

Currently, range() follows the conventions of other languages, where range(0,5) returns [0,1,2,3,4]. This makes sense mainly because range(0,array.length) is such a common use case of range in other languages.

However, we don't do very much indexing of arrays in Woof (pretty sure it never shows up in documentation), which makes me less certain that we need to follow this standard for range(). I think it makes more sense to say range(1,5) will count from 1 to 5, and thus return [1,2,3,4,5].

I'm unsure if we actually want this change due to backwards compatibility concerns (it will make most uses of range() in existing projects have one more thing inside them, which will break some things), but is worth considering.

The actual code to change this is trivially easy, making < into <= on 1805 and doing the same for the decreasing for loop at 1811

hallpell avatar May 21 '20 16:05 hallpell

I like the idea of a more intuitive range function.

In terms of backwards compatibility, we've never broken it but I've always thought that if we wanted to, we could save the version of woof (commit hash) with the project (probably when it's created) so we can make breaking changes that won't affect older projects because they will run with the version of woof they were created with.

We'll also have to make sure to show the right version of the documentation as well.

stevekrouse avatar May 25 '20 17:05 stevekrouse

I like the idea of a more intuitive function, but I do not like the idea of students learning range() in a way which is wrong once they move on from WoofJS to another programming language. Sounds like a formula for confusion and off by one errors!

Why not just leave range() the way it is now ( range(0, 5) results in [0, 1, 2, 3, 4] ) and make a different function that does the more intuitive behavior? Perhaps we can call this new function sequence() unless anyone has a better name?

That solves the issue of backwards compatibility because range() is left unchanged, but sequence() is more intuitive to use. And students who do use range() won't leave WoofJS and be confused by range() in other languages.

On Mon, May 25, 2020 at 1:46 PM Steve Krouse [email protected] wrote:

I like the idea of a more intuitive range function.

In terms of backwards compatibility, we've never broken it but I've always thought that if we wanted to, we could save the version of woof (commit hash) with the project (probably when it's created) so we can make breaking changes that won't affect older projects because they will run with the version of woof they were created with.

We'll also have to make sure to show the right version of the documentation as well.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stevekrouse/WoofJS/issues/582#issuecomment-633666118, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACA2A2LSH4AWRCVVXBLCHWTRTKVITANCNFSM4NG6UU6A .

wendybujalski avatar May 25 '20 18:05 wendybujalski

Good compromise!

stevekrouse avatar May 25 '20 18:05 stevekrouse