Twin methods

One of the patterns you can see in many languages are paired methods — modify itself, and the other one — create new instance and modify it. For example, it could be the case of any sequence:

// modify itself
def !reverse()
  •••
end

// return the modified version
def reverse() 'Self
  let clone = this.copy();
  clone!reverse();
  return clone;
end

The body of the first method of course varies, but the second one is always the same and there is no point in writing it manually. In Skila you write the first method and you will get the second one automatically.

Advertisement
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 )

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: