what naming convention do you use for generic type...
# announcements
t
what naming convention do you use for generic type parameters? The single letter names are often too confusing for me
k
#codingconventions, but personally if I really need multiletter names I go with all-caps, eg
MyClass<SELF: Myclass<SELF>>
.
m
I prefer to use
UpperCamelCase
for them as they reflect types. The name must reflect the purpose of the parameter. So Kotlin’s default `map`:
Copy code
fun <T, R> Iterable<T>.map(transform: (T) -> R): List<R>
I’d write as
Copy code
fun <Value, TransformedValue> Iterable<Value>.map(transform: (Value) -> TransformedValue): List<TransformedValue>
It’s clearly longer but I’ve learned from Swift that “Clarity is more important than brevity”. And that’s true! 🙂 (https://swift.org/documentation/api-design-guidelines/#clarity-over-brevity)
🙂 2