https://kotlinlang.org logo
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
benchmarks
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
confetti
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
lincheck
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
Title
c

Colton Idle

03/25/2022, 9:15 PM
A little bit of a discussion based around method naming. I essentially have an interface with methods like this. Not all methods have a "oneshot" and "flowable" version, but a lot of them. Some of them will be exclusively oneshot or flowable. But idk how I feel about the names. I could just have a suffix of
Flowable
but that smells like hungarian notiation... but I do remember a book/blog post (effective java?) that said it should be clear when a method is doing stuff with threads/async. Thoughts?
interface MyRepository {
    suspend fun getLatestBooks(): List<Book>
    fun getLatestBooksWithLiveUpdates(): Flow<List<Book>>
    suspend fun getBookDetail(): BookDetail
    fun getBookDetailWithLivesUpdates(): Flow<BookDetail>
}
a

Adam Powell

03/25/2022, 9:20 PM
usually I treat flows as plurals of what they return, e.g.
val latestBookLists: Flow<List<Book>>
, generally as properties instead of methods unless the flow needs to be recreated+parameterized
1
c

Casey Brooks

03/25/2022, 9:20 PM
I might go with something more like
getLatestBooksAsFlow()
, taking from the Compose convention of things like
StateFlow.collectAsState()
. Alternatively, you may consider only returning
Flows
, not having any dedicated one-shot methods, and doing
.first()
on those flows in place of the
one-shot
methods (if your data sources allow for that, that is)
a

Adam Powell

03/25/2022, 9:21 PM
yeah,
latestBookLists.first()
is generally enough to not require a one-shot get method alongside it, but sometimes situational subscription overhead makes it suitable. If something can change such that you want a flow in some cases, it's also worth asking if exposing one-shot getters encourages weird race conditions somewhere. Often the answer is yes.
c

Colton Idle

03/25/2022, 9:23 PM
So idk if this helps. but the additional context is that this is built firebase's firestore. So basically you can take any one-shot query you wrote and convert it into a flowable (i.e. providing real time updates) I do like the "can you just remove all one-shot requests and instead use .first()" idea
val latestBookLists: Flow<List<Book>>
somehow seems confusing to me. Maybe I gotta re-read it a bit more. Wouldn't
latestBooksLists
make more sense? Basically when you land on my app you see a list of the top 10 books, and if a title change or something on the BE, then you see the update live. Hence why I thought
WithLiveUpdates
was kinda nice because it explains the intent a bit?
a

Adam Powell

03/25/2022, 9:30 PM
Kinda redundant though, isn't it? What else would a flow be?
c

Colton Idle

03/25/2022, 9:33 PM
I suppose so. I guess not having type information baked into the name makes sense. but yeah. theres something about using these in practice where we've shot ourselves in the foot (having a flowable in a flowable) and so I'm trying to make the name more apparent.
e

ephemient

03/25/2022, 9:34 PM
val latestBookss: Flow<List<Book>>
:android-badvice:
😂 1
a flow inside a flow sounds like a valid thing to use sometimes, though. what kind of foot-gun did you run into?
c

Colton Idle

03/25/2022, 9:42 PM
We weren't getting live updates after we did the flow in a flow.
The flow within a flow was accidental. Once we had them be two flows that just run on their own everything was updating just fine.
But anyway. appreciate the thoughts. Looks like generally my hunch of like "dont encode Types into the name" kinda still stands. But the idea of just not having one-shots was interesting. I will play around with it a bit more. thanks
m

myanmarking

03/25/2022, 10:46 PM
I generally name it getX (suspend) vs observeX (flow)
c

Colton Idle

03/25/2022, 10:47 PM
oOoOO
m

myanmarking

03/25/2022, 10:51 PM
?
c

Colton Idle

03/25/2022, 10:59 PM
I like it! Didn't think of that.
👍 1
u

ursus

03/27/2022, 9:05 AM
I call it
loadFoo
for one time and
foo
for flow
k

K Merle

03/27/2022, 6:30 PM
I don't add suffixes in that case. If you're really interested in type, you can literally just check object type by inspecting the object.
z

Zoltan Demant

04/01/2022, 5:04 AM
get -> T
query -> Flow<T>
Been doing this forever ❤️ Does it seem clear to you? It does to me, but I might just be super-used to it! 😛arty-parrot:
👍 1
c

Colton Idle

04/04/2022, 5:29 PM
@Adam Powell re
yeah,
latestBookLists.first()
is generally enough to not require a one-shot get method alongside it, but sometimes situational subscription overhead makes it suitable. If something can change such that you want a flow in some cases, it's also worth asking if exposing one-shot getters encourages weird race conditions somewhere. Often the answer is yes.
Can you expand on "sometimes situational subscription overhead makes it suitable" The way I initially read this was "there is more overhead to calling .first() on a flowable vs just having a one shot method available"
a

Adam Powell

04/04/2022, 5:55 PM
yes, there's more overhead to calling
.first()
on a flow
it can range from, "a little bit more overhead from throwing a
CancellationException
to stop the upstream after the first" to, "implementation of the specific flow sets up a two-way subscription over a long-running connection with a server instead of a much simpler REST request/response"
c

Colton Idle

04/04/2022, 7:59 PM
Hm. Okay. In my case, I will just keep two separate methods for now. Thanks Adam!