Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove circular dependency from debugging code #1354

Merged
merged 2 commits into from Jan 17, 2015

Conversation

nylen
Copy link
Member

@nylen nylen commented Jan 14, 2015

This circular dependency is giving me problems with browserify, see
browserify/browserify#1068.

Move the debug property from request to request.Request, and
define a property at the old location to pass through to the new
location for backwards compatibility.

@nylen nylen force-pushed the debug-no-circular-dep branch 4 times, most recently from facdb9c to c09c09e Compare January 14, 2015 17:33
@nylen
Copy link
Member Author

nylen commented Jan 16, 2015

Review @simov @seanstrom @FredKSchott ?

@seanstrom
Copy link
Contributor

Looks good, though are we forced to have the debug module inlined into request.js ?

@nylen
Copy link
Member Author

nylen commented Jan 16, 2015

I was having trouble thinking of a clean way to pass the needed flag. I guess something like this would work though:

lib/debug.js

module.exports = function(Request) {
  Request.debug = // do process.env check
  return function debug(msg) {
    if (Request.debug) {
      // do stuff
    }
  }
}

and in request.js

var debug = require('./lib/debug')(Request)

Do you think this is better than just having it inlined?

@seanstrom
Copy link
Contributor

Ehm, It's probably better to have it inline. Now that I see the alternative.

Move the `debug` property from `request` to `request.Request`, and
define a property at the old location to pass through to the new
location for backwards compatibility.
@@ -240,6 +239,14 @@ function Request (options) {

util.inherits(Request, stream.Stream)

// Debugging
Request.debug = process.env.NODE_DEBUG && /\brequest\b/.test(process.env.NODE_DEBUG)
function debug() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd expect to see the debug function up with the other inlined functions, instead of here in the Request prototype methods

@FredKSchott
Copy link
Contributor

+1 lgtm (with 1 small comment)

@nylen
Copy link
Member Author

nylen commented Jan 16, 2015

Yeah that's one of the reasons I wanted some review on this. It's here because the linter complains about use of Request before it's defined otherwise, and moving it to the bottom makes it complain about the same thing with debug.

@nylen
Copy link
Member Author

nylen commented Jan 16, 2015

@FredKSchott I guess I could put var debug at the top, then debug = function()... at the bottom, would that be better?

@FredKSchott
Copy link
Contributor

Ah yea, I see that now. In that case I'm fine with what you have written, it makes sense given the layout. Although it also means our constructor could never call debug, which is a shame.

Not sure if defining var debug at the top buys us much, that would confuse me even more :)

The only other solution I can think of would be to define some var isDebugEnabled to hold the flag instead, and then expose some Request.getDebug/setDebug methods for index.js to hook into that check that flag. But... that's not too much cleaner.

@nylen
Copy link
Member Author

nylen commented Jan 16, 2015

Agreed, and I'd rather avoid adding more machinery here. Somebody besides me want to merge this?

Minor issues in the scheme of things, but I've been reminded of this article a lot lately: http://stilldrinking.org/programming-sucks

@FredKSchott
Copy link
Contributor

Haha yea, but I'm glad these are our problems now, vs "what the hell is this code doing please halp"

Also fwiw, you can always enable/disable eslint rules within certain code blocks:

/*eslint-disable no-alert, no-console */

alert('foo');
console.log('bar');

/*eslint-enable no-alert */

seanstrom added a commit that referenced this pull request Jan 17, 2015
Remove circular dependency from debugging code
@seanstrom seanstrom merged commit f0b7f75 into request:master Jan 17, 2015
@nylen
Copy link
Member Author

nylen commented Jan 17, 2015

thanks @seanstrom for the separation of duties :)

nylen added a commit to nylen/request that referenced this pull request Jan 29, 2015
Make debug a prototype method.  This has a couple of advantages:

- It's no longer necessary for the debug code to be at a specific place
  in request.js, see request#1354
- It's easier for helper methods in other files to generate debug
  messages, see request#1360
@nylen nylen mentioned this pull request Jan 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants