I continue to find Lisp to be a fascinating language especially this really interesting piece of code.
Ok so what’s going on here?
if b > 0
“Why would you write it this way when (insert code here) works better?”
Shut up troll! I’m not telling anybody to go off and write their code in expression trees when the following code is clear the correct why to write it.
See that’s way easier, but this isn’t a post about smart things to do with expression trees now is it?
Let’s up the silliness some more and make it an extension method just for fun.
I was having so much fun with this that I even roped some of my teammates in on it. Heres Chad Myers solution.
So I think its cool that you can kind of return + or – from an if statement, but what started as a fun little exercise turned into an amazing adventure into learning expression trees.
So as my final brain beating exercise I tried make this into a Func<int,int,int> completely build using expression trees.
So here’s a little challenge. In the comment section I invite you to completely school me in the ways of Expression Trees. Try and come up with a way more awesome version of a_plus_abs_b using expression trees or IL or whatever awesome sauce is in the .NET framework that I’m not aware of.
My name is Ryan Rauh and I like shiny things. If I've seen it on twitter more the twice most likely I've looked at it or tried it. I really like memes and other silly and seemingly useless things out on the internet.
I blog about things *I* think are cool and interesting, I hope you will find them cool and interesting too.