-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
replace const with let in reference examples #3877
Comments
I kinda feel the opposite. JS, even after ES6, is still very quirky and as you mentioned For immutable objects, it would be better to |
That is interesting. I guess I take Either way I think some consistency should be added, both in the source and the examples. |
My justification for using The same mentality is how lebab applies its transformation. If the variable is never reassigned, it will be marked as Nonetheless, I couldn't agree more that we need to have a consistent methodology for using
However, I'm not sure if this will be informative or confusing for the example codes and newcomers. |
Cool that all makes sense @hsab. I especially like this way of describing its use
So I guess then the to-do would be to use As for examples, I think we should follow the same use as in the source. The distinction between when to use Also to touch on an earlier note, I would say that yes, objects that are truly immutable should use |
For me this is a rather tricky thing to balance, on the one hand there's the "use |
For the codebase, I favor the approach @limzykenneth mentioned "use |
It seems like the consensus is in favor of using So perhaps this discussion should be more focused on the usage pertaining to examples? For the ones that switched to ES6 in Yet, I agree with @stalgiag in that
|
Ok it sounds like we're pretty agreed on keeping things as is for the codebase. Regarding the examples, I wonder if we should deploy as is for now and listen for feedback. I'd be curious to hear if there are any other opinions from people teaching with ES6 @brysonian @saberkhaniscool @shiffman |
I teach similar to what @limzykenneth said, that In my experience the clarity of " |
Is it possible to teach the concept of assignment/reassignment at the very beginner stage instead of making it seems like constants? This is what I'm personally unsure of since I've never tried teaching this concept from the beginning especially regarding how to introduce this concept of assignment/mutability/value & reference/etc. without overwelming art students (in my context) with a bunch of computer science concepts. I do like trying |
For my own coding these days as well as contexts like intermediate JavaScript courses like those that involve node.js and other JS libraries I use exactly this principle:
However, for contexts where I am with younger (K-12) audiences or total beginners, I only use I don't know the right answer here at all and I recognize there are important concepts and reasons for having |
@limzykenneth I'm always teaching in an arts context, normally college and grad level and teach both I honestly haven't had students express confusion over const and let. (and they do tend to express it in general so i hope they would bring it up). Using |
I was still using
|
I agree and feel that exclusively using It seems to me that in order to make sense of the distinction between changing the value and reassigning, one must have an understanding of how different types relate to memory. My earlier point about teaching the correct way from the beginning is a nice aspiration but in this case it may undermine the goal to make this accessible for all stages of experience. |
This makes sense to me. We use |
Hi. Experienced developer, first-time open source contributor here. I can take this task. |
sounds good @LisaMabley! let us know if you have any questions! welcome! 🎊 |
Ok, a little confused already. Are we talking about these reference examples -- which are in a different repo? https://p5js.org/examples/ |
Or everywhere it says |
I'm assuming the above is what needs to be changed, and that (given the conversation above) I should also replace |
hi @LisaMabley! yes we are talking about everywhere it says and yes i would say changing all |
Might this prompt a look at aiming to have different "levels" of examples/tutorials? API : showcase different variables for each function Beginners : more of an eye of teaching basics/MVP of JS and basic P5 functionality Intermediate : maybe more elaborate/advanced P5 functionality and use in larger things (classes, flocking might be a good example) Advanced : more of a focus on performance and P5 interacting with other libraries/hardware (buffers, data structures, other libs, machine learning, shaders) Key would be that within each "level" that variable declaration, data structures (1D arrays vs. 2D arrays vs classes vs etc.) would be common (as much as is possible). |
I changed all the consts and vars I found in the @example blocks to let and updated my outstanding PR. So I'll consider this done until feedback comes my way. |
- Update inline examples to start audio context on a user gesture, either by playing a sound (soundFile.play() / oscillator.start()) or by explicitly calling userStartAudio() #388 - Use let in examples, instead of var, but not const, as discussed in this issue where it was decided to use let exclusively in examples: processing/p5.js#3877 - Update styles for consistency with other p5 inline examples Some examples use soundFile.play() or oscillator.start() rather than a potentially redundant call to userStartAudio(). It might be worth that redundant call, because the difference between methods that call "start" on a WebAudio node (thus enabling audio on a user gesture) and those that do not is pretty obfuscated...
I know this thread is many many years old, hopefully a comment notification is not disturbing anyone here! I just wanted to pop in and mention that I am working on a p5.js version of The Nature of Code book and am planning to use nature-of-code/noc-book-2#140 (comment) Any feedback or thoughts there would be welcome! |
Hi all, this is in no way urgent but just wanted to open an issue to discuss the usage of
const
for mutable assign-by-reference variables.This can be seen in a number of places, here for example or here. This isn't always the case as seen here.
This is technically okay since the immutable part of an assign-by-reference variable is the reference and the data is able to change. A clear explanation is available here.
Though it is technically okay, I personally feel that it is little more clear to only use
const
for declaring variables that will not be modified within the scope of that variable. If the data connected to a variable will be changed through use of that variable then it should be declared withlet
.The text was updated successfully, but these errors were encountered: