Lambdas: An Example in Refactoring Code

Background: Lambdas and Why This Example is Important Based on your experience in C# or other programming languages, you may or may not be familiar with what a lambda is. If the word "Lambda" is new and scary to you, don't worry. Hopefully after reading this you'll have a better idea of how you can use them. My definition of a lambda expression is a function that you can define in local scope to pass as an argument provided it meets the delegate signature. It's probably pretty obvious to you that you can pass in object references and value types into all kinds of functions... But what about passing in a whole function as an argument? And what if you just want to declare a simple anonymous method right when you want to provide it to a function? Lambdas. So…

1 Comment

Events: Demystifying Common Memory Leaks

Background If you've poked through my previous postings, you'll probably notice that I love using events when I program. If I can find a reason to use an event, I probably will. I think they're a great tool that can really help you with designing your architectures, but there are certainly some common problems people run into when they use events. The one I want to address today has to do with memory leaks. That's right. I said it. Memory leaks in your .NET application. Just because it's a managed language doesn't mean your code can't be leaking memory! And now that I've got your attention, let's see how events might be causing some leakage in your application. (There is source that you can download and run. Check the summary section at the end!) Instance-Scope Event Handlers One of the…

4 Comments

Why Events? Flexibility.

Before we talk about events... Let's consider that there are many different approaches to developing software. In my opinion, the opposite ends of the spectrum end up being: Knowing how the whole system looks, feels, and operates before coding a single line. Having an idea of what the user wants and coding to make it happen. Although I'm generalizing a lot here, it's sort of like the battle between Waterfall and Agile. Okay, great. So what am I rambling on about here? Well, in the first case, you know all the ins and outs of the system. You can structure your system so that almost no matter how complex it is, you can ensure that method A is always run immediately after method B which is etc... The design is completely controlled. You have a spec for how all the…

1 Comment

End of content

No more pages to load