JetBrains dotPeek

redgate‘s decision to start charging for their Reflector .NET decompiler sent ripples through the .NET development community. Personally, while I do not think that the 25-69 EUR price is outrageous, I must agree with many people – redgate promised to keep Reflector free after the acquisition.

But, whatever happens, happens for the best. New decompilers started appearing like mushrooms after the rain, and JetBrains, the famous maker of e.g. ReSharper and TeamCity, came with its own free dotPeek decompiler, which is in the EAP or Early Access Program stage now. Knowing and using JetBrains’ products, I believe that dotPeek has all chances to become the de-facto standard for a .NET decompiler eventually, so I will keep an eye on it.

Managed/Native Debugging in C#/C++

I had a problem debugging my solution consisting of C#, C++/CLI, and native C++ projects. I was not able to get breakpoints working in the native C++ parts – after running the solution with breakpoints set, they were turning gray with warning sign, and their tooltip stated that “The breakpoint will not currently be hit. No symbols have been loaded for this document.” despite all debug properties were set right on those projects and all debugging symbols existed. After fighting it for a few hours and almost giving up, I started to think that the problem might not be with the native C++ projects, but rather somewhere else, e.g. in the StartUp project, which is C#. Checked that project’s properties, and guess what! Debug > Enable unmanged code debugging option was off!!! Switched it on, and voila – breakpoints work fine in native C++ DLL now!!! :)

Debugging MSBuild Scripts (VS2010)

I did not actively search for the subject, but once I bumped into a three-part article about the MSBuild script debugging (Part I, Part II, Part III) on The Visual Studio Blog I immediately though that it is worth remembering about it when (I am not saying if, but rather when here) I need it in the future. The blog itself is also worth checking, as there is much information about VS IDE, MSBuild, and extensibility from the Visual Studio development team.

Security: Banned C Functions

memcpy() Is Going to Be Banned article at InfoQ talks about dangers of memcpy (and other memory/string related functions). Microsoft has more in-depth explanations as well as the list of Security Development Lifecycle (SDL) Banned Function Calls at MSDN. Also available from Microsoft is banned.h header file that, once included, will produce warnings for all the banned functions. Alternatively one can use the /W4-C4996 compiler option.

SciTech .NET Memory Profiler

Schitech .NET Memory Profiler has plenty of features that will make your life easier when you try to fight memory-related problems in your .NET applications. Nice touch – it is able to track unmanaged resource usage (e.g. HWND, HBITMAP and unmanaged memory) and present it together with the .NET memory information. Just this single feature alone saved my day when I had to find unmanaged memory leak in the mixed-mode .NET app (C# and C++), and all other profilers just $@% badly – I had the bug fixed in less than one hour after I downloaded the trial version of the tool (that 1 our included “learning curve” as well!!!). Recommend!

Crack.NET

Crack.NET is a runtime debugging and scripting tool that gives you access to the internals of a WPF or Windows Forms application running on your computer. It nicely rounds the Snoop and Mole for Visual Studio group, as it allows you to “walk” the managed heap of another .NET application, and inspect all values on all objects and types. In addition, you are able to write and execute IronPython scripts that run inside the target application.

Josh Smith is the author, and has a nice introductory page for the tool.

Microsoft DevLabs

On the DevLabs site you read: “Any truly remarkable software innovation that introduces a paradigm shift is based on solid inventive ideas. But it also needs discussion, trial, collaboration, and a critical eye. Explore the projects that we are experimenting with in our labs, and let us know if they inspire you.”

Currently there are four projects there:

  • Popfly, a “fun, easy way to build and share mashups, gadgets, games, Web pages, and applications”
  • Small Basic, a “simple and easy programming language with a friendly environment that provides a cool and fun way of learning programming”
  • Pex, an “intelligent assistant to the programmer”
  • CHESS, a “concurrency testing tool for finding and reproducing concurrency Heisenbugs in your code. CHESS can find assertion violations, deadlocks, livelocks, data-races, and memory-model errors. CHESS works both for managed and for unmanaged code”

Monitoring Last Error Code in Visual Studio

Found this trick in the Jeffrey Richter’s Windows via C/C++ book (in Chapter 1). Visual Studio debugger has a very useful feature – it can monitor the thread’s last error code. You can display this error code together with its text description in the Watch window by typing $err,hr. In case some API call fails, the Watch window will show the error code (the one that would be returned by the GetLastError function). Thanks to the ,hr qualifier, the Watch window shows the error description as well (the string mentioned in the WinError.h header file for the occured error code).

Mocking Frameworks

Today was Sunday and I took a “day-off” from the project :) and decided to look into the world of mocking… Before I start, I should admit, that while I understand (or at least I hope so) principles and benefits of Test Driven Development (TDD) and mocking, I have never used them in my work. There are a few reasons for this:

  1. Currently I am developing a digital TV feature and infrastructure for an advanced set-top box (running on Windows XP Embedded), and simply do not get how I can use TDD and mocking with needs like processing 25-40+ megabit transport streams and doing something useful with them. The code that I would be able to test using TDD and mocking is way too simple for this, and the code I perhaps would be interested in testing automatically, is not really “testable” for the abovementioned reasons.
  2. Unit testing and mocking frameworks for C++ and C++/CLI, the two languages I use 80% of my time nowadays, are quite “anemic” at best, and it is really no fun to use anything like those frameworks.
  3. On top of that, to be honest, I never felt the need to use TDD and mocking in my own practice. Retrospectively thinking, I do not remember any project where TDD or mocking would substantially improve the quality of my code and/or reduce the number of defects (although I definitely know cases where it would not harm to use TDD and mocking) – I am not “boosting” myself, but there is an order of magnitude difference in performance among developers, and even bigger difference in quality of the code they write. In fact, I think TDD and mocks were invented to somehow compensate for this difference.
  4. I somehow have a weird feeling about adding to my project as much testing/mocking code as there is “normal” code. And then, I am definitely not “purist” but rather “pragmatic” – I agree that it might be wise to have unit testing/mocking in some parts of the system, but definitely not everywhere.

So, now that I explained my background, I am ready to continue. After spending quite much time on Google and other development-related sites I managed to narrow the list of available .NET mocking frameworks down to three: Typemock Isolator, Rhino Mocks, and Moq. All frameworks support .NET 3.5 (Rhino has it in version 3.5 RC).

Typemock is definitely the most powerful of these frameworks, but this property of Typemock is often mentioned in the cons section. The argument is, that while allowing mocking everything and everywhere, Typemock is not really helping developers to design loosely coupled code – for example, you do not have to “resort” to Inversion of Control (IoC) principle to use Typemock. I think Typemock is as its best when you try to introduce TDD and mocking into legacy project to get better understanding of that code and to have easier time modifying it. The framework has a free version, but to get e.g. its Natural Mocks feature (allowing to define expectations by recording them in a type-safe manner) you will have to cash out 349€ for Professional or 449€ for Enterprise editions.

Rhino Mocks is likely the most used .NET mocking framework. The framework looks quite powerful, is type-safe, supports generics, and is actively developed.

Then, there is Moq – a newcomer to the scene. Some people criticize it for being too simple. Some accuse it of not being “pure”. From what I have seen today, I should say that I liked it most (second being Rhino). It has rather elegant type-safe API built around lambda expressions. This API allows writing shorter and more concise code than Rhino does. What sets Moq apart from other mocking frameworks is that it is not using the record/playback model.

I will definitely give TDD and mocking a try on my next project. On the other hand, my C++ part of our current project is much smaller than our C#/.NET 3.5/WPF code-base, so I might introduce mocking into our current project if there will be not too big “opposition” from the development team and other project stakeholders – we are under heavy time pressure now, and adding some new concepts at this moment will probably introduce significant delays. I think that the framework of choice will be Moq, although it is just a gut-feeling at this moment.

And here is the list of interesting blogs/sites about the mocking:

Software Testing and Related Things

By accident found Google Testing Blog. Not bad.

One of the articles is called How to Write 3v1L, Untestable Code – a must-read for newbie (and not newbie too!) programmers. Not on this blog, but nevertheless related article is How To Write Unmaintainable Code by Roedy Green – very serious collection of bad things despite it is very funny to read.

Debuggers and Disassemblers

SmidgeonSoft provides free Windows programming utilities, e.g. PEBrowse Professional Interactive (native and managed code debugger), PEBrowse Professional (PE file viewer/disassembler), PEBrowse Crash-Dump Analyzer, TopToBottomNT (component manager/system explorer), NTDevices (driver/device object explorer), NTObjects (kernel/executive object explorer).

OllyDbg – free (shareware, but can be used for free) 32-bit assembler level analysing debugger for Windows. List of features is really impressive.

Tools, Technologies and Other Things

Well, not really WPF related, but still…