2 ms·
Ask HN: What are your thoughts about primitive obsession in JavaScript?
People talk a lot about primitive obsession in other languages but I don't see anyone talking about it in JavaScript.
Basically, we have literals (Array/String/Object) that don't actually have any meaning to the domain. We have built-in methods like `.filter`, `.map`, etc. in those primitives and we see people often using it just for mutate data through functions instead of just building "mapeable" or "filterable" functions/objects.
What are your thoughts about this? Is primitive obsession a thing in JavaScript? Should we care about it? Do you have any link to similar discussions happening elsewhere?
- angersock 10y agoI'm unfamiliar with whatever recent chatter on "primitive obsession" there's been, but it's not a new idea ( http://www.jamesshore.com/Blog/PrimitiveObsession.html http://www.jamesshore.com/Blog/PrimitiveObsession.html ) and has been discussed elsewhere ( http://wiki.c2.com/?PrimitiveObsession http://wiki.c2.com/?PrimitiveObsession ). Frankly, while I do see the point about fixing it with value objects and whatnot, I rather think that is a sign of wannabe architect/PL wankery. Javascript has a basically useless type system in practice (especially with legacy code) and has a lot of really handy/flexible features that would only interact badly with attempts to fix this "primitive obsession" stuff. I don't think it matters in the JS ecosystem.