is there some heuristic whereby it makes sense tha...
# getting-started
j
is there some heuristic whereby it makes sense that collections.last() is a function but size is a property?
e
j
thanks!
e
I think there are some parts of stdlib where it's arguably inconsistent - e.g.
isEmpty()
- but lots of parts of Kotlin pre-date the modern style document
2
y
I was attempting to justify in my mind why
isEmpty
would be a method, but nope I can't find any reason. It doesn't do any expensive or long computation in the case of normal collections (just a size check) or Iterables/Sequences (just a
hasNext
) check. Sure, hasNext theoretically could be "expensive", but I don't think that justifies it. ... wait, why isn't hasNext a property? 🤦
e
arguably,
hasNext()
can be expensive, e.g.
Copy code
generateSequence(2.toBigInteger()) { it.nextProbablePrime() }.iterator().hasNext()
but that doesn't apply to
isEmpty()
since that's a method on
Collection
and other types with a
size