https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
announcements
  • h

    Hullaballoonatic

    12/21/2019, 4:58 PM
    Is it performance improving to lazy implement every field? example:
    class Polygon(val vertices: List<Point>) {
        val height by lazy { vertices.maxBy(Point::y)!!.y - vertices.minBy(Point::y)!!.y }
        val width by lazy { vertices.maxBy(Point::x)!!.x - vertices.minBy(Point::x)!!.x }
    
        val edges by lazy { (points + points.first()).zipWithNext(::Line) }
    
        val area by lazy { edges.sumByDouble { (cur, next) -> cur.x * next.y - cur.y * next.x } / 2 } // shoelace method
        
        val centroid by lazy {
            edges.reduce(Point.Origin) { acc, (cur, next) ->
                acc + ((cur + next) * (cur.x * next.y - next.x * cur.y))
            }
        }
        
        // etc
    }
    Afaik Advantages: • faster instantiation • instance fields that are never accessed are never computed Disadvantages: • instance fields computed when first accessed, which may be a performance heavy time General questions: • Does
    lazy<T>
    occupy more space than
    T
    ? Answered: yes, it creates an object and a lambda in memory • Is there some kind of performance impact at initialization for
    lazy
    that may make for a negligible difference in impact for many fields? • Am I an idiot, and unless something is rarely accessed, I should just completely avoid using
    lazy
    ?
    d
    m
    +4
    • 7
    • 19
  • t

    tjohnn

    12/21/2019, 11:42 PM
    I guess this has to do with Type erasure but I can't get a solution, I want to have a centralized function for firebase callback, so I have something like this:
    fun <T> dataAsFlow(){
        //ValueEventListener impl start
        val type= object : GenericTypeIndicator<List<T>>() {}
        val result = dataSnapshot.getValue(type)
        // emit result
        //ValueEventListener impl end
    }
    The problem is data is getting deserialized into
    List<HashMap<String, String>>
    instead of
    List<T>
    . It works well if I am using the real type, say, e.g
    List<Category>
    instead of
    List<T>
    t
    d
    • 3
    • 12
  • s

    Slackbot

    12/22/2019, 2:50 PM
    This message was deleted.
    s
    • 2
    • 2
  • s

    Siva Ganesh

    12/23/2019, 3:32 AM
    “Advanced Android Programming With Kotlin” by Siva Ganesh Kantamani https://link.medium.com/Z3Lnuu7cD2 Provide your thoughts in comments if you've time.
    n
    • 2
    • 4
  • s

    smallufo

    12/23/2019, 9:44 AM
    Hi , I am new to
    kotlin-serialization
    , I have a problem serializing interface/implementation by modules , can someone take a look at my problem on SO ? https://stackoverflow.com/questions/59453009/serializer-for-interface-implementation , thanks.
    s
    • 2
    • 1
  • r

    Robert Jaros

    12/23/2019, 11:25 PM
    Is it possible to split
    build.gradle.kts
    file, so I could have the whole project configuration in one file and dependencies listed in the second?
    m
    g
    +2
    • 5
    • 6
  • d

    Doganmiketuran

    12/24/2019, 1:23 PM
    Is this code , java or kotlin?
    a
    • 2
    • 4
  • h

    Holger Steinhauer [Mod]

    12/24/2019, 1:24 PM
    Happy holidays everyone
    🎄 15
    👍 12
    j
    • 2
    • 1
  • m

    Marc Knaup

    12/24/2019, 2:56 PM
    Has anybody measured the performance impact of using
    Result
    -style classes? (and
    sealed
    vs.
    inline
    for distinguishing cases). I imagine plenty of object allocations.
    b
    j
    • 3
    • 4
  • m

    Marc Knaup

    12/24/2019, 3:26 PM
    Why is is legit to call any extension function on
    Nothing
    , but not for example class functions? Is that a bug? This is especially confusing if
    this
    (unexpectedly?) resolves to
    Nothing
    because there’s not even a warning 😅
    error("foo").hasSurrogatePairAt(1)
    d
    a
    +3
    • 6
    • 35
  • d

    Doganmiketuran

    12/24/2019, 5:23 PM
    Someone who know why i can't compile the last dependency in the bottom ?
    d
    g
    • 3
    • 3
  • d

    Doganmiketuran

    12/24/2019, 5:26 PM
    do you know , what is the problem here ?
    t
    • 2
    • 8
  • c

    Czar

    12/24/2019, 6:13 PM
    Hi, there is a nice collection of good practices when writing tests in kotlin, I specifically was excited about Parameterized tests part. But in IntelliJ I see only
    this should pass(TestData)[1]
    , not the beautiful toString result of the TestData data class like it's shown in the guide: https://phauer.com/2018/best-practices-unit-testing-kotlin/#data-classes-for-parameterized-tests Does anyone have an idea, why is junit not printing contets of TestData? I have implemented the test exactly as in the guide.
    n
    • 2
    • 2
  • b

    bbaldino

    12/24/2019, 9:21 PM
    is there a way to accomplish something like this without the need for a temp variable?
    val temp = someMember
    someMember = null
    temp.close()
    i've got multiple threads accessing
    someMember
    (via
    ?.
    ), want to make sure it isn't accessed in between calling
    close()
    and assigning it to null.
    m
    • 2
    • 6
  • d

    Doganmiketuran

    12/24/2019, 9:44 PM
    I have problems with this part of the code... Someone who know why? ... i can't understand why.
    g
    • 2
    • 2
  • b

    b0R1NGx

    12/24/2019, 10:23 PM
    Hey guys, i try to set a font for my needs, but get this this is a java.awt.Font package, why compiler says me this
    s
    • 2
    • 6
  • g

    ghedeon

    12/25/2019, 11:19 AM
    More like a type puzzle, is it possible to solve it without specifying the second type as well?
    interface IFoo<A>
    class Foo: IFoo<String>
    class Bar<A>: IFoo<A>
    
    inline fun <reified T: IFoo<*>> createBar(){
       val type = T::class.supertypes[0].arguments[0].type // the type is not lost, String is here
    
       Bar<type>() // ?? how to use it here
    }
    
    createBar<Foo>()
    I know that I can declare something like
    fun <A, T:IFoo<A> createBar()
    , but it's kind of repeating myself and the
    A
    is already known...
    ➕ 1
    a
    d
    • 3
    • 10
  • d

    Doganmiketuran

    12/25/2019, 12:10 PM
    Someone who know the problem here?
    d
    • 2
    • 2
  • g

    ghedeon

    12/26/2019, 12:55 PM
    [SOLVED] When using synthetics, is there any performance difference between: 1.
    class Holder(override val containerView: View) : ViewHolder(containerView), LayoutContainer {
        fun bind() {
            my_view
        }
    }
    2.
    class Holder(override val containerView: View) : ViewHolder(containerView), LayoutContainer {
        fun bind() {
            containerView.my_view
        }
    }
    • 1
    • 1
  • m

    Matthieu Stombellini

    12/26/2019, 3:28 PM
    Are there any plans when it comes to the Kotlin Scripting support being stabilized out of the experimental phase? This has lots of potential but I feel like it's not getting any love or attention from Kotlin devs 😕 https://github.com/Kotlin/KEEP/issues/75
    g
    • 2
    • 2
  • s

    steenooo

    12/26/2019, 9:40 PM
    Does a lombok-like-ish generator for a kotlin script dsl exist? 🤔
    s
    • 2
    • 5
  • o

    Orhan Tozan

    12/26/2019, 11:48 PM
    Hey guys, we are using Kotlin to build a native Android app, and we are planning to also build an native iOS app. We have a lot of business logic written in Kotlin right now, and its nicely layered, so seperated from the Android framework. I've read about Kotlin Multiplatform and its option to share common logic between different platforms, although after reading more, I'm not sure if our usecase is supported by Kotlin multiplatform. My question and usecase is: is it possible to have a 3 seperate repo setup: core (written in Kotlin), android-app (written in Kotlin) and ios-app (written in Swift). android-app and ios-app both use the core project.
    a
    s
    • 3
    • 3
  • d

    David Martin

    12/27/2019, 7:33 AM
    Hi guys, how is it going? I wanna ask if there’s a framework or something similar which will be integrated into github and check for coding convention + build and deploy android apps, and if my code aren’t conform to the coding conventions then the build processing will be exhausted and errors will be logged on github or email to me? Thank you very much.
    m
    • 2
    • 4
  • c

    Chirag Prajapati

    12/27/2019, 9:49 AM
    Anyone help me to found a solution to this error: java.lang.SecurityException: This PhoneAccountHandle is not enabled for this user. Thanks in advance
    b
    • 2
    • 4
  • c

    Czar

    12/27/2019, 11:40 AM
    Hi, looking at inline classes now. In our codebase we have
    typealias Amount = BigDecimal
    to mark amounts which have proper scaling and rounding. It serves well as a markier, but unfortunately doesn't help with compile time checking. I wonder if I can instead use inline classes. The problem is there is a lot of jackson mapping and JPA Hibernate mapping going on in the application. So I wonder will inline classes "just work" with all this mappinng?
    j
    • 2
    • 4
  • d

    Doganmiketuran

    12/27/2019, 2:20 PM
    Hi folks.. When i try to clone my kotlin project from GitHub.. It gives me an error which isn't in the original project? It comes in the clone version. idk why? Can you help me ?
    s
    • 2
    • 1
  • d

    David Glasser

    12/27/2019, 6:20 PM
    does kotlin stdlib have a function like
    Boolean.something<T>(f: () -> T): T?  = if (this) { f() } else null
    ?
    e
    i
    • 3
    • 3
  • d

    David Glasser

    12/27/2019, 6:24 PM
    also, is there a way in this context:
    class Foo<T> {
      fun <U> function() { ... }
    }
    to compile-time constraint
    U
    to be either
    T
    or
    List<T>
    (subclasses of T are OK too)?
    s
    • 2
    • 1
  • c

    Czar

    12/28/2019, 2:53 PM
    interface Provider {
      fun <P : X> provide(name: String, clazz: KClass<out P>): P?
    }
    inline fun <reified P : X> Provider.provide(name: String): P? =
      provide(configName, P::class)
    I want to discourage use of normal provide and enable easy migration, so I put
    @Deprecated
    annotation on it like this:
    @Deprecated(
      message = "Direct usage of provide(name, clazz) is discouraged",
      level = DeprecationLevel.WARNING,
      replaceWith = ReplaceWith(
        expression = "???",
        imports = ["com.example.provider.provide"]
      )
    )
    I can't get the replacement exception right. Say I have this in code:
    myProvider.provide("asdf", MyData::class)
    when expression is 1.
    provide(name)
    → the code is replaced with
    provide("asdf")
    - receiver is lost 2.
    provide<clazz>(name)
    → the code is replaced with
    myProvider.provide<clazz>("asdf")
    I understand, that substitutor is not smart enough to decode
    clazz
    , but when I don't specify it resulting code is even more broken. Is this a bug? I want the replacement to be either
    myProvider.provide<MyData>("asdf")
    or at least
    myProvider.provide("asdf")
    m
    • 2
    • 2
  • h

    Hullaballoonatic

    12/28/2019, 8:13 PM
    Can someone explain the advantages of dependency injection in kotlin as opposed to just using an object(/singleton)?
    i
    n
    a
    • 4
    • 55
Powered by Linen
Title
h

Hullaballoonatic

12/28/2019, 8:13 PM
Can someone explain the advantages of dependency injection in kotlin as opposed to just using an object(/singleton)?
i

itnoles

12/28/2019, 8:18 PM
very similar to https://blog.kotlin-academy.com/dependency-injection-the-pattern-without-the-framework-33cfa9d5f312
n

nfrankel

12/28/2019, 8:19 PM
whether in kotlin or any other language one word: ability to unit test the class
☝️ 2
h

Hullaballoonatic

12/28/2019, 8:20 PM
a unit test is simply a comprehensive test of the endpoints of a class using a constant state, right, so why can't that be performed on a kotlin
object
?
n

nfrankel

12/28/2019, 8:22 PM
it’s not about the kotlin
object
it’s about users of it
you cannot test them independently
a

Adam Powell

12/28/2019, 8:22 PM
if the kotlin
object
itself is stateful you can't provide a constant state to things that consume it, you're at the mercy of its current internal state
☝️ 1
n

nfrankel

12/28/2019, 8:22 PM
if you’re intested, i’ve written a piece https://blog.frankel.ch/basics-dependency-injection/
h

Hullaballoonatic

12/28/2019, 8:25 PM
Oh, I suppose I understand. A DI class can be acquired stateless at any time. An object is stateful, and various unit tests run using it would make it very difficult to ensure it is in a constant state.
n

nfrankel

12/28/2019, 8:27 PM
di means you can inject an object with the state you want and thus can test other objects that use it with a known state
a

Adam Powell

12/28/2019, 8:42 PM
DI doesn't solve the problem of making things testable, DI solves a problem that is often created by certain patterns of making things testable: configuring complex object graphs
n

nfrankel

12/28/2019, 8:49 PM
di solve the problem of making classes being testable in isolation
a

Adam Powell

12/28/2019, 9:16 PM
no, interfaces solve that. 🙂 DI solves the problem of having to construct and configure too many interface-implementing objects along the way to getting a concrete instance of an object with a complex dependency graph.
Having that second problem is not a foregone conclusion when you're making things testable, but if you do have it, DI is a good solution to it.
n

nfrankel

12/28/2019, 9:19 PM
no, interfaces solve that
no 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 😉
a

Adam Powell

12/28/2019, 9:20 PM
I read it 🙂
👍 1
n

nfrankel

12/28/2019, 9:20 PM
then you understood the gist is: the problem lies within instantiation interfaces don’t solve that issue
you need to remove the instantiation from inside the class
there are ways to do that di is one of them
a factory based on environment variables/system properties/etc. is another one
a

Adam Powell

12/28/2019, 9:22 PM
it sounds like we agree then 🙂
n

nfrankel

12/28/2019, 9:22 PM
then i don’t understand your point 😞
a

Adam Powell

12/28/2019, 9:22 PM
sorry, my phrasing was perhaps confusing
providing dependencies using interfaces helps make things testable, but in itself it is not, "dependency injection" in the sense of an injection framework that resolves dependency graphs for you to create object instances, which is what most people think of when they say, "DI."
n

nfrankel

12/28/2019, 9:24 PM
good point in my post, i try to explain that di is not dependent on frameworks you can di yourself
a

Adam Powell

12/28/2019, 9:25 PM
at that point it's not really "injection," it's just, "providing arguments to functions" 🙂 - though it makes for a good teaser description for a blog post that people will find in search!
n

nfrankel

12/28/2019, 9:25 PM
and about interfaces, you don’t need them for di (not saying interfaces are not useful) the important part is to create and configure the dependent object outside of the dependable object (not sure dependable is the correct word sorry, english is not my native language)
a

Adam Powell

12/28/2019, 9:26 PM
no worries, I'm also being sloppy with my language on holiday here as well 🙂
n

nfrankel

12/28/2019, 9:26 PM
at 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
enjoy your holidays 🎉
a

Adam Powell

12/28/2019, 9:27 PM
thanks!
a constructor is just a special kind of function; especially in kotlin where you see patterns like factory functions named after the type name they return so that they look like a constructor invocation at a call site
n

nfrankel

12/28/2019, 9:28 PM
yes, but a function is not a special kind of constructor
a

Adam Powell

12/28/2019, 9:32 PM
how would you consider a factory object?
n

nfrankel

12/28/2019, 9:46 PM
what do you mean? for me, it’s another way to do inversion of control
a

Adam Powell

12/28/2019, 9:56 PM
drawing a parallel between a factory object and a factory function and that they're all facets of the same idea of bringing control out and away from an object implementation; constructors aren't special in particular for inverting control
n

nfrankel

12/28/2019, 10:18 PM
constructors aren’t special in particular for inverting control
agreed
but so far, imho, they have proven to be the easiest way to do that
but this is getting far from kotlin at this point
a

Adam Powell

12/28/2019, 10:26 PM
to bring it back to Kotlin then, consider DSL functions and builders such as
flow {}
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.
Kotlin opens a lot of exciting doors for inversion of control! 🙂
n

nfrankel

12/28/2019, 10:28 PM
it would help if you provided a snippet 😅
a

Adam Powell

12/28/2019, 10:38 PM
I'll see if I can extract one from something later
👍 1
here's a rough snippet from a hobby project:
mqttClient(
    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.
n

nfrankel

12/29/2019, 10:26 AM
interesting! di for functions 🙂 now i understand your point about constructors
a

Adam Powell

12/29/2019, 5:15 PM
🙂 This is also why I disagree with the use of the term, "DI" to describe any sort of providing a nontrivial policy object as a parameter to a function and prefer to reserve the term for describing the use of DI frameworks - once you explore the space a bit, if you apply it to any parameter passing then it becomes so widely scoped as to be kind of meaningless. Plus, given the widespread knowledge across the web about DI how-to, overgeneralizing it tends to confuse newcomers. "Manual DI" is a nice, snappy term to demystify the inner workings and concepts of DI frameworks, but without the, "injection" part being performed by such a system, it's hard to call it DI. "Inversion of control"/IoC seems sufficient as a term to describe the more general pattern at play.
And I've come to like the pattern from the snippet above a lot. As I've used more function-forward designs like that, I've found my code becomes easier to read both in implementation and in use, easier to test without building complex test harnesses or configurations, and it has fewer bugs the first time
I think I ended up bringing some of this thinking to kotlin after writing a bunch of go, you can see a lot of similarities especially in the way coroutines evolved, e.g. the
go
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 way
n

nfrankel

12/29/2019, 5:25 PM
I disagree with the use of the term, “DI” to describe any sort of providing a nontrivial policy object as a parameter to a function
it’s hard to change the semantics of a agreed-upon term i think you should come up with your own
if we both use the same word with different semantics it’s hard to understand each other
a

Adam Powell

12/29/2019, 5:26 PM
I feel the same way about your usage of it 😄
but you're not the only one to use it that way and by now I've resigned myself to grumble a bit like the above and then agree to disagree
but since there is disagreement in the community, documentation, and search results across the web we both need to clarify which definition we're using for our audiences
n

nfrankel

12/29/2019, 5:29 PM
but you’re not the only one to use it that way
that’s my point it’s agreed upon by many easier if you come up with a term that describes your meaning
a

Adam Powell

12/29/2019, 5:30 PM
the definition I use is also agreed upon by many 🙂
😮 1
n

nfrankel

12/29/2019, 11:27 PM
would be interested in more info on that
View count: 5