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

Verbose/Complete Local Requirements #15

Closed
caffeinewriter opened this issue Apr 18, 2014 · 4 comments
Closed

Verbose/Complete Local Requirements #15

caffeinewriter opened this issue Apr 18, 2014 · 4 comments

Comments

@caffeinewriter
Copy link
Contributor

I'm not sure if this should fall under the scope of the style guide, but should requirements be verbose?

E.g.

var sample = require('./routes');
vs
var sample = require('./routes/index.js');

Or

var other = require('./routes/other');
vs
var other = require('./routes/other.js');

I personally always include them, to avoid any accidental conflicts that might be cause by editor autosaves, or something wonky, yet Express uses the former rather than the latter.

This is just one thing I was pondering, since the latter seems like a better practice. However, I'm not sure it actually warrants inclusion in the style guide.

@caffeinewriter caffeinewriter changed the title Verbose Requirements Verbose/Complete Local Requirements Apr 18, 2014
@felixge
Copy link
Owner

felixge commented Apr 22, 2014

i'm never verbose, but i don't feel strongly about it

@ghost
Copy link

ghost commented Apr 22, 2014

You are requireing, not including, which means the one without .js at the end should be used.

@guomo
Copy link

guomo commented Sep 26, 2014

What about where the require is included? For clarity I think requires should always be at the top of the file unless there is a really good reason to only include in a closure/scope of some sort like a rare conditional. I see code all the time where people do lazy requires, inline, etc. To me it obfuscates the code making difficulty to understand a file's external dependencies. My suggested rule should be something like this:

Requires At Top

Always put requires at top of file to clearly illustrate a file's dependencies. Besides giving an overview for others at a quick glance of dependencies and possible memory impact, it allows one to determine if they need a package.json file should they choose to use the file elsewhere.

@kentcdodds
Copy link
Contributor

I would be fine merging something like that in @guomo.

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

No branches or pull requests

5 participants