Hi all,
Thanks for your answers. I'll try to address all your questions:
* What are the advantages of using domains?
The killer feature, for me, was that all the new events created inside
a domain get propagated only inside such domain. This allowed me to
use events without worrying about polluting other requests.
Having the request globally accessible is a (nice) side effect, even
if that were not possible, I think domains are still worth using.
* What's so bad with passing the request object around?
Nothing, actually. What I do find wrong is passing it "just in case",
adding one more parameter to every call because some method deep in
the call chain may need to make use of it. This is typically the case
with template helpers.
Is not unusual to have a helper function somewhere that checks, for
example, if the user is logged in. For this specific cases I find it
very useful to have the request always available.
Global variables have very well defined dangers [0], which can be controlled by:
1. Making use of it in as few places as possible.
2. Treating it as read-only.
If this 2 rules are followed, there are some cases where they are just
the cleanest solution. Think about the typical use of environment
variables, which is to tell a software which configuration file to
use. It's very handy, gives us a mechanism to modify a software's
behavior without having access to its code. This works because that
variable is read in only one place and is never modified. You have to
be very strict about it.
I even advice against globals in the documentation [1].
Juraj, the `this.request` approach is a good idea, would be useful to
get rid of the parameter injection which I'm not very happy with. But
it doesn't make the request globally accessible, right? As I said, I
like the idea of having both options and trust that the user will use
them responsibly.
Kevin, if I understood correctly, you say that variables defined
globally may leak outside the domain? I guess that it's already a
problem with the fact that Node runs in a single thread. Global
variables are global to every request, and I don't attempt to "fix" it
with domains, only to provide global access to the request.
Cheers!
[0]
http://c2.com/cgi/wiki?GlobalVariablesAreBad
[1]
https://github.com/tooxie/kolba#cons
2013/8/29 Kevin Swiber <
ksw...@gmail.com>:
> --
> --
> 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
nod...@googlegroups.com
> To unsubscribe from this group, send email to
>
nodejs+un...@googlegroups.com
> 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
nodejs+un...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.
--
Alvaro Mouriño