Skip to content
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

"Days since 2000" Scratch block should have a Leopard util #171

Open
towerofnix opened this issue Mar 10, 2023 · 2 comments
Open

"Days since 2000" Scratch block should have a Leopard util #171

towerofnix opened this issue Mar 10, 2023 · 2 comments

Comments

@towerofnix
Copy link
Member

Right now sb-edit converts sensing_dayssince2000 into this:

(((new Date().getTime() - new Date(2000, 0, 1)) / 1000 / 60 + new Date().getTimezoneOffset()) / 60 / 24)

In principle, this seems sound: "days since 2000" is a slightly ridiculous block and exposing users to real-world JavaScript date manipulation is basically a good idea.

The issue is, Scratchers aren't trying to figure out Date Mathematics when they use this block — and Scratch has blocks for date math. ("current minute", "current second", etc.) By replacing a simple Scratch block with much more complexity in JavaScript, we're only introducing overhead.

There exist a number of other functions (most recently compare & friends, as well as scratchTan) which ensure compatibility with Scratch without bringing obtuse or overly-explicit syntax to generated projects. I think the behavior for "days since 2000" should be moved into one of these. Let's call it... this.daysSince2000()! 👻

@towerofnix
Copy link
Member Author

Just to make a case against such a function as this.daysSince(new Date(2000, 0, 1)): IMO if we add a generic function, we're 1) opening up to arbitrarily going further than Scratch [with the standard library], which isn't a design goal of Leopard, and 2) limiting incentive to learn how that function works yourself, as a user, and come up with an alternative which suits your case more specifically.

We don't expose Leopard's inner workings to users right now, but overall, I think if we want to more specifically introduce users to JavaScript programming concepts, there are a number of better ways than by replacing a very compact standard utility with a bunch of "magic words" users will likely just copy and paste, gloss over, or be flat-out overwhelmed by.

@towerofnix
Copy link
Member Author

If we want to simulate re-running a project deterministically [not generally but for the purpose of testing and catching behavior changes], we need to be able to mock this block anyway, which we basically can't do when directly accessing Date behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant