Ben Dodson
05/15/2019, 4:54 PM{{}}
instead of `{}`: chain.map{{ input -> /* capture throws a compiler error */ }}
littlelightcz
05/19/2019, 6:57 PMval foo = AtomicInteger(0)
foo++
Current increment
operator would allow me to work only with var foo
, but this is obviously not what I want. In my use case I want to launch N coroutines and show a progress bar with how many of them have already finished (tracked in the foo
AtomicInteger)Martin Devillers
05/21/2019, 12:52 PMMarc Knaup
05/30/2019, 3:35 PMvararg
parameter using vararg
keyword.
Reason: Make code easier to read & understand (one keyword in both locations), simplify language (no extra unary *
operator needed)
Esp. helpful for people who are new to Kotlin or have only rarely if ever use spread operators in other languages.
Example:
ByteString.of(*buffer.toByteArray())
->
ByteString.of(vararg buffer.toByteArray())
At the declaration-site vararg
denotes "variadic number of parameters".
At the call-site vararg
denotes "variadic number of arguments".Marc Knaup
06/06/2019, 3:28 PMdata class
a lot - but mostly for automatically generating toString()
and equals()
, sometimes hashCode()
, rarely `copy`().
I never care about componentX()
for destructuring but noticed that their existence can be confusing to people (and me changing the order of properties breaking their code).
The general idea of having less boilerplate for simple repetitive tasks / common idioms is good. It would be awesome if developers could express with more detail what auto-generated functionality is actually desired and which is not. This also makes the actual capabilities and the intended usage of a class clearer than using a data class
that adds functionality which may not always make sense.
I know that I may be misusing data classes here and I guess I'm not the only one using them to avoid manual and repetitive implementation of toString()
, equals()
and hashCode()
. In addition to having less boilerplate the compiler can generate well-optimized implementations which are even more work & code when done manually (think for example a good hashCode()
implementation over multiple properties without boxing or platform dependency à la Java's Objects.hashCode(…)
).
I like Swift's approach where a developer can for example state that a struct
is Equatable
or even Hashable
and if all properties are too then the implementation is auto-generated by the compiler. Kotlin could do the same to make adding these method simpler.
E.g. if I add : AutoEquatable
to a class the compiler could auto-generate equals()
for me over all properties - just like a data class and potentially using the same constraints as for these.
Same for AutoHashable
-> hashCode()
, AutoStringConvertible
(or alike) -> toString()
, AutoCopyable
-> copy()
and AutoDestructurable
-> componentX()
.
A data class
is automatically AutoEquatable
, AutoCopyable
, AutoDestructurable
, AutoHashable
and AutoStringConvertible
.
@gildor suggested to use annotations instead of interfaces, which is also a good option.
There would be no need to change the language itself. The Standard Library would merely add a few interfaces and the compiler use them for auto-generating some code.
Another alternative could be to use data classes but opt out to some of its functionality, e.g. data(nocopy, nocomponents) class …
. That would require syntax and language changes though.
What do you think? 🤔Quy D X Nguyen
06/08/2019, 2:27 AMHullaballoonatic
06/10/2019, 7:58 PM@AmbiguityDefault
operator fun Foo.plusAssign(other: Foo)
Hullaballoonatic
06/11/2019, 7:50 PMfun repeatReversed(times: Int, action: (Int) -> Unit)
in stdlib?Ruckus
06/13/2019, 8:50 PMinner object
On several instances I've come across a situation where I have code like:
class Parent {
val child: Child = Child()
inner class Child
}
Where it would be preferable to have:
class Parent {
inner object Child
}
The main advantage I'm looking for (other than readability) is locality:
- Every Parent
has in instance of Child
- Child
is a well defined type
- You cannot create new instances of Child
with something like parent.Child()
Hullaballoonatic
06/14/2019, 9:41 PMtry {
...
} catch { e ->
...
}
try foo() catch { bar(it) }
try foo() catch bar()
or as @Marc Knaup suggested:
try foo() else bar()
instead of catch
in the event you are ignoring the throwableHullaballoonatic
06/15/2019, 11:27 PMimport foo.Foo
@innerOf(Foo)
inner class Bar
import foo.Foo
@innerOf(Foo.Bar)
fun bar() = "blah"
The same may then be extended to sealed classeswickedev
06/16/2019, 2:10 PM<SemanticsComponentNode
container
explicitChildNodes
enabled
checked
selected
button
header=null
textField=null
focused=null
inMutuallyExclusiveGroup
obscured=null
scopesRoute=null
namesRoute=null
hidden
label
value
hint=null
textDirection
testTag=(testTag ?: providedTestTag)
actions>
TestTag(tag=DefaultTestTag) {
children()
}
</SemanticsComponentNode>
https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/ui/framework/src/main/java/androidx/ui/core/Semantics.kt#130Nicole
06/19/2019, 12:43 AMdata class Component(val active: Boolean) {
val getList get() = listOf("empty")
val isPoorlyNamed get() = 10
val isCorrectlyNamed get() = true
}
JVM code:
Component component = new Component(false);
component.getActive();
component.getGetList();
component.isPoorlyNamed();
component.isCorrectlyNamed();
Proposal: To better match Java Bean naming conventions:
val active
-> boolean isActive()
- Boolean return maps to “isProperty”
val getList
-> List<String> getList()
- Already prefixed with “get” -> leave it
val isPoorlyNamed
-> int getIsPoorlyNamed()
- Prefixed with “is”, but isn’t a boolean -> add “get” prefix
val isCorrectlyNamed
-> boolean isCorrectlyNamed()
- Same as todayjdemeulenaere
06/20/2019, 11:12 AMHullaballoonatic
06/20/2019, 6:38 PMAlexander Vtyurin
06/26/2019, 7:27 PMsuspendCancelableCoroutine
a part of the language instead of suspendCoroutine
as a more general and tweakable language unit.Hullaballoonatic
07/02/2019, 9:52 PMwhere
syntax
current:
class Foo<A, B>(val a: A, val b: B) where A: Bar, A: Baz
proposed:
class Foo<A: Bar & Baz, B>(val a: A, val b: B)
not like &
is getting any use in Kotlin anyhow...Hullaballoonatic
07/02/2019, 10:07 PMinterface Bar {
val bar: Int
companion object {
operator fun invoke(bar: Int) = object : Bar {
override val bar = bar
}
}
}
interface Baz {
...same as how Bar is implemented
}
class Foo(bar: Int, baz: Int): Bar by Bar(bar), Baz by Baz(baz)
but wouldn't it be nice to just:
class Foo(bar: Int, baz: Int): Bar(bar), Baz(baz)
Hullaballoonatic
07/03/2019, 12:22 AMby
, is
, or something like that
current:
var foo = 3
var bar
get() = foo
set(v) {
foo = v
}
proposed:
var foo = 3
var bar by foo
diego-gomez-olvera
07/08/2019, 10:36 AMvararg
and 0 arguments, a new Object[0]
is allocated every time, according to the decompiled code
https://youtrack.jetbrains.com/issue/KT-32474Ruckus
07/12/2019, 2:39 PMval thing = Thing().apply { setup(...) }
. While this is simple enough, I do it so often it would be nice to have an operator for it, that calls the function, but ignored the return value and returns the receiver instead, so I could do something like val thing = Thing()&.setup(...)
This may just be to my style of programming, but I figured I'd throw it out there to see if anyone else is interested.Hullaballoonatic
07/12/2019, 8:21 PMfoo if (condition)
syntax, like exists in Ruby and other languages. It is superior to if (condition) foo
in that it doesn't allow for multiline, and avoids the problem of:
if (foo)
bar
baz // not in scope
Also maybe drop the condition's enclosing ()
jdemeulenaere
07/18/2019, 3:19 PMSlackbot
07/19/2019, 6:23 PMMuneebshere
08/08/2019, 10:49 AMFudge
08/11/2019, 8:17 AM// Inferred as x: String, y: Int = 2, z : String = "hello"
fun foo(x : String, y = 2, z = "hello"){
}
david-wg2
08/13/2019, 9:48 AMif (pin?.length != 36) throw Exception()
// pin is smart cast here
if (pin?.length !in (8..36)) throw Exception()
// pin is not smart cast here
elect
08/15/2019, 9:05 AMvar hovered = false
var held = false
if(..) {
val (_, ho, he) = buttonBehavior(columnHitRect, columnId)
hovered = ho
held = he
}
Elijah Verdoorn
08/20/2019, 7:01 PMsuper
. For example:
override fun onDestroy() {
super.onDestroy()
channel.close()
}
could become
super fun onDestroy() = channel.close()
The override
word becomes optional, since the call to super
only makes sense in the context of functions that are being overridden.themarketka
08/22/2019, 10:44 PM.trimMargin()
as `const`s – any chance it would get done in some reasonably near future? I’d offer myself to implement a PR for the compiler if only I had better understanding of it. :kotlin-flag:🐿🎄themarketka
08/22/2019, 10:44 PM.trimMargin()
as `const`s – any chance it would get done in some reasonably near future? I’d offer myself to implement a PR for the compiler if only I had better understanding of it. :kotlin-flag:🐿🎄Ruckus
08/23/2019, 1:36 PMAll discussion in this channel should begin with a use-case or proposal instead of a question.This isn't the channel to ask about progress on issues.