Hullaballoonatic
12/28/2019, 8:13 PMitnoles
12/28/2019, 8:18 PMnfrankel
12/28/2019, 8:19 PMHullaballoonatic
12/28/2019, 8:20 PMobject
?nfrankel
12/28/2019, 8:22 PMobject
it’s about users of itnfrankel
12/28/2019, 8:22 PMAdam Powell
12/28/2019, 8:22 PMobject
itself is stateful you can't provide a constant state to things that consume it, you're at the mercy of its current internal statenfrankel
12/28/2019, 8:22 PMHullaballoonatic
12/28/2019, 8:25 PMnfrankel
12/28/2019, 8:27 PMAdam Powell
12/28/2019, 8:42 PMnfrankel
12/28/2019, 8:49 PMAdam Powell
12/28/2019, 9:16 PMAdam Powell
12/28/2019, 9:19 PMnfrankel
12/28/2019, 9:19 PMno, interfaces solve thatno i write about it in my post i’m too lazy to rewrite it here... it you’ re too lazy to read, that’s fine too 😉
Adam Powell
12/28/2019, 9:20 PMnfrankel
12/28/2019, 9:20 PMnfrankel
12/28/2019, 9:20 PMnfrankel
12/28/2019, 9:21 PMnfrankel
12/28/2019, 9:21 PMAdam Powell
12/28/2019, 9:22 PMnfrankel
12/28/2019, 9:22 PMAdam Powell
12/28/2019, 9:22 PMAdam Powell
12/28/2019, 9:24 PMnfrankel
12/28/2019, 9:24 PMAdam Powell
12/28/2019, 9:25 PMnfrankel
12/28/2019, 9:25 PMAdam Powell
12/28/2019, 9:26 PMnfrankel
12/28/2019, 9:26 PMat that point it’s not really “injection,” it’s just, “providing arguments to functions”imho it is with a nuance, it’s providing arguments to constructors
nfrankel
12/28/2019, 9:27 PMAdam Powell
12/28/2019, 9:27 PMAdam Powell
12/28/2019, 9:27 PMnfrankel
12/28/2019, 9:28 PMAdam Powell
12/28/2019, 9:32 PMnfrankel
12/28/2019, 9:46 PMAdam Powell
12/28/2019, 9:56 PMnfrankel
12/28/2019, 10:18 PMconstructors aren’t special in particular for inverting controlagreed
nfrankel
12/28/2019, 10:18 PMnfrankel
12/28/2019, 10:19 PMAdam Powell
12/28/2019, 10:26 PMflow {}
and similar. The receiver object (which might be an interface) is provided to a block of code supplied by the caller, and that block of code is supplied to the function. If that block is a suspending lambda, it allows the caller to supply a complex policy for behavior over time with a single block of sequential code. DI frameworks and constructor injection may result in a much harder to follow solution in such cases, and both can achieve testability.Adam Powell
12/28/2019, 10:26 PMnfrankel
12/28/2019, 10:28 PMAdam Powell
12/28/2019, 10:38 PMAdam Powell
12/29/2019, 12:48 AMmqttClient(
mqttDialer(hostname),
clientId = clientId,
keepalive = 300,
will = Message(statusTopic, "disconnected", retain = true)
) {
send(statusTopic, "connected", retain = true, qos = Qos.AtLeastOnce)
Managing a connection to an MQTT server is wrapped up into a single suspend function call. The "dialer" function called in the first parameter returns a factory that sets up a connection and returns a socket-like object with a pair of okio sink/source objects as properties. Easy to fake a server with for testing using plain okio Buffer
objects. The trailing lambda parameter is a suspending function with a receiver interface type that implements CoroutineScope
and also offers methods to send mqtt messages (shown) and to get `Flow`s for mqtt topic subscriptions (not shown). When the body block completes and any child coroutine jobs join, the connection is torn down and the function returns. Unrecoverable errors or cancellation throw. Any part of it can be broken down pretty easily for testing and testability, and the dependencies are either provided as regular parameters or they're captured as part of the lambda body from the surrounding lexical scope.nfrankel
12/29/2019, 10:26 AMAdam Powell
12/29/2019, 5:15 PMAdam Powell
12/29/2019, 5:16 PMAdam Powell
12/29/2019, 5:19 PMgo
statement and kotlin's launch
, channels, etc. When you have tools like suspend
to help represent scoped behavior over time, you don't need a graph full of objects and callbacks and strategies and factories in the same waynfrankel
12/29/2019, 5:25 PMI disagree with the use of the term, “DI” to describe any sort of providing a nontrivial policy object as a parameter to a functionit’s hard to change the semantics of a agreed-upon term i think you should come up with your own
nfrankel
12/29/2019, 5:26 PMAdam Powell
12/29/2019, 5:26 PMAdam Powell
12/29/2019, 5:27 PMAdam Powell
12/29/2019, 5:28 PMnfrankel
12/29/2019, 5:29 PMbut you’re not the only one to use it that waythat’s my point it’s agreed upon by many easier if you come up with a term that describes your meaning
Adam Powell
12/29/2019, 5:30 PMnfrankel
12/29/2019, 11:27 PM