Hacker News new | ask | show | jobs
by galephico 3453 days ago
Sincere question: do you really have the feeling the over cost is worth it? Do you do this for EVERY external library you're using?
3 comments

It really depends on the library. Sometimes you look at the API of a library and you just want to wrap it because you know you're going to have to do a lot of work to get the data in and out of it in the right shape, or the lifecycle management is a pain, or the types involved aren't going to play well with tests, or it's just fundamentally relying on external state, thus preventing me writing proper unit tests of anything which might call it.

Other times, no, it doesn't seem worth it. And I don't do it for every single external library I use.

Although it does tend to end up being most of them - which seems to be a consequence of the way I've generally done n-tier application design at work. I'm not always a fan of this architecture, but sometimes it does fall out nicely.

Yeah, I don't get it. Swapping out a third party library is rare and usually because you want to get extra features another library doesn't have or some other big reason. Given how rare it is I would just use the library as is and refactor if/when the time comes. If you wrapped every library you'd waste a lot of time.

I had a senior developer suggest I wrap jQuery one time.

Honestly in JavaScript there's very little call for it because the language is so flexible, and you can't really build anything that's unmockable.

C# is a very, very different matter, and that's the perspective I was initially commenting from.

No, some libraries (like React-bootstrap) export a bunch of components that don't really need a facade. But be careful. Later, when you need to modify functionality (and it can't be done via modifying the bootstrap variables via Less) it's a slight pain to retrofit.
Even so, I like to keep the imports local so I only have to change one reference to a custom-wrapped version if/when the need arises. I have a lib file to act as a manifest of components, and while most are mine, there are also some "export {Grid} from 'react-bootstrap'" type things in there.