Giter VIP home page Giter VIP logo

Comments (6)

shiffman avatar shiffman commented on August 16, 2024

thanks for these comments, this is very helpful

from learningprocessing.

shiffman avatar shiffman commented on August 16, 2024

Ok, I am finally getting around to these fixes. I like the idea of a sidebar but managed to squeeze the chapter 8 section into one paragraph which now reads:

In #functions, we showed how when a primitive value (integer, float, etc.) is passed in a function, a copy is made (known as pass by value. With objects, this is not the case, and the result is a bit more intuitive. If changes are made to an object after it is passed into a function, those changes will affect that object used anywhere else throughout the sketch. In Java, this is strangely still an example of pass by value, the difference is that a copy of a reference to the object is passed rather than a copy of the object itself. You can think of a reference as the address in memory where the object's data is stored. So while that address is copied there is still only one object and so any changes to that object affect both variables.

@ybakos would love any thoughts on the above if you have a minute! Closing this issue for now.

from learningprocessing.

ybakos avatar ybakos commented on August 16, 2024

"With objects, this is not the case..."

I would change that to say something besides "this is not the case," because the following sentences contradict that. (Reader: Uh... so is it the case or is it not the case?)

Maybe just something like:

In #functions, we showed how when a primitive value (integer, float, etc.) is passed to a function, a copy of the value is made (known as pass by value_)_. With objects, this process is less intuitive.

from learningprocessing.

shiffman avatar shiffman commented on August 16, 2024

Ok, rewritten again now:

In #functions, we showed how when a primitive value (integer, float, etc.) is passed in a function, a copy of the variable is made and the original variable remains the same no matter what happens in the function. This is known as pass by value. With objects, things work a bit differently. If changes are made to an object after it is passed into a function, those changes will affect the original object. Instead of copying the object and passing it into the function, a copy of a reference to the object is passed rather. You can think of a reference as the address in memory where the object's data is stored. So while there are in fact two distinct variables holding on their own value, that value is simply an address pointing to only one object. And so any changes to that object affect both variables.

I am also going to add a diagram which I think will help make it more clear.

from learningprocessing.

ybakos avatar ybakos commented on August 16, 2024

That's pretty good! Two minor quibbles:

  • first sentence: passed into a function (same as in the remainder of the paragraph)
  • delete "rather"

from learningprocessing.

shiffman avatar shiffman commented on August 16, 2024

Thanks, changed!

from learningprocessing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.