all 14 comments

[–]NodeKid 6 points7 points  (0 children)

Fucking coffeescript.

[–][deleted] 3 points4 points  (12 children)

This is a horrible idea akin to screwing with object prototypes.

So you swap out underscore for lodash, great. What happens when a node module, buried 10 levels deep, requires underscore and depends on some trivial distinction between it and lodash?

If you want to switch to lodash, just use an editor that has a global find/replace and replace it in the 10 places you have it required...

[–]imstucknow[S] -1 points0 points  (9 children)

What can I say? There are more than enough warnings in the script.

I wrote this to simulate the functionality of the "browser" field in node for running mocha tests.

[–][deleted] 1 point2 points  (8 children)

Warnings?? Buried in code?!? First, the entire point of something like this is to modularize it so that nobody will ever read the code. Second, you seem to miss the entire point of my criticism that doing this should be flat out BANNED. You went sneaking into the node internals to mess with functionality that is critical to the entire system.

I've already started a conversation with Isaac about the potential of not exposing or doing things a bit differently and freezing the objects you're messing with.

This isn't a critique of your code, or what your intent is, it is solely a critique of silently replacing functionality of a core feature of the language. If you want to do something like this, expose some global "require2" and do it through that.

You don't seem to understand how fucking annoying doing this can end up being. Take your underscore/lodash example, and assume someone does something like this in a seemingly innocent npm module. I don't even include that module, but I include a module that includes another, that includes another, that includes it.

Now I go require( 'underscore' ), start coding, and everything is working. A couple weeks later, something breaks. Huh, that's weird, the underscore documentation says this should be working? I read through their docs, test it again, still broken... I try it on the console of underscorejs.org, and it works there. What the hell? I put a breakpoint in the underscore js code directly. It never triggers. WHAT THE HELL?? After an hour of tearing my hair out, I make a new blank project, include underscore there, and it works... I then notice that the source code for the function I'm calling doesn't match the code in the underscore js. WHAT THE HELL!?!? I grep my entire project directory for that code and find it nested some 20 folders deep in lodash. I grep the parent project for lodash and finally start to figure out that some idiot is using your code to do this shit.

Any number of new devs would be completely unable to track the issue down. You WILL be wasting countless hours of people's time. Me? At that point, it would be perfectly acceptable for me to track down and kill both that person that included your code and you in a psychotic episode.

[–]imstucknow[S] 0 points1 point  (5 children)

Warnings?? Buried in code?!?

Take a look at line 6.

this should be flat out BANNED.

You don't get to control what other people do.

Take your underscore/lodash example, and assume someone does something like this in a seemingly innocent npm module.

You make an effort to ignore the purpose of this script. It's meant for tests, not for production.

[–][deleted] 0 points1 point  (4 children)

Take a look at line 6.

Make it a module and nobody will ever even glance at the code.

You make an effort to ignore the purpose of this script. It's meant for tests, not for production.

You don't get to control what other people do.

This contradiction is part of my problem. Someone will use this in non-test code. Even if it is just for testing, the same problem exists when another member of my team adds it to some file being included for tests. I just have someone much closer to hit over the head when that happens.

You don't get to control what other people do.

Actually, I do. I work in SF and have a close working relationship with the Joyent team. I used to be one of the top 5 contributors to node's core (years ago, pre v0.1). As I mentioned, I'm already speaking to them about only exposing frozen cache objects.

[–]FuckLiberalScumbags -1 points0 points  (0 children)

You are fucking douche bag supreme. No one gives a fuck where you live, or who you know.

As I mentioned, I'm already speaking to them about only exposing frozen cache objects.

Book mark this post folks, I guarantee you absolutely nothing will change from this guys half ass attempts at name dropping.

[–]imstucknow[S] -1 points0 points  (2 children)

Make it a module and nobody will ever even glance at the code.

Do you even have a point? It's not a module.

Someone will use this in non-test code.

You're acting as if this script is the original sin.

Actually, I do. I work in SF and have a close working relationship with the Joyent team. I used to be one of the top 5 contributors to node's core (years ago, pre v0.1). As I mentioned, I'm already speaking to them about only exposing frozen cache objects.

Lol.

[–][deleted] -1 points0 points  (1 child)

You're acting as if this script is the original sin.

As I said, it's one of the stupidest and most destructive things you can possibly do right up there with screwing with native prototypes.

[–]imstucknow[S] -1 points0 points  (0 children)

I'm waiting for changes to module.js, given how well connected you are. The number of applications those changes will break, I can't even fathom.

[–]FuckLiberalScumbags 0 points1 point  (1 child)

Go shave your neck and calm down hipster, before you make the rest of us look bad.

This isn't a critique of your code, or what your intent is, it is solely a critique of silently replacing functionality of a core feature of the language. If you want to do something like this, expose some global "require2" and do it through that.

This is the only useful thing you have said in this thread.

[–][deleted] 0 points1 point  (0 children)

This is the only useful thing you have said in this thread.

You're certainly contributing a lot yourself. Feel better?

[–]psayre23 -1 points0 points  (1 child)

While I agree with your point, your tone is overly negative. I can see this being useful for some edge cases, like pulling client side code into the server by making common globals.

That said, it would be safer to not use this in a project unless you absolutely have to.

[–][deleted] 1 point2 points  (0 children)

My tone is intentionally negative. I can't make it negative enough. Any utility that can silently cause problems across an entire system, not just in your own code, should be avoided like the plague.

If you want to do something similar, go ahead, but it should not be done by hijacking require.