You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I really like the idea of lazy evaluations and initialization.
But I am not sure that the vocabulary borrowed from RSpec ("let") sits with me well.
What if you could just use the words lazy and eager instead of let and eager?
And letc I would propose to merge with let (and replace by eager/lazy), and instead of the current dependency use depends or inject. This would better express that lazy/eager is for defining a dependency that will be used elsewhere, while depends or inject is for expressing a dependency on the externally defined object.
Also, instead of receiving box as an argument, perhaps the lambda can be run as instance_exec from the box itself, so that you don't need to provide box. and can just type this:
classMyApp::MainBoxincludeLittleBoxes::Boxlazy(:redis)dorequire'redis'Redis.newendeager(:publisher)do# no parameter, because evaluated inside of box.instance_execPublisher.newredis: redisendendclassPublisherincludeLittleBoxes::Configurableinject:redisendclassMainBox# ...lazy(:publisher){Publisher.new}end
What is the purpose of letc and why not just always resolve dependencies? I totally get the need for lazy and eager, but I wasn't really clear why you'd need two methods to define objects in the mainbox.
Overall — interesting concept and definitely worth looking into. Thanks for your work, and feel free to throw away all the suggestions. After all, naming is highly subjective if not personal :)
The text was updated successfully, but these errors were encountered:
Hi @kigster, thank you very much for your suggestions. They are very interesting. Let me reply to them one by one:
What if you could just use the words lazy and eager instead of let and eager?
...and instead of the current dependency use depends or inject
Sounds like a good alternative. I wouldn't consider making this change at this stage though.
And letc I would propose to merge with let
I actually thought about this when I started the library. I thought on relying on responds_to? to check if the object is configurable. However I learned that relying on responds_to? can be a can of worms and leads to unexpected behavior. I decided to discard it.
Also, instead of receiving box as an argument, perhaps the lambda can be run as instance_exec from the box itself, so that you don't need to provide box.
I also thought about this. instance_exec can bring unexpected behavior too, like preventing access to the outside scope.
I really like the idea of lazy evaluations and initialization.
But I am not sure that the vocabulary borrowed from RSpec ("let") sits with me well.
What if you could just use the words
lazy
andeager
instead oflet
andeager
?And
letc
I would propose to merge withlet
(and replace by eager/lazy), and instead of the currentdependency
usedepends
orinject
. This would better express thatlazy/eager
is for defining a dependency that will be used elsewhere, whiledepends
orinject
is for expressing a dependency on the externally defined object.Also, instead of receiving box as an argument, perhaps the lambda can be run as
instance_exec
from the box itself, so that you don't need to providebox.
and can just type this:What is the purpose of
letc
and why not just always resolve dependencies? I totally get the need forlazy
andeager
, but I wasn't really clear why you'd need two methods to define objects in the mainbox.Overall — interesting concept and definitely worth looking into. Thanks for your work, and feel free to throw away all the suggestions. After all, naming is highly subjective if not personal :)
The text was updated successfully, but these errors were encountered: