Garbage Collection and C++
2008-10-24

Why doesn’t C++ have garbage collection? Simply put, it doesn’t need it. C++ has something called Resource Acquisition Is Initialization. What this means is that programmers can deterministically know when an object is created and when it is destroyed. You do not have the same information with garbage collected languages. For example, in C# you know when an object is created (when you call new), but you have no idea when the object gets destroyed. Read on...
A sweeeeet commenting tip
2008-09-30

No no no…this isn’t another typical post splurging about how you should comment your code, just another sweet tip I got from a good friend of mine. If you’ve been coding for a while you’ll run into a time where you have 2 sections of code that you need to edit. However, you can only have 1 section commented, and the 2nd section uncommented, or vice versa. Even with the built-in keyboard shortcuts (Ctrl+K, Ctrl+C) and (Ctrl+K, Ctrl+U), it’s still a pain in the behind. Read on...
An Unfortunately Too Well Hidden Tool
2008-09-20

Alright, maybe it’s not THAT well hidden, but it’s well hidden enough that most developers don’t even know it exists, yet I find it to be probably one of the top 3 tools of Visual Studio that I find most useful. What is it? Break into debugger at any uncaught exception. Yep! There’s actually a feature that can do that! You don’t have to pull your hair out trying to figure out what exception is causing your program to mess up or when it gets swallowed. Read on...
The Infamous IDisposable Pattern
2008-09-17

At one point or another, any .NET developer should come across the concept of implementing the IDisposable pattern. For more detail, visit this excellent article at http://www.codeproject.com/KB/cs/idisposable.aspx. One of the most common errors of programmers with a C++ background is that they define the Finalize() method with ~() syntax. This is almost always wrong. Just like you should never call GC.Collect(), you should not define a finalizer most of the time. Read on...
GC.Collect Is Bad For You
2008-09-11

Sometimes I wish Microsoft didn’t include this method in the API because it promotes bad programming. I’ve seen people use this in their code and 99.99% of the time, it is incorrect to do so. I came across a program which had many try/catch/finally blocks which had GC.Collect() in the finally block. C# has a garbage collector so you, the programmer, does not have to worry about cleaning up memory. In fact, it’s optimized in such a way that it only collects memory when it needs to. Read on...