CSharpFeeds - All your C# feeds in one place.

Sponsors

Thursday, June 18, 2009

Use your legs, not your back

by Eric Lippert via Fabulous Adventures In Coding on 6/18/2009 1:32:00 PM

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.

email it!bookmark it!digg it!

Original Post: Use your legs, not your back

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us