Giter VIP home page Giter VIP logo

Comments (9)

Niels-NTG avatar Niels-NTG commented on May 13, 2024

I can definitely see what you mean. During the porting proces in the past months I've made an effort to not only do a verbatim translation from Java to JavaScript, but also utilise the power of JS where it made improvements to both performance and readability. I've also removed or changed things that just don't make much sense in JavaScript or are remnants of old versions of Processing (for example: smooth(); is completely unnecessary since that's on by default since at least Processing 2). In JavaScript it's a lot easier to do OOP. Instead of having a dozen of arrays of the same length where the index has to be kept in sync, you can make an Array of objects that does the same thing with comparatively better performance, shorter overal size of the sketch and beter readability.

from code-package-p5.js.

Niels-NTG avatar Niels-NTG commented on May 13, 2024

So basically what I'm saying is that we should find a good middle ground.

from code-package-p5.js.

bohnacker avatar bohnacker commented on May 13, 2024

You're right, we should find a compromise. I'd opt for keeping the Circle object but replacing forEach(), circles.some()and circles.find()with simple for-loops. I know, it breaks the heart of a real javascript programmer, but from my experience even a simple for-loop is hard enough to understand for beginners.

from code-package-p5.js.

Niels-NTG avatar Niels-NTG commented on May 13, 2024

I completely agree. I will make the appropriate changes to P_2_2_5_01 and P_2_2_5_02 ASAP. Also will look into changing this the new sketches I designed.

from code-package-p5.js.

joeyklee avatar joeyklee commented on May 13, 2024

@bohnacker @Niels-NTG - do you think we should convert then all the forEach loops into for loops for the other sketches as well? I think I use forEach quite often...

from code-package-p5.js.

Niels-NTG avatar Niels-NTG commented on May 13, 2024

forEach is for iterating data, normal for loops are for iterating a range of numbers. I use forEach all the time whenever I write JavaScript. But this style where you pass functions isn't common in other mainstream programming languages, meaning that's not directly transferrable to another language. Also you have the complexity of scoping this, of which the working should not be in the scope of the book. To keep it simple for the reader, I'm in favour for picking a single style we use all throughout the book. And that's is probably a plain old for loop.

from code-package-p5.js.

bohnacker avatar bohnacker commented on May 13, 2024

I wouldn't mind if there are some forEachs remaining in the examples. It's especially ok for all _02, _03, ... sketches. We explain the _01 sketches in the book, so these should be quite readable and understandable for beginners.

from code-package-p5.js.

bohnacker avatar bohnacker commented on May 13, 2024

@Niels-NTG Did you already change something on this sketch? If not, I will just go on with that...

from code-package-p5.js.

Niels-NTG avatar Niels-NTG commented on May 13, 2024

@bohnacker I haven't had time for it yet. Go ahead.

from code-package-p5.js.

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.