Evolution of a method

My understanding of the difference between getter method and getter property is the latter is the attribute of given type, something that you can just read. The former on the other hand is something you (painfully or not) compute.

It really annoyes me that in C# you have for example the method Count for IEnumerable (granted, as an extension) and you have Count property for such collection as List.

Let’s think in terms of refinement — when you have a method in your base type you can refine it in any derived type, but if at some stage you could guarantee no actual computation takes place you would be sending the wrong signal. Internally you have just a fetch operation, for the outer world you are still struggling with some number crunching. That is why Skila allows to refine a method as a property.

Dead simple:

interface Sequence<out T>
  // here we compute
  base def count() Int •••

class !Array<T> extends Sequence<T>
  // here we just read
  extends def count Int •••

And to make using properties as pleasant as possible Skila goes the opposite way than Scala — it is possible to call a property like a function but not the other way around:

let seq ~Int = [ 1, 2, 3 ];
_ = seq.count();
// invalid in Skila, valid in Scala
_ = seq.count; 

let coll [Int] = [ 1, 2, 3 ];
// both target the property
_ = coll.count(); // invalid in Scala
_ = coll.count; 
Tagged ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: