Comments (6)
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.
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.
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.
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.
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.
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)
- Make `without` support removing item from an array HOT 4
- how to use splice like array HOT 1
- Internet Explorer tests are failing HOT 4
- Issue regarding null values HOT 5
- Why are IE tests failing? HOT 3
- How to apply splice with seamless-immutable? HOT 1
- Merge does not work with class instances
- __immutable_invariants_hold is enumerable on Edge HOT 1
- Garbage collector features? HOT 1
- Performance characteristics
- Any difference with deepCopy? HOT 1
- [types] Mixin not applied to nested objects HOT 1
- flatMap not working HOT 2
- Add documentation for merge mode
- Files not being replaced on a deep merge
- Fails on IE 11 HOT 1
- TypeError: Object(...) is not a function HOT 1
- Lodash Vulnerability Problem
- Is the project still maintained? HOT 2
- immutable object causes rapid memory growth HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from seamless-immutable.