Another effective [debugging] technique is to explain your code to someone else. This will often cause you to explain the bug to yourself. Sometimes it takes no more than a few sentences, followed by an embarrassed "Never mind. I see what's wrong. Sorry to bother you." This works remarkbly well; you can even use non-programmers as listeners.
- From "The Practice of Programming"
by Brian W Kernighan & Rob Pike.
Search This Blog
Infinite .NET Languages !!!
Though I knew that there are quite a few languages for the .NET platform, I came to know when surfing today that there are many well beyond my knowledge, most surprisingly like the COBOL.
I would not want to write chunks of code to spawns threads and perform many of my background tasks such as firing events, UI update etc. Instead I would use the System.Threading.ThreadPool class which serves this purpose. And a programmer who knows to use this class for such cases would also be aware that the tasks queued to the thread pool are NOT dispatched in the order they are queued. They get dispatched for execution in a haphazard fashion.In some situations, it is required that the tasks queued to the thread pool are dispatched (and executed) in the order they were queued. For instance, in my (and most?) applications, a series of events are fired to notify the clients with what is happening inside the (server) application. Although the events may be fired from any thread (asynchronous), I would want them or rather the client would be expecting that the events are received in a certain order, which aligns with the sequence of steps carried out inside the server application for th…
There are two facilities in C# to determine the
size of a type - sizeof operator and
Marshal.SizeOf method. Let me discuss what they offer and how they differ.
Pardon me if I happen to ramble a bit. Before we settle the difference between sizeof and
Marshal.SizeOf, let us discuss why would we want to compute the size of a variable
or type. Other than academic, one typical reason to know the size of a type (in
a production code) would be allocate memory for an array of items; typically done
malloc. Unlike in C++ (or unmanaged world), computing the size of a type
definitely has no such use in C# (managed world). Within the managed application,
size does not matter; since there are types provided by the CLR for creating\managing
fixed size and variable size (typed) arrays. And as per MSDN, the size cannot be
computed accurately. Does that mean we don't need to compute the size of a type
at all when working in the CLR world? Obviously no, else I would not be w…
This is about a killer bug identified by our chief software engineer in our software. What was devised for ease of use and write smart code ended up in this killer defect due to improper perception. Ok, let us go!CComPtr is a template class in ATL designed to wrap the discrete functionality of COM object management - AddRef and Release. Technically it is a smart pointer for a COM object.void SomeMethod()
HRESULT hr = siPtr.CoCreateInstance(CLSID_SomeComponent);
}Without CComPtr, the code wouldn't be as elegant as above. The code would be spilled with AddRef and Release. Besides, writing code to Release after use under any circumstance is either hard or ugly. CComPtr automatically takes care of releasing in its destructor just like std::auto_ptr. As a C++ programmer, we must be able to appreciate the inevitability of the destructor and its immense use in writing smart code. However there is a difference between …