27.01.2014, 05:22, "Ryan Schmidt" <[email protected]>: > On Jan 21, 2014, at 15:26, Alex Kocharin wrote: > >> As for models, requiring a file without assigning its returning value means >> that that file have side effects. It is rarely justified (except for tests), >> and if you have the whole folder of such files, it smells really bad. > > Doesn’t smell bad to me. Last time I looked at writing a nodejs app using > mongodb, for example, you were expected to register all your models at the > start of the application. There’s no need to assign the return value to > anything, because the models are already known to the mongodb library and you > can retrieve them whenever you need them.
If you require something and don't use return values, it means this module has side effects. "Side effects" mean "state", and functional languages avoid them for a good reason. Such module tends to depend on cache and break if it's required twice. It is often untestable, if you have to require the module multiple times in tests. It is hard to pass parameters to such module, and it is very hard to pass different ones. I found exactly three uses of such require() with side effects in my modules: 1. heapdump 2. date-utils (extending Date prototype, doh) 3. coffee-script/register All three are there for a good reason. If I find another one, I'd flag them on code review right away... it doesn't mean that it's wrong, but it's a clear sign that something is wrong. It's the same deal as with global variables by the way. It's often justified to use them, but in the general case the rule is "don't". -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
