Ruckus
10/19/2022, 4:05 PMRobert Williams
10/19/2022, 4:25 PMOliver.O
10/19/2022, 4:50 PMRuckus
10/19/2022, 5:45 PMRuckus
10/19/2022, 5:52 PMtransform()
) and the mutable to append a phrase (e.g. transformInPlace()
).Oliver.O
10/19/2022, 5:52 PMLandry Norris
10/19/2022, 5:53 PMRuckus
10/19/2022, 5:54 PMLandry Norris
10/19/2022, 5:54 PMval array = loadData()
array.sorted()
useArray(array)
Oliver.O
10/19/2022, 5:54 PMRuckus
10/19/2022, 5:55 PMLandry Norris
10/19/2022, 5:55 PMLandry Norris
10/19/2022, 5:57 PMOliver.O
10/19/2022, 5:57 PMOliver.O
10/19/2022, 5:58 PMLandry Norris
10/19/2022, 5:58 PMLandry Norris
10/19/2022, 5:59 PMOliver.O
10/19/2022, 5:59 PMRuckus
10/19/2022, 6:03 PMtoShuffled()
vs shuffleInPlace()
, but that's just ugly.Landry Norris
10/19/2022, 6:03 PMOliver.O
10/19/2022, 6:04 PMbut it definitely isn't universal.Life is too short to wait for such a thing as a universal opinion. Someone will always disagree.
Ruckus
10/19/2022, 6:04 PMmap
and filter
.Ruckus
10/19/2022, 6:04 PMOliver.O
10/19/2022, 6:05 PMOliver.O
10/19/2022, 6:10 PMThe name of a method is usually a verb or a verb phrase saying what the method _does_:,close
. The name should also suggest if the method is mutating the object or returning a new one. For instancereadPersons
is sorting a collection in place, whilesort
is returning a sorted copy of the collection.sorted
Landry Norris
10/19/2022, 6:13 PMOliver.O
10/19/2022, 6:18 PMmyList.*shuffle*()
vs. myList.shuffled()
?
(Assuming that object mutation is the more dangerous option.)streetsofboston
10/19/2022, 7:35 PMshuffle()
returning a Collection/List and shuffleItems()
returning a Unit, shuffling the items in place?Landry Norris
10/19/2022, 8:01 PMshuffleItems()
returning a Collection/List and shuffle()
returning a Unit, shuffling the items in place?Oliver.O
10/19/2022, 8:06 PMshuffleItems
is really a more specific term of shuffle
. It's like using synonyms for two things and then re-interpreting language to differentiate. Does not really work once you omit the explanation.Landry Norris
10/19/2022, 8:07 PMOliver.O
10/19/2022, 8:12 PMlouiscad
10/20/2022, 12:19 AMwithWhatever
or withXxxxWhatever*ed*
when whatever*ed*
isn't explicit enough or reads not right.Youssef Shoaib [MOD]
10/20/2022, 10:26 AM@CheckResult
annotation, or automatically warning about unused results and having a way to signal a discardable result. Seems like it's being worked on though KT-12719ephemient
10/23/2022, 1:59 AMarr.shuffle!
mutates arr
in-place
arr.shuffle
returns a new arrayephemient
10/23/2022, 1:59 AMephemient
10/23/2022, 2:07 AM.sort()
and I think it's an overall strength that Kotlin doesn't change much thereephemient
10/23/2022, 2:09 AM.sorted()
would have been more visually distinct from .sort()
if had been named .toSortedList()
, with the bonus of indicating the return type as well, which isn't obvious from the current name, but that seems too verbose for what should be the default when working with immutable dataOliver.O
10/23/2022, 9:43 PM.toSortedList()
is certainly more visually distinct, ambiguity remains: Applied to a list, it could be interpreted as "mutate that list into its sorted form".
with the bonus of indicating the return typeHeading back towards the dark ages of Hungarian Notation? 👻 For example, if the return type is a set or a list does not matter if I'm just iterating over it, so why enforce its indication? What I find particularly attractive in Kotlin is type safety without ceremony. That way, code can effectively communicate ideas without distractions by technical clutter. Regarding the best amount of visual distinction, I'd prefer not to merely speculate, but do trials and gather some hard empirical data on what really works and what doesn't.
ephemient
10/23/2022, 9:45 PM.toFoo()
returns a new copy in a given representation, e.g. .toList()
, .toSet()
, and even .toSortedSet()
Oliver.O
10/23/2022, 9:57 PM.toString()
. As long as there's a type change involved, these are somewhat OK. But they are ambiguous at least in some contexts, they have to be learned, and are not necessarily applied consistently. I'd have preferred .asList()
. For me, the entire question is more future-oriented: What would be the best naming strategy, starting now? And then think about where it is better to stick to (weaker) conventions, because the downside of abandoning them seems to huge.ephemient
10/23/2022, 9:58 PM.toList()
ephemient
10/23/2022, 9:59 PM