Call by the what now?

Some not work related computery bits and pieces have been percolating around my head for some time now. I think we should talk about them for a while. That is: I’ll talk. You listen.

I’m probably going to write a couple of more techy blogs, all loosely interrelated. I am going somewhere with them, but I’m not entirely certain as to how much of this journey I will share with you.

First of all, I’m going to talk about the fairly simple computer related concept of “Call by reference” versus “Call by value”. This is fairly basic computer science (though I wish they’d taught it properly earlier on in my course). It’s possible (probable, even) that this example (or variations of it) has been used a thousand times before. I’m not going to go look for one (or the absence of one), I’m just going to write down my own particular take on it. I assure you that any plagiarism I’m about to commit is in no way deliberate. So, without further ado…

Let’s say you want to send a specific piece of information to someone via email. Let’s say it’s part of today’s featured article on Wikipedia (William I of Orange, at the time of writing). In today’s connected digital world, you have too main options. First of all, you could send them the information itself, like so:

William was born in the castle of Dillenburg in Nassau, present-day Germany. He was the eldest son of William, Count of Nassau and Juliana of Stolberg-Werningerode, and was raised a Lutheran. He had four younger brothers and seven younger sisters: John, Hermanna, LouisMary, Anna, Elisabeth, Katharine, Juliane, Magdalene, Adolf and Henry.

There are several things your recipient can do with this. They can read it. They can edit it, but this will only edit their local copy. The original remains unchanged. If they want to request that a change be made, they can, however, edit it and send it back to you. This is “calling by value.”

Your second option is to send them a link to the information:

This, again, allows them to read it. They have to follow the link to the information it points to first, though. This time, if they make an edit (this being wikipedia) they actually are changing the original copy. They can also see what other information is around it, and if they feel so inclined they can change that is well. You might consider this to be an undesirable consequence. This method has the aditional advantage, however, that you did not have to take the time and effort to make a copy, and the amount of information you had to actually send is significantly smaller. This is “calling by reference.”

If you deal with this sort of thing on a day to day basis, you may well be aware that when you do this sort of thing in a computer program you have another option. You can send a constant reference, which would be analagious to sending a link to a website the recipient has no write access to. For example:


, ,

  1. #1 by Dougal on February 25, 2009 - 2:53 pm

    You forgot call-by-need!

    And actually the browser example is closer to call by need. If the person you send the link to never clicks on it (ie, the function argument is not evaluated) then no resources are used by the caller (the browser) or the callee (the server) to evaluate it.

    I suppose that would make call-by-reference analogous to the “eager” browsers that will attempt to precache all the links on a page in order to speed up response times when you finally click a link. It also plays merry hell with server load and your download allowance, I bet.

  2. #2 by harveynick on February 26, 2009 - 10:45 pm

    Ah hah, but my example was not the browser, it was the emailing of the link. I’ve never knowingly come across “call by need”. How is that difference to calling by reference, but never actually evaluating the reference?

  3. #3 by Dougal Stanton on February 26, 2009 - 11:58 pm

    Call by reference is still strictly evaluated. If the argument doesn’t terminate then neither will the function that it’s applied to.

    Call by need is a non-strict evaluation strategy. foo(3/0) may terminate if foo() never evaluates its argument. This wouldn’t be the case with a strict strategy.

  4. #4 by Dougal Stanton on February 26, 2009 - 11:59 pm

    Also I still think the browser example is pertinent — the link/quote describes how the data is sent, but not the order of evaluation.

  1. Looking Out To Sea » Time for an argument

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: