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
hiring-french
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
p

Peter Mandeljc

02/07/2023, 10:23 AM
Any opinion on prefixing
Flow<Boolean>
with "is". E.g.
val isVisible: Flow<Boolean>
?
s

Sam

02/07/2023, 10:34 AM
I would follow the same convention as for a regular Boolean property. In my experience Kotlin uses the
is
prefix for those, though I can’t find a mention in the official style guide…
e

ephemient

02/07/2023, 10:50 AM
Kotlin property naming generally follows JavaBeans conventions, http://www.oracle.com/technetwork/java/javase/documentation/spec-136004.html
Kotlin's
var foo: Any
behaves like
public Object getFoo();
public void setFoo(Object);
in Java
the JavaBeans specification explicitly allows
public boolean isFoo();
to be a getter for the
foo
property, only if the type is
boolean
.
that does not apply to
Flow<Boolean>
, so I would not name it
isVisible
o

Oliver.O

02/07/2023, 10:55 AM
So what would you suggest instead?
j

Javier

02/07/2023, 10:56 AM
I think the main reason in Kotlin is used
isBoolean()
over
isBoolean
are contracts, when contracts are supported on getters and not only functions, probably all will be moved to getters instead of normal functions
e

ephemient

02/07/2023, 10:57 AM
Kotlin will still generate `isVisible()`/`setFoo()`, so it's not as confusing to Java consumers as `getIsFoo()`/`setIsFoo()` would be… but what name would be better would depend on context
??
I'm sorry, I can't parse what you wrote there.
j

Javier

02/07/2023, 10:58 AM
Additionally, if you move to "reactive" like elements like compose or flow with molecule, where the
Flow
box disappears, they use
isVisible
too
I am not sure if it is a better name
isVisibleStream
over
isVisible
, I would stick without
Stream
IMO
e

ephemient

02/07/2023, 11:00 AM
visibilities.collect { isVisible -> }
reads better to me than
isVisible.collect { ??? -> }
j

Javier

02/07/2023, 11:00 AM
@ephemient not sure about Java tho, I am thinking in Kotlin in general, I haven't consumed Kotlin from a Java project, maybe
@JvmName
can help there?
visibilities
looks weird for me, it is the state of an element, so it can look like there are visibilities for multiple components on the first sight
o

Oliver.O

02/07/2023, 11:02 AM
It's a series of visibility states. So plural makes sense.
s

Sam

02/07/2023, 11:04 AM
I like the singular, because I would think of it as one value that changes over time, rather than a series of values. And I don’t like the Hungarian notation of e.g.
isVisibleStream
. The type already conveys that.
j

Javier

02/07/2023, 11:05 AM
what if you have
Flow<List<Boolean>>
that will be
visibilities
for me
s

Sam

02/07/2023, 11:15 AM
Curious: would
isVisible
be more palatable for a
StateFlow
than a plain old
Flow
?
o

Oliver.O

02/07/2023, 11:17 AM
In general, I agree with @Sam in that Hungarian notation is a bad idea and we should avoid repeating type information in names. If it were a
MutableState
, I'd name it
isVisible
. With flows, the plural makes sense to me, because it becomes a series of changes, and that's a different beast than a single value, even if it were a changing single value.
e

ephemient

02/07/2023, 11:23 AM
StateFlow<Boolean>
results in
isVisible.value
which I don't like, but it's less bad than the
Flow<Boolean>
scenario IMO
j

Javier

02/07/2023, 11:23 AM
There is no difference between
MutableState
and
Flow
, or whatever
Flow
like box as it is a series of elements. Indeed with Molecule you get with
Flow
the same you have with
MutableState
e

ephemient

02/07/2023, 11:24 AM
MutableStateFlow
is a
Flow
of course, so in the cases where you're using it as a flow (and performing mapping operations on it or collecting it) then I would apply the
Flow
rules to it
simply getting the
value
once is… eh, not that bad
j

Javier

02/07/2023, 11:25 AM
Additionally, it is possible to use references too
visibilities.collect(MyComponent::show)
vs
isVisible.collect(MyComponent::show)
o

Oliver.O

02/07/2023, 11:26 AM
There is no difference between
MutableState
and
Flow
,
Then how would you iterate over a series of values with plain
MutableState
?
e

ephemient

02/07/2023, 11:26 AM
oh are we talking about Compose's MutableState and not Flow's MutableStateFlow now?
that's not what the discussion was earlier, but ok
j

Javier

02/07/2023, 11:27 AM
@ephemient I think he was meaning to the Compose
MutableState
which they do a trick as with Compose you "remove" the box, so it is a series of values but you write it like if it was only one
val isVisible = visibilities.collectAsState()
e

ephemient

02/07/2023, 11:27 AM
at least that's not what I read earlier… did I misread?
j

Javier

02/07/2023, 11:28 AM
it looks weird to me too
e

ephemient

02/07/2023, 11:28 AM
that one makes total sense to me
you're pulling a snapshot out of the all the visibilities over time
j

Javier

02/07/2023, 11:29 AM
in practice I think nobody does that, as an example with MVI could be
val state = store.state.collectAsState()
o

Oliver.O

02/07/2023, 11:29 AM
I just wanted to use another type expressing the same state, so just for the argument I chose
MutableState
. I'd name the base value and its mutable variant the same, so not Hungarian.
j

Javier

02/07/2023, 11:29 AM
But I am not 100% sure, maybe
store.states.collectAsState()
exists, I haven't used it too much
additionally, in the store what would we have for the private part?
_states
? or
_state
?
_states.value = ...
vs
_state.value = ...
and when they improve the part in which we don't need the private property, we would use
states
or
state
so the consumer and the producer will use the same one
p

Peter Mandeljc

02/07/2023, 11:41 AM
I guess Kotlin authors would agree on singular form, because we have
FlowState
and not
FlowStates
?
e

ephemient

02/07/2023, 11:42 AM
no, what does that have to do with it?
val names: List<Name>
a list is a singular collection containing multiple items, a flow is a singular object emitting multiple items
p

Peter Mandeljc

02/07/2023, 11:53 AM
ups, makes sense. But since you just said it's a singular object, is it really ok to name it in multiple form? 🙂
e

ephemient

02/07/2023, 11:55 AM
yes. in real life, you call the Smith family, the Smiths. one singular family, multiple family members. ditto objects.
l

louiscad

02/11/2023, 6:43 PM
Personally, I'd name it
isVisibleFlow
or
isVisible
if it doesn't create name clashes and it doesn't end up being more confusing.