Recursive and ancestor calls

The problem with recursive calls is they look the same as regular calls to a function — i.e. you have to specify the name of the function and arguments. The obvious shortcoming is writing recursive lambda — in languages like C# you cannot do this. The second one looks trivial but distracts me — when I don’t have too elaborate function, let’s say 3­–5 lines, and I have to write another, very similar, one. Creating unified, more general, function for such short form is an overkill, so in all cases I remember I copy&paste the code changing important bits. But every time I do this, I have to pay special attention if I changed the recursive call — otherwise my program would be compiled without any error, yet this would introduce a bug into the code.

Skila forbids recursive calls by function name — you have to call “self” for recursive call. “self” does not mean “function(s) with this name”, it means “this function”.

This improves distinction when reading the code — if you see “self”, you know automatically there is recursion involved. If not — it is regular call. In the second case, the workflow could still be recursive (via cross calls), but checking this is out of scope of compiler (and there is no purpose anyway).

There is also another type of call with improved visual factor — a call to closest base method in class inheritance tree. When writing descendant “SayIt” method instead of using the name:

base.SayIt("hello world");

call “super”:

super("hello world");

and the “same” method will be invoked, but implemented in ancestor class.

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 )

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: