Named parameters

Consider such code:

var uri = new Uri("", true);

Could you tell me what this true stands for? Inside the function it is clear, because you work with parameter, not value, but on the outside it is not obvious.

When I write the function in C# which takes boolean I always face moral dilemma — write quickly and go with raw boolean, or pollute code with short-lived enum with two values True and False (reminder: in C# you have to use enum type name and value, not just enum value) making any call self explanatory.

The problem is solved in Skila — not only you can use parameter names when calling function, but you can define function with constraint on giving the name. Having Uri class in Skila:

class Uri
  Uri(address : String,named dontEscape : Bool) = ...

your minimal choice for call is:

var uri = new Uri("", 
                  dontEscape: true);
Tagged ,

Leave a Reply

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

You are commenting using your 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: