Fabulous Adventures In Coding

Eric Lippert's Blog

Use your legs, not your back

In C# you can "lift", "raise" and "hoist", and they all mean different things.

To "lift" an operator is to take an operator that operates on non-nullable value types, and create from it a similar operator that operates on nullable value types. (We are a little bit inconsistent in exactly how we use the word "lifted", which I documented here.)

For example, if you have

 public static Complex operator +(Complex x, Complex y) { ... }

 then we automatically generate a lifted operator for you that basically does this:

 public static Complex? operator +(Complex? x, Complex? y) 
 {
   return (x == null || y == null) ?
    (Complex?) null : 
    (Complex?) (x.Value + y.Value);
 }

"Raising" by contrast refers to events -- not to exceptions, which are of course "thrown". Another common term for raising an event is "firing". Given that it makes sense to standardize on one or the other, the usage committee people felt that between "raising" and "firing", they'd pick the less bellicose-sounding one. Which is maybe a bit silly, but if you've got to pick one, then I suppose that's as good a criterion as any.

Finally, "hoisting" is what we call it when the compiler emits a field for what looks like a local variable, because that local variable is in fact a captured outer variable of an anonymous function (or a local of an iterator block). When you have:

class C
{
  void M()
  {
    int x = 123;
    Func<int, int> f = y=>x+y;
...

then we rewrite that as if you'd written something like:

class C
{
  private class Locals
  {
    public int x;
    public int Method(int y) { return this.x + y }
  }
  void M()
  {
    Locals locals = new Locals();
    locals.x = 123;
    Func<int, int> f = locals.Method;
...

 see, local "x" has been "hoisted" up and out of its declaration space.

Even after a number of years on the compiler team, I still misuse "raise", "lift" and "hoist" in casual conversation; that they have such similar meanings in English and dissimilar meanings as jargon is unfortunate, but usually doesn't result in too much confusion.

Published Thursday, June 18, 2009 6:32 AM by Eric Lippert
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Tony Cox [MSFT] said:

In choosing between "raising" and "firing" an event, it seems to me that "less bellicose sounding" is a far less useful criteria than "doesn't collide with existing common usage".

Since "raising an exception" is common terminology in other contexts, whereas nobody "fires" anything in other contexts that I can think of (well, except for events), surely "fire" would have been a much better choice.

"Triggered" or "activated" might also have been reasonable alternatives.

Sometimes when writing a spec, you need a good thesaurus to hand...

June 18, 2009 1:39 PM
 

Pavel Minaev [MSFT] said:

Oh, if you only knew the woes of translating "raising the event" (or "firing" one, for that matter) to Russian! Or, say, the difference between "statement" and "operator"...

It's actually something worth keeping in mind - no matter how clear you can get it for English speakers, other languages will still have its own problems that you can't really anticipate in advance.

June 18, 2009 5:59 PM
 

Joe said:

@pminaev - you could just do what the Germans do: mangle your language and shove in English words everywhere!  Then you end up with lovely expressions like "das Exception throwen" (instead of: die Ausnahme ausloesen) and "das Event raisen" (instead of: das Ereignis ausloesen).  It sounds as horrid to the ear as it looks to the eye, but I suppose it's better than when people use the wrong word and end up saying things like "throw the event" which just makes you go "huh?"  It also doesn't help that whoever translated the C# reference into German wasn't at all bothered by turning "throw" and "raise" into the same word (ausloesen).

June 19, 2009 1:20 AM
 

Denis said:

@pminaev, @Joe - whatever you do, don't use the online translators: once, just for the fun of it, I tried to type some English text into one such program (can't remember which one), translate it to the Chinese, and then the result - back to English. If only the program is not smart enought to simply revert to your original under such circumstances, the result is really educational - try it yourselves! And don't choose some closely related laguages, like Spanish and Portuguese, or Russian and Ukrainian - that's no fun! :-)

There are many apocryphal but funny stories about machine translation gone bad. Two of my favourite legends: "out of sight, out of mind" (an English idiom meaning "if you cannot see it then you will eventually forget about it") gets translated to Japanese and then back to English, and comes back as "the blind people are insane". Or "the spirit is willing but the flesh is weak" (meaning "I wish to do something that I am not physically able to do") round-trips through Russian to "the vodka is fine but the ham has spoiled". -- Eric

June 19, 2009 3:42 AM
 

Steven said:

I once accidentally installed the Dutch .NET version on my development PC. It was terrible. The C# compiler errors were all given Dutch. Even terms like "overloaded” (as in overloaded methods) were translated to Dutch. But not a single Dutch programmer uses a Dutch translation of "overloaded" (translated to "overbelast" in .NET) and while I'm Dutch, it was like reading German :-)

June 19, 2009 4:38 AM
 

Doeke Zanstra said:

In vb6 speak, one raises events. So that's a bit old school. But in the entire web, we talk about firing events. Also Google thinks "fire events" (96.8 M hits)  is bigger than "raise events" (50.4 M hits). Although substantial, I wonder for how long you can keep it up ;-)

June 19, 2009 5:32 AM
 

askitanna said:

can anybody say me the meaning for the qoute below the title

"Use your legs, not your back"  

June 19, 2009 5:53 AM
 

Daniel Earwicker said:

@askitanna - it's good advice when lifting a heavy object.

(I guess a heavy object would be one with a finalizer?)

June 19, 2009 6:06 AM
 

TubbyHubby said:

@askitanna - Whenever you lift (or hoist or raise) something heavy, you should take a stance that allows you to use the strength of your legs, not your back, for safety purposes.  In the US, it is very common to simply say "Use your legs, not your back" to describe the entire safe method of getting something heavy up off the ground.

June 19, 2009 3:19 PM
 

Denis said:

The funniest story I ever heard about the machine translations was the name Osama Bin Laden coming out as "Osama the Loaded Rubbish Container" (as an explanation, think the Recycle BIN on your Windows desktop, and the word "laden", adjective, is self-explanatory)

June 20, 2009 7:23 AM
 

Alex said:

Hi, Eric

You said that hoising captures local variables (hope I'm not putting words in your mouth), but I did some research of my own and found out that it is not true.

I wrote some code along these lines to look into the matter:

....

var toBeHoisted = 1;
Func<int, int> f = a => a + toBeHoisted;
var before = f(1);
toBeHoisted = 2;
var after = f(1);

....

I would assume that since that variable got "hoisted", a snapshot of it was made in function "f" (it was captured in your words) and variables "after" and "before" should have coincided, but they did not !

Then I wrote this code:

....

var toBeHoisted = 1;
Func<int, int> f = a => {toBeHoisted += 1; return a + toBeHoisted;};
f(1);

....

Again I was in for a surprise, I had thought that variable "toBeHoisted" would not be changed from the anonymous delegate, but it was !

[[ The variable itself is captured, not the value of the variable. When you make a change to the variable in one place, everyone that captured that variable sees the change. Now is it clear why what you're seeing is expected. -- Eric ]]

June 27, 2009 4:50 PM

Leave a Comment

(required) 
(optional)
(required) 

  
Enter Code Here: Required
Submit

About Eric Lippert

Eric Lippert is a senior developer on the Microsoft C# compiler team. Before that he worked on the framework of Visual Studio Tools For Office. Before that, he worked on the compilers, runtimes and tools for VBScript, JScript, Windows Script Host and other Microsoft Scripting technologies. He lives in Seattle and spends his free time editing books about programming languages, playing the piano, and trying to keep his tiny sailboat upright in Puget Sound.

This Blog

Syndication


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker