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
language-proposals
  • l

    louiscad

    04/21/2017, 1:04 PM
    Wonder why Kotlin is taking off while Clojure didn't so much... I personally really like Kotlin features, and don't find it bloated. BTW, I really like inline methods, and noinline can be useful for all the real world tricky use cases
    p
    d
    • 3
    • 11
  • l

    louiscad

    04/21/2017, 1:31 PM
    Don't think adding so much information in the error is needed since the stacktrace shows you the code where it crashed, which helps knowing why
    b
    • 2
    • 1
  • p

    poohbar

    04/21/2017, 2:00 PM
    Why doesn't the Android framework use enums instead? Those could be checked exhaustively.. Or wrapped in sealed classes or....
    ☝️ 1
    d
    p
    r
    • 4
    • 12
  • s

    spand

    04/21/2017, 2:57 PM
    I doubt you could measure a performance difference even if you tried. The amount of code is obviously a matter of opinion.. but really.. how many enum types are there in Android that you actually use? 10 ? 100 ?
    👍 4
    l
    k
    +2
    • 5
    • 6
  • j

    jw

    04/21/2017, 6:37 PM
    Don't use ints!
    l
    • 2
    • 1
  • i

    irus

    04/22/2017, 9:19 AM
    What about
    auto intefaces
    ? So you can write class. declare that it implements auto interface, and kotlin will generate interface using public members.
    🤔 1
    b
    • 2
    • 1
  • m

    mg6maciej

    04/22/2017, 9:22 AM
    All discussion in this channel should begin with a use-case or proposal instead of a question.
    😉
    i
    o
    • 3
    • 4
  • s

    spand

    04/25/2017, 9:34 AM
    To get rid of the
    .toByte()
    you can just call
    .map()
    To get rid of the many
    0xFF
    then I guess you can specify it in Longs
    0xFF_FF_FF_FF_FF_FF_FF
    and convert to bytes. Im not sure additional syntex is needed.. seems a util package for bits and bytes could take care of most of it
    👍 1
    l
    • 2
    • 6
  • c

    christophsturm

    04/25/2017, 11:52 AM
    “ffff000000000000”.hexStringToByteArray()
    👍 3
    👎 1
    l
    • 2
    • 1
  • d

    dmitry.petrov

    04/26/2017, 7:05 AM
    Not yet. That's just an idea how that could possibly be designed / implemented in Kotlin. Rather shallow one so far.
    b
    r
    • 3
    • 7
  • e

    elizarov

    04/26/2017, 9:01 AM
    I don’t see much improvement that sigils make w.r.t top-level functions. They definitely make tooling trickier. Writing
    Regex("haba")
    instead of
    ~r/haba/
    is only slightly more verbose, but way more readable. The only potential issue that one can see here is performance, e.g. that the function is being invoked at run-time, but there’s a much less intrusive way to solve that: https://youtrack.jetbrains.com/issue/KT-14652
    👍 6
    b
    • 2
    • 1
  • e

    elizarov

    04/26/2017, 12:19 PM
    @rrader
    constexpr
    functions are not macros. The key insight here is that you don’t really need macros most of the time. Macros is like hammer. You can do a lot of things with it, but most of the problems you encounter (inlining debug functions and generating compile-time constants are two good examples here) can (and should be) solved with more targeted features, because those narrower features get a nice tooling automatically without you having to write IDE plugin every time.
    👍 3
    r
    • 2
    • 1
  • r

    rrader

    04/26/2017, 12:29 PM
    of course we can do a lot without any macros, but also we can do a lot without inline functions 😉
    e
    d
    p
    • 4
    • 10
  • p

    Paul Woitaschek

    05/02/2017, 5:56 AM
    Is there an existing proposal for an exhaustive when in a non return block?
    m
    • 2
    • 2
  • k

    kirillrakhman

    05/05/2017, 9:52 AM
    kotlin makes important things explicit
    j
    • 2
    • 6
  • e

    elect

    05/05/2017, 9:53 AM
    what about recursively destructuration?
    fun a() = Pair(0 to 1, 2 to 3)
    
        fun b() {
            val ((a, b), (c, d)) = a()
        }
    k
    • 2
    • 3
  • m

    mg6maciej

    05/05/2017, 11:45 AM
    Also applies here @johnl
    r
    • 2
    • 3
  • p

    poohbar

    05/05/2017, 1:26 PM
    At the expense of sounding completely ignorant, why is not implicitly initializing the nullable properties a good thing?
    👍 2
    b
    • 2
    • 5
  • r

    rrader

    05/05/2017, 2:08 PM
    Kotlin’s design principle of making important things explicit
    than please make that all function have throws in function declaration like in Java
    ➕ 1
    b
    p
    +3
    • 6
    • 14
  • e

    elect

    05/11/2017, 9:33 AM
    I dont recall if I already asked this, but why `inner class`es cannot have `companion object`s?
    :stackoverflow: 3
    b
    • 2
    • 4
  • m

    miha-x64

    05/11/2017, 12:49 PM
    I propose adding underscore support for unused method parameters. Use-case is the same as for lambdas, e. g.
    object SomeDeserializer : com.google.gson.JsonDeserializer<Something> {
        override fun deserialize(json: JsonElement, _: Type?, _: JsonDeserializationContext?): Something {
            return Something(json.get("whatever").asString)
        }
    }
    r
    • 2
    • 1
  • i

    ilya.gorbunov

    05/13/2017, 8:29 PM
    Something like
    if ((val localVal = nullableExpr) != null && localVal.property = "x") {  do something with localVal }
    ?
    b
    • 2
    • 1
  • s

    Slackbot

    05/13/2017, 8:36 PM
    This message was deleted.
    b
    j
    • 3
    • 4
  • g

    groostav

    05/14/2017, 7:52 AM
    so, I'm starting to use sealed classes a lot, they're really handy, but it has come up twice now that I would like to access a sealed classes instances via reflection, but no such API exists. Any chance I could get some method support for retrieving the subclasses of a sealed type via reflection?
    k
    • 2
    • 1
  • d

    dimsuz

    05/18/2017, 4:50 PM
    what is the future of annotation processing in kotlin? will it be still as slow and use Java as an intermediate generation language? Will it be possible to generate kotlin directly somehow? Or will there be other machineries to allow some kind of metaprogramming? Maybe there are already some proposals related to this?
    l
    k
    • 3
    • 3
  • e

    edenman

    05/22/2017, 7:35 PM
    i filed a suggestion for Smart Cast, anybody got thoughts or feedback? https://youtrack.jetbrains.com/issue/KT-18023
    😱 1
    👎 7
    b
    k
    a
    • 4
    • 7
  • e

    elizarov

    05/23/2017, 5:35 PM
    @edenman What kind of vars are those? Why are they nullable? Have you tried using
    lateinit
    ? Can you share some code?
    ➕ 1
    e
    o
    • 3
    • 5
  • r

    Ruckus

    05/24/2017, 2:38 PM
    Escaping and string interpolation are two different things. Personally, I use interpolation in raw strings all the time (for example, when building complex regex patterns).
    👍 1
    e
    f
    • 3
    • 4
  • g

    groostav

    05/25/2017, 8:24 AM
    hah, heres a super awesome piece of code almost certainly created by a merge conflict:
    catch (exception: AssertionError) {
                <http://eventBus.post|eventBus.post>(ControlFlowInterruptedEvent())
                return optimizationModel?.id ?: NullUUID
            }
            catch (exception: AssertionError) {
                <http://eventBus.post|eventBus.post>(ControlFlowInterruptedEvent())
                return optimizationModel!!.id
            }
    Can ask the compiler to make this illegal? Would it ever be useful to catch the same type like this?
    👍 4
    m
    • 2
    • 1
  • n

    noctarius

    05/28/2017, 5:44 PM
    Did you guys think about “copy-constructors” for data classes? 😉
    ➕ 1
    b
    m
    p
    • 4
    • 15
Powered by Linen
Title
n

noctarius

05/28/2017, 5:44 PM
Did you guys think about “copy-constructors” for data classes? 😉
➕ 1
b

benleggiero

05/28/2017, 6:14 PM
Like this?
data class Foo(bar: Bar, baz: Baz) {
	fun copy (bar: Bar = this.bar.copy(), baz: Baz = this.baz.copy()) = Foo(bar, baz) 
}
n

noctarius

05/28/2017, 6:20 PM
something like this, yeah but it be more like
Foo(foo: Foo) => foo.copy()
you pretty much create a new clone but instead of calling clone you use a copy constructor
(especially in the future, with value types, that would be cool :D)
b

benleggiero

05/28/2017, 6:24 PM
ah, I see. As a much more generally powerful feature, I'd like to see "factory" constructors, which you can call like a normal constructor but don't behave like one. For instance:
class Foo(bar: Bar) {
    private val shared = Foo(bar = Bar())
    
    factory constructor() = if (condition) shared else Foo(Bar())
n

noctarius

05/28/2017, 6:26 PM
I think you could do this with companion object, can’t you?
but I guess you want the opposite of https://kotlinlang.org/docs/reference/multi-declarations.html 😄
constructing declarations 🙂
b

benleggiero

05/28/2017, 6:29 PM
Mostly I want to change
Foo.create()
to
Foo()
n

noctarius

05/28/2017, 6:30 PM
ohh ok, sorry took a moment 😄
m

miha-x64

05/28/2017, 9:07 PM
Are you guys looking for this? https://kotlinlang.org/docs/reference/data-classes.html#copying
b

benleggiero

05/29/2017, 10:19 PM
@miha-x64 not me personally 😛
p

Paul Woitaschek

05/30/2017, 6:44 AM
@benleggiero Then make it an operator fun called invoke
data class Sample(val string  : String) {
  
  companion object{
    
    operator fun invoke() = if(Random().nextBoolean()) Sample("bob") else Sample("alice")
  }
}

fun whatever(){
  val sample = Sample()
}
😍 1
b

benleggiero

05/31/2017, 11:35 PM
w-woah... I did not know this was possible. I'm gonna have to play with this.
😂 1
View count: 2