GithubHelp home page GithubHelp logo

Comments (6)

crudh avatar crudh commented on July 20, 2024

I think the biggest drawback is that you have to do push differently for normal and immutable arrays, and there isn't anything telling you that you are doing it wrong if you push on an immutable array and don't take care of the result.

It can be especially confusing if you have a code base where you use both regular arrays and immutable arrays.

from seamless-immutable.

ivan-kleshnin avatar ivan-kleshnin commented on July 20, 2024

I think that's pretty easy to differ visually:

robots.push(robot); // mutable push
...
let count = robots.push(robot) // mutable push
...
robots = robots.push(robot); // immutable push
...
let robots2 = robots.push(robot); // immutable push 

It's a good tone today to use concat instead of push. So when you see push you're going to be especially attentive in any case. That's from code-reading point of view. From code-development point of view... you need to know where you data is mutable and where is immutable to not get immutable exceptions right?

push behaves differently just in the same manner as x[0] = 1 behaves differently (throws warnings or do mutation). If second is not confusing for you, first also shouldn't.

I'm not saying your arguments are meaningless. They are good.
I'm saying that from my personal opinion benefits are greater than drawbacks.

from seamless-immutable.

crudh avatar crudh commented on July 20, 2024

Yeah, it is easy to differ visually. But if you are working with code that uses both mutable and immutable arrays and you do a push on an immutable array now you get an error and you are made aware of it during development.

With this change you might by mistake do a push on an immutable array and forget to handle the result and get no warning about it. It might then lead to bugs that can be tricky to locate the source of.

So you have a valid point, but I'm not personally convinced that the benefits are greater than the drawbacks. And if push should be changed in this way then maybe all other banned mutating methods should be changed in the same way too?

from seamless-immutable.

ivan-kleshnin avatar ivan-kleshnin commented on July 20, 2024

And if push should be changed in this way then maybe all other banned mutating methods should be changed in the same way too?

Maybe. I can recall only push being needed all the time but, yeah, banned. What else?
Maybe a bigger picture will guide the best decision here.

from seamless-immutable.

rtfeldman avatar rtfeldman commented on July 20, 2024

Yep, @crudh's explanation is exactly the reason behind banning the mutable methods. If there were a desire to add an alternative to concat for single elements, I'd call it something else, like append.

A separate question is whether a method like that is worth adding to the API. Is there a common use case where this would be a significant upgrade over concat? I have not encountered any yet, and I'm hesitant to expand the API without strong motivating use cases because that's how libraries get bloated. 😄

from seamless-immutable.

ivan-kleshnin avatar ivan-kleshnin commented on July 20, 2024

Well, I was pretty sure about this proposal being rejected so no disappointment here 😄
Thank you guys for discussion 👍 hope to give this lib a better try soon.

from seamless-immutable.

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.