benleggiero
05/15/2018, 10:17 PMkarelpeeters
05/15/2018, 10:30 PMbenleggiero
05/15/2018, 10:36 PMvarargs
?” and I had no good solution so it was quickly droppedkarelpeeters
05/15/2018, 10:37 PMbenleggiero
05/16/2018, 3:16 AMfun Array<T>.insert(at index: Int) { /* ... */ }
but then they said that conflicts with
fun Array<T>.add(vararg elements: T) { /* ... */ }
So in that case vararg
looks like a label but should be considered a qualifier. I said we should move it to after the :
and before the T
, but they said something about that making types harder to distinguish… or something… It’s not very clear in my head. Someone mentioned some horrid syntax like this at some point and I gave up
fun Array<T>.insert(@ParameterLabel("at") index: Int) { /* ... */ }
rrader
05/16/2018, 6:24 AMrrader
05/16/2018, 6:30 AMadd(elements: ...T)
gildor
05/16/2018, 8:30 AMkarelpeeters
05/16/2018, 8:30 AMvararg
? Kotlin is stable, you can't just deprecate commonly used core language syntax.gildor
05/16/2018, 8:30 AMgildor
05/16/2018, 8:30 AMgildor
05/16/2018, 8:31 AMfun Array<T>.insert(at: Int) {
val index = at
/* ... */
}
gildor
05/16/2018, 8:31 AMrrader
05/16/2018, 8:44 AMDeprecateIt will work the same, no code breaks? Kotlin is stable, you can't just deprecate commonly used core language syntax.vararg
karelpeeters
05/16/2018, 8:48 AMgildor
05/16/2018, 9:26 AMat
variable instead of index
. Imo it’s too big change for such minor featurebenleggiero
05/18/2018, 5:23 PMConnection(destination="<http://google.com|google.com>", protocol=HTTP)
, you could have Connection(to="<http://google.com|google.com>", over=HTTP)
benleggiero
05/18/2018, 5:26 PM...T
looks like "a range of elements of type T, where the left end is open", or LeftOpenRange<T>
gildor
05/19/2018, 5:24 AMclass Connection(to: Uri, over: Protocol)
It’s completely your preferences about naming. I prefer protocol
than over
, but I’m not sure how label can solve naming problem for both of us.
The only difference that inside of the class you will have different name of the variable.
I understand that all those things about labels came from ObjC and then from Swift, but even Swift now closer to classical naming than to ObjC (but with support of labels, yeah).
I just think that such big syntax change with a lot of pitfalls about name resolution, conflict with vararg etc just don’t worth of this feature goals (different name for consumer and producer) and feature itself is very doubtful, at least I don’t see good use casesbenleggiero
05/20/2018, 4:51 PMto
and over
) makes it a worse experience for me as the API writer, at the sacrifice of making it a better experience for the API user.
Maybe a syntax like this would be unambiguous?
fun <T> ensure(that=badItem: T, vararg isNotIn=allItems: T) = !allItems.contains(badItem)
println(ensure(that = "Qux", isNotIn = "Foo", "Bar", "Baz") // true
println(ensure(that = "Bar", notIn = "Foo", "Bar", "Baz") // false
karelpeeters
05/20/2018, 5:19 PMval target = to
benleggiero
05/20/2018, 5:35 PMfun foo() = bar
syntax, but IDEA issues this warning:
Variable is an exact copy of another variable and can be inlined
This inspection reports local variables either used only in the very next return or exact copies of other variables. In both cases it's better to inline such a variable
gildor
05/21/2018, 3:21 AMworse experience for me as the API writerIt’s destiny of API writer to provide better experience for others and have worse one for yourself 😅
benleggiero
05/21/2018, 4:37 PMIt’s destiny of API writer to provide better experience for others and have worse one for yourself 😅Heh... True. But it can still be better
benleggiero
05/28/2018, 7:45 AMsortedWith(sorter)
and compareBy(comparator)
would look if they had explicit labels, like sorted(with= sorter)
or compare(by= comparator)
. Heck, maybe even list(of= foo, bar, baz)
!
(I think even nicer if we used :
here instead of =
but that might conflict with other planned features…)
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/sorted-with.html
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.comparisons/compare-by.htmlgildor
05/28/2018, 7:50 AM=
, also easier to find in autocompletegildor
05/28/2018, 7:51 AMinline fun <T> Iterable<T>.sorted(with: Comparator<in T>): List<T> {
return sortedWith(with)
}
Honestly, I don’t see any improvements of API, and even if such feature will be available all the API will use old style. it’s more about preferred style of naming rather than real language feature.benleggiero
05/28/2018, 8:12 AMgildor
05/28/2018, 8:13 AMSwift functions are clearer and more expressivethis is just your opinion
gildor
05/28/2018, 8:14 AMbenleggiero
05/28/2018, 5:41 PMmyList.add(1, 2)
will add 1
to myList
at index 2
, or 2
to myList
at index 1
, or add 1
and 2
to the end of myList
. It’s not my opinion that myList.add(1, atIndex: 2)
is more clear; that’s just a fact. Introducing more information where it’s necessary is a huge part of making things clear. Making that optional and separate from variable names makes that more expressive, encouraging API designers to use this kind of syntax instead of saying “yeah it’s possible if you use this workaround which makes you do more work in every function”.
Allowing required labels = clearer APIs = better understanding by API users = fewer bugs
Separating labels from variable names = easier to make more expressive APIs = more use of the aforementioned required labels = better use by API users = fewer bugs
These are not just feelings I have. These are rigorously-tested facts that caused the largest and most profitable tech company in the world to make the decisions they made.
Please, to understand where I’m coming from, watch this:
especially starting around 6 minutes invoddan
05/29/2018, 7:53 AMkarelpeeters
05/29/2018, 8:32 AMtschuchort
05/29/2018, 8:57 AMfun foo() =
syntax is valid, but imo this is a whole different problem beyond the scope of parameter labels. Instead there should be something like where
syntax in haskell to be able to declare local variables/functions in a declarative way without having to resort to {}
which is ugly and also prevents return type inferencebenleggiero
05/31/2018, 2:19 AMbenleggiero
05/31/2018, 2:22 AMbenleggiero
07/20/2018, 3:13 AM@param at
and @param with
just… they don’t read well at all.
Kotlin is, in general, a rather elegant language. I think it could use a more elegant solution to this problem