

C# Hidden Optimizations - gavdraper
http://www.gavindraper.co.uk/blog/2010/08/10/CHiddenOptimizations.aspx

======
heresy
Nit: These aren't "optimizations", they're syntactic sugar.

~~~
achew22
I'm far from impressed with this. How is ?? any different from a guard ( || )?
I use that all the freaking time in every language. I've never written a line
of C# and even I know about the parallel module, how didn't that make the cut?

~~~
mullr
C# has || just like any other language, but objects aren't truthy and nulls
aren't falsy. This was a good design decision, since it catches the common =
vs. == error if(a=b) while doing the type check rather than silently doing the
(probably) wrong thing. As a consequence, the || doesn't work as it does in
other places. Hence ??.

~~~
steverb
?? is the null coalescing operator and it's neither new nor is it hidden.

It is damned handy though.

------
oozcitak
I would say expression trees is one of the less well-known and under-
appreciated features of C# 3.0:

    
    
        Expression<Func<int, int>> e = (x) => x + 1;
        Func<int, int> f = e.Compile();
        int b = f.Invoke(42);

~~~
arethuza
I'm quite fond of C# but that syntax is a bit much when compared to things
like humble old JavaScript:

    
    
       var f = function(x) { return x + 1; };
       var b = f(42);

~~~
yread
well you can write it as

    
    
      var f = ((x) => x + 1).Compile();
      int b = f.Invoke(42);

~~~
oozcitak
I don't think that would work. How would the compiler know the type of x and
the return type of the lambda expression?

~~~
the_rara_avis
It won't. In just about all cases, C# doesn't do backtracking to infer types.
See Eric Lippert's posts:
[http://blogs.msdn.com/b/ericlippert/archive/2010/10/04/no-
ba...](http://blogs.msdn.com/b/ericlippert/archive/2010/10/04/no-backtracking-
part-one.aspx)

------
newt
This article is Ok, in an introductory sort of way, but these are not
"optimizations" in the sense that they will make your code run faster. They're
syntactic sugar as _heresy_ says.

They're also not very hidden either.

------
Rickasaurus
How did this garbage get on the HN front page?

