https://kotlinlang.org logo
Docs
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
  • j

    jtravis

    09/19/2018, 7:50 PM
    Are there any current proposals regarding introspection of string templates? I’m looking through the KEEPs and not seeing any.
    g
    k
    • 3
    • 3
  • a

    artem_zin

    09/24/2018, 4:34 AM
    Hey guys, do you think you have time to change
    Result
    (also known as
    SuccessOrError
    ) type before 1.3 release? I think it can be improved and you might want it to be improved for the future of language, I’m writing a KEEP but it takes a long time so I wanted to reach out so you know it’s coming
    e
    g
    +6
    • 9
    • 40
  • h

    holgerbrandl

    09/24/2018, 8:08 AM
    Hi there, is there a ticket/KEPP about supporting local enums, that is enums which are defined in a function body? I think this would be pretty handy e.g. when writing api examples (like with dokka).
    r
    d
    • 3
    • 6
  • f

    Fleshgrinder

    09/24/2018, 5:33 PM
    I would love to see these extension function in the core for Kotlin JVM. Not sure how to go about that. Should one create a KEEP for discussion, even if it something simple like this, or simply go ahead and create a PR?
    Serializable.kt
    k
    r
    • 3
    • 4
  • a

    adam-mcneilly

    09/25/2018, 6:18 PM
    I'm sure it's a pretty common request to have
    when
    statement support multiple conditions for the else block, does anyone know if there's an official feature request or discussion around this?
    when (x) {
      1, 2 -> println ("one or two")
      3, else -> printlnt("doesn't compile")
    }
    ➕ 2
    k
    a
    +3
    • 6
    • 21
  • v

    voddan

    09/26/2018, 5:00 AM
    🔔 We have formed a new KEEP on class delegation and we are looking for feedback (and a sheppard)! @Dico is the author: https://github.com/Kotlin/KEEP/pull/154
    👍🏻 1
    😁 1
    o
    d
    • 3
    • 8
  • l

    LeoColman

    09/27/2018, 6:52 PM
    Hey guys! Would it be valit for STDLib to contain an extension function such as
    Int.length
    , that counts how many numbers are in an Integer?
    t
    d
    +3
    • 6
    • 6
  • j

    jkbbwr

    10/05/2018, 11:50 PM
    I wonder about
    data class
    is that basically designed as a compiler plugin? if so would there be a way to extend this in the future to add user defined (with compiler plugin)
    r
    • 2
    • 3
  • m

    Marc Knaup

    10/08/2018, 2:32 PM
    Is there any news on whether we'll get default arguments for generic parameters? 🙂 à la
    class Something<Context = DefaultContext>
    ->
    val something: Something
    🤔 1
    ➕ 3
    d
    k
    +3
    • 6
    • 12
  • n

    natpryce

    10/10/2018, 7:50 AM
    I’ve found an unusual edge case:
    object foo {
        operator fun invoke() {
            println("an object")
        }
    }
    
    fun foo() {
        println("a function")
    }
    
    
    fun main(args: Array<String>) {
        foo() // prints "a function"
    }
    l
    c
    +6
    • 9
    • 55
  • r

    Ruckus

    10/12/2018, 5:19 PM
    Now that
    main
    can be suspended in 1.3, I propose an all-suspend plugin that would make all functions
    suspend
    functions (along the same lines of the all-open plugin), allowing a Go style of programming without having to mark each function as suspended. (Note: I know next to nothing about Go, so I could be way off in my comparison. I'm also not sure of the implications of this idea, so I haven't even decided if I like it myself, but I figured I'd throw it out there.)
    👍🏼 1
    👎 4
    l
    g
    j
    • 4
    • 3
  • c

    cbruegg

    10/12/2018, 5:25 PM
    I suppose this would not work well with Java-interop and stdlib functions that don't accept suspending functions as parameters.
    r
    g
    • 3
    • 3
  • e

    elect

    10/15/2018, 4:17 PM
    I'd be very interested into some sort of solution to automatically infeer a field order for reflection
    🤔 1
    a
    u
    • 3
    • 5
  • e

    elect

    10/24/2018, 8:18 AM
    small feature requests, no more commas on multiline primary constructor parameters: https://youtrack.jetbrains.com/issue/KT-27785
    👍 1
    g
    v
    • 3
    • 5
  • v

    Vladyslav Sitalo

    10/24/2018, 1:35 PM
    is there somewhere a write up/discussion about the decision to make the
    dynamic
    type available only on the js platform? From what I’m reading for now it seems to be that it was not supposed to be like that initially (i.e. here: https://discuss.kotlinlang.org/t/dynamic-type/1145)
    :trollface: 3
    🚫 2
    😱 1
    👨‍💻 1
    🙈 2
    k
    e
    d
    • 4
    • 9
  • l

    louiscad

    10/25/2018, 10:17 AM
    Hi, I think I actually found a use case for the
    dynamic
    behavior during prototyping/development: allow unresolved symbols after
    TODO(…)
    calls. I created an issue: https://youtrack.jetbrains.com/issue/KT-27818
    👍 2
    t
    e
    • 3
    • 9
  • a

    addamsson

    10/26/2018, 11:56 AM
    @orangy I'm not a language designer yet 😞
    :thread-please: 1
    o
    • 2
    • 2
  • n

    natpryce

    10/30/2018, 8:34 AM
    I was wondering… is there a reason that Kotlin doesn’t support reified generic parameters on classes? I frequently find myself wanting it.
    l
    k
    +4
    • 7
    • 22
  • e

    elect

    10/30/2018, 1:01 PM
    what about changing the
    -
    to
    _
    in order to allow calling function with inline classes from java? https://kotlinlang.org/docs/reference/inline-classes.html#mangling
    o
    e
    d
    • 4
    • 6
  • k

    karelpeeters

    10/30/2018, 1:25 PM
    Huh? They are mangled? Than what's the point of restricting inline classes to not have constructors? I thought the argument was that Java interop could always work around them.
    g
    a
    • 3
    • 9
  • k

    karelpeeters

    11/02/2018, 10:25 AM
    for (i in 0 until 10 step 2) {
        println(i)
    }
    This code is only partially optimized, there is still an allocation of both an
    IntRange
    and an
    IntProgression
    . This get worse when this loop is part of another loop, that means two useless allocations per iteration of the outer loop. Are there plans to optimize all of that away?
    g
    l
    +2
    • 5
    • 10
  • d

    Dominaezzz

    11/02/2018, 11:44 AM
    I have a vague idea, macro functions (and maybe classes). Where a function is marked with a keyword
    macro
    and like inline functions, will support "reified" generics and cannot be called outside of Kotlin (i.e Java), but instead of being inlined at the call site, they are generated and called. (Like templates in C++). Any reflection done in the function is inlined. This allows for IDE friendly templates(C++), easy code generation and maybe something similar to LINQ to SQL.
    g
    k
    d
    • 4
    • 4
  • d

    Dico

    11/02/2018, 4:10 PM
    @louiscad https://github.com/Kotlin/KEEP/issues/155 Try getting the keep a shepherd
    l
    • 2
    • 1
  • l

    louiscad

    11/03/2018, 1:17 AM
    You could be able to access this, but all the fields not defined as constructor parameters would be non accessible (marked as not initialized yet), unless it's from a lambda (like the one in
    lazy { … }
    )
    d
    • 2
    • 15
  • a

    addamsson

    11/06/2018, 3:33 PM
    What !? 😄
    r
    a
    +4
    • 7
    • 16
  • a

    aarjav

    11/12/2018, 9:38 PM
    when to comment on an issue vs pull request in KEEP repo?
    g
    • 2
    • 2
  • s

    sksk

    11/13/2018, 11:09 AM
    Proposal: Generics new constraint
    data class CPosition(var x: Int, var y: Int)
    
    fun main(args: Array<String>)
    {
        addComponent<CPosition>().apply {
            x = 5
            y = 5
        }
    }
    
    
    fun <T : new> addComponent(): T
    {
        // create an instance of T
        val c = T()
        
        // do stuff with c
        
        return c
    }
    m
    k
    +7
    • 10
    • 16
  • p

    pablisco

    11/20/2018, 11:48 AM
    Just so I don't create duplicates, has there been discussions about having different type exposed by a getter? Example:
    val items = mutableListOf<Item>()
      get() : List<Items>
    • 1
    • 1
  • z

    zak.taccardi

    11/24/2018, 8:40 PM
    has there been a proposal to allow us to use a
    typealias
    as a namespace?
    typealias MainViewModel = ViewModel<State>
    Then I’d like to have classes defined as:
    MainViewModel.State
    ➕ 2
    b
    • 2
    • 3
  • m

    marcusfs

    11/28/2018, 3:10 PM
    i don't know if this has been discussed in the past, but it'd be really nice if there was an enum-style shorthand for sealed data classes. basically so you can do something like this:
    sealed data class Foo {
        First,
        Second(val x: Int),
        Third(val s: String)
    }
    instead of this:
    sealed class Foo {
        object First : Foo()
        data class Second(val x: Int) : Foo()
        data class Third(val s: String) : Foo()
    }
    it's not a huge difference but it feels unnecessarily messy to do it the current way (especially when you mix in "no argument" data classes and have to use object/class instead) , and I imagine this is a pretty common use-case for sealed classes. what do you think?
    👍 3
    👎 6
    o
    k
    +3
    • 6
    • 60
Powered by Linen
Title
m

marcusfs

11/28/2018, 3:10 PM
i don't know if this has been discussed in the past, but it'd be really nice if there was an enum-style shorthand for sealed data classes. basically so you can do something like this:
sealed data class Foo {
    First,
    Second(val x: Int),
    Third(val s: String)
}
instead of this:
sealed class Foo {
    object First : Foo()
    data class Second(val x: Int) : Foo()
    data class Third(val s: String) : Foo()
}
it's not a huge difference but it feels unnecessarily messy to do it the current way (especially when you mix in "no argument" data classes and have to use object/class instead) , and I imagine this is a pretty common use-case for sealed classes. what do you think?
👍 3
👎 6
o

orangy

11/28/2018, 3:14 PM
It cannot be
enum
, all enum values are singletons.
m

marcusfs

11/28/2018, 3:20 PM
well yes it can't be a java enum, but it can be inner classes with a hidden constructor (so like sealed classes). or did you mean there is something conceptually in the language, or practical in the compiler that prevents the keyword from being used?
o

orangy

11/28/2018, 3:21 PM
enum is enum 🙂 it has
values
,
valueOf
, etc, that assumes all variants are singletons. Using same word for something that is significantly different is very confusing.
m

marcusfs

11/28/2018, 3:23 PM
fair enough 🙂 either way i think it'd be useful with a shorthand for algebraic data types like this
o

orangy

11/28/2018, 3:23 PM
enum
comes from the fact that all values are
enumerable
, after all.
m

marcusfs

11/28/2018, 3:24 PM
that's true - in this case you would only be able to enumerate the constructors
o

orangy

11/28/2018, 3:24 PM
so what’s wrong with sealed classes as they are?
having to write some
:Foo()
and
data class
?
m

marcusfs

11/28/2018, 3:25 PM
it's not that it's wrong, it just seems like a common use-case is unnecessarily messy
yes, and sometimes
object
if you don't have any arguments to a case
(or
class
i guess)
o

orangy

11/28/2018, 3:25 PM
It may be wordy, but I don’t think it’s messy. It states pretty explicitly what is what
m

marcusfs

11/28/2018, 3:29 PM
i guess it's a matter of taste to some extent, but especially that you have to jump between using object and data class makes the code align really poorly which doesn't help readability
and it can get quite noisy as well. here's a more practical example from an android app:
sealed class AddEditTaskEvent {
    data class DefinitionCompleted(val title: String, val description: String) : AddEditTaskEvent()
    object CreatedSuccessfully : AddEditTaskEvent()
    data class CreationFailed(val reason: String) : AddEditTaskEvent()
    object UpdatedSuccessfully : AddEditTaskEvent()
    data class UpdateFailed(val reason: String) : AddEditTaskEvent()
}
versus
enum data class AddEditTaskEvent {
    DefinitionCompleted(val title: String, val description: String),
    CreatedSuccessfully,
    CreationFailed(val reason: String),
    UpdatedSuccessfully,
    UpdateFailed(val reason: String)
}
o

orangy

11/28/2018, 3:38 PM
I agree with an idea that it could look better in specific cases. I don’t think
enum
is appropriate shortcut here.
As a side note you’d probably have a kdoc before each of the variants, no? 😉
m

marcusfs

11/28/2018, 3:39 PM
i'm not so attached to the name, it's really the shorthand i care about
it really depends tbh but i hear what you're saying 🙂 with functional patterns types can work quite well as documentation though, and documentation that type-checks has better longevity than comments 😉
k

karelpeeters

11/28/2018, 11:30 PM
(FYI: this exact concept is called
enum
in rust, which misses the JVM concept of enum entirely)
g

gildor

11/29/2018, 3:12 AM
One more problem with this approach, that now you have choice: use nested classes or don’t, for example your code snippet can looks as:
sealed class AddEditTaskEvent
data class DefinitionCompleted(val title: String, val description: String) : AddEditTaskEvent()
object CreatedSuccessfully : AddEditTaskEvent()
data class CreationFailed(val reason: String) : AddEditTaskEvent()
object UpdatedSuccessfully : AddEditTaskEvent()
data class UpdateFailed(val reason: String) : AddEditTaskEvent()
And used as:
CreationFailed("reason)
instead of
AddEditTaskEvent.CreationFailed
But with implicit sealed class you don’t have such choice.
m

marcusfs

11/29/2018, 9:17 AM
well, you can always import them explicitly - this isn't different from how enums work
g

gildor

11/29/2018, 9:20 AM
you can import explicitly, sure, but it’s all about naming. By default will be used full name, because sometimes it makes a lot of sense for naming. Like
Event.Success
vs
SuccessEvent
, you don’t want to have
Event.SuccessEvent
, I just pointed that this proposal doesn’t work well with non-nested classes
m

marcusfs

11/29/2018, 9:20 AM
btw for the record swifts
enum
(or enum-with-associated-data as they refer to it) works like rust too. one really frustrating thing about their enum though is that the cases aren't subtypes of the enum type - in fact they are not even types at all and you can only access them using pattern matching.
@gildor ah, yes that's true. i don't think this would be useful for every use-case though, just the case where you are using sealed data classes as an algebraic data type. for example the equivalent in other languages would be: Swift
enum Foo {
    case First
    case Second(Int)
    case Third(String)
}
Rust
enum Foo {
    First,
    Second(int),
    Third(String)
}
Haskell
data Foo = First | Second Int | Third String
sealed data classes already have the right semantics for this, it's just that i think the syntax when declaring it is a bit verbose, as i stated above
g

gildor

11/29/2018, 9:35 AM
See, version of Haskell is exactly what I’m talking about. It’s
First
, not
Foo.First
. i don’t think this would be useful for every use-case
That’s the problem, you suggest new language feature and new syntax, which is big change itself, so should work for so many cases as it possible Maybe there are some other ways to avoid additional verbosity, but now it’s pretty limited, for example you also want to have constructor properties for parent sealed class, but this syntax doesn’t allow that
m

marcusfs

11/29/2018, 9:44 AM
honestly i would like this to be more of an extension/shorthand to existing language features rather than a completely new one. isn't there already precedent where language features work as shorthand for other features but don't support every possible scenario? i'm thinking of things like interface delegation being shorthand for implementing interfaces yourself (delegation is less verbose but also a strictly less powerful way to do it)
g

gildor

11/29/2018, 9:46 AM
class delegation is definitely a bad example of well designed feature and Kotlin team and Andrey Breslav many times mentioned this
m

marcusfs

11/29/2018, 9:47 AM
fair enough, it was just the first thing that came to mind
g

gildor

11/29/2018, 9:47 AM
but even in case of delegation it’s potentianlly removes much more boilerplate than this proposal (which is very limited)
m

marcusfs

11/29/2018, 9:48 AM
but do you think the idea of having a shorthand for this is a fundamentally flawed idea for kotlin, or is it more about my specific proposal?
g

gildor

11/29/2018, 9:49 AM
I would like to write less code for sealed classes, but I don’t have any good solutions which are flexible enough and play nicely with existing code.
and I think proposed solution is too limited to be a part of the language: enum keyword is misused, what about not nested classes, how to share properties
if use case is only for simplest cases (like Foo above), than I don’t see big advantages, it actually creates a new syntax for one particular use case of existing feature
m

marcusfs

11/29/2018, 9:57 AM
if it is a common use-case i don't see why it would be a bad idea to provide shorthand? just like
data class
is shorthand for a specific kind of
class
(namely a product type), i'd really like to see something like a
sealed data class
as a complement for supporting sum types.
g

gildor

11/29/2018, 10:00 AM
because data class saves a lot of typing
this one saves one constructor call without arguments
also has completely new semantics about classes, data classes and object
m

marcusfs

11/29/2018, 10:01 AM
plus mixed `object`/`data class` prefixes
g

gildor

11/29/2018, 10:01 AM
yes, and this is what I mean about new semantics, sorry bad word for this probably
what if you need just a class?
, i’d really like to see something like a
sealed data class
this actually interesting addition, maybe this makes more sense, because doesn’t clash with existing implementation
m

marcusfs

11/29/2018, 10:06 AM
that is the concept i'm trying to describe 🙂
g

gildor

11/29/2018, 10:06 AM
original proposal was about
enum
m

marcusfs

11/29/2018, 10:06 AM
it was in my original message but i updated the code now to also reflect it
sorry about that
o

orangy

11/29/2018, 10:08 AM
sealed data class
clashes with existing meaning. E.g. if you have
inner class
and you make it
inner data class
it doesn’t change syntax that radically
(again, I’m not against the idea itself, I just discard some syntactic ideas based on experience in this language design)
👍 2
m

marcusfs

11/29/2018, 10:09 AM
i really appreciate the feedback!
o

orangy

11/29/2018, 10:13 AM
Also note, that since each item is still a class, it can have a body (with functions, overrides, etc). So syntax should either accomodate for it (and make it non-ambiguous to parse), or disallow it in the short form.
m

marcusfs

11/29/2018, 10:13 AM
yes, that is true
even enums allow bodies after all
g

gildor

11/29/2018, 10:24 AM
even enums allow bodies after all
But the same body for each item, which may be too restrictive for sealed class (because each item has own types in constructor, so probably want to have own methods)
m

marcusfs

11/29/2018, 10:25 AM
yes, i agree
d

Dico

11/29/2018, 10:26 AM
So the thing he's proposing is enum-like syntax for a concept dubbed
sealed data class
. Body of the parent class can follow the
;
just like in enum class (even if I'm not personally a fan of that syntax)
The only thing that remains is how the parent constructor is called - in
enum class
you call the parent constructor instead of declaring a new one
Very interesting idea but it definitely needs to be approached critically. Come up with a design that has answers to points of critique.
m

marcusfs

11/29/2018, 10:35 AM
absolutely - this kind of feedback is precisely what i was looking for when bringing it up
l

louiscad

11/29/2018, 9:20 PM
Enum cases can have different classes as each case can have a body, so they're not so different from one level hierarchy nested sealed classes.
g

gildor

11/30/2018, 1:05 AM
Ah, yes, sure
View count: 2