Archive for the 'Software Components' Category
PostSharp 1.5 RTM
Threadsafe Events article at CodeProject explains problems one might encounter with .NET events in a multithreaded environment (not necessarily stating the absolute truth but still). Unfortunately, no-one has figured out the perfect solution, and we will have to choose “the best from all bad solutions” for some time still.
Asynchronous Callback Contexts article by the same author shows possible solution for event cancellation, particularly during object disposal: end-users do not expect components to raise events after they have been disposed or after they have unsubscribed from these events. The author refers to his Nito Asynchronous Library as a way to solve this issue.
Win32/C++ Resources
A “healthy set” of Win32 and C++-related links (related stuff, anyway):
- MVP Tips, Techniques, and Goodies by Joseph M. Newcomer has a lot of C++ and Win32 topics, covering all “gray” areas like asynchronous operations, synchronization, threading, memory leaks, optimizations, various Windows APIs, device drivers, etc. For example, there is An introduction to memory damage problems that goes thoroughly through the topic, or absolutely fantastic The n Habits of Highly Defective Windows Applications that nicely enumerates ugliest “no-no’s” one should avoid in his code if he wants to sleep well :)
- C++ In Action, book by Bartosz Milewski. Cool thing is that there is a web edition of the book. Additionally, on the C++ Resources page there is Windows API Tutorial, RSWL: Free Windows Library, and some other papers and presentations, including topics on Resource Management, something called auto_vector ;) , and rather interesting Dealing with Software Complexity presentation.
- Win32 samples has a lot of samples for Net*() APIs, as well as for LSA, NTFS streams, processes, security
Managed Windows API
Managed Windows API is a collection of C# components that wrap Windows API functionality – a nice addition to pinvoke.net.
Found TCP: Buffer Management and related Async Sockets and Buffer Management and Async Sockets and Buffer Management [CTD] articles on Greg Young’s blog. These articles describe the problem and show the solution:
When you call BeginReceive/BeginSend on a socket, the memory that you pass to the method will be pinned for the duration of the call. This will lead to heap fragmentation and to make matters worse it will often be in your gen0 heap if you aren’t careful. This becomes especially true in the most common socket applications (request/response) as BeginReceive is often called and waits for a long time to receive data (by long time I mean a few seconds or more).
The blog itself is interesting on its own.
API Hooking
Detours is a Microsoft library for instrumenting arbitrary Win32 functions (by Microsoft Research), unfortunately not free. There is a paper Detours: Binary Interception of Win32 Functions by Microsoft guys. In addition, there is API Hooking with MS Detours article on CodeProject.
Then, there is EasyHook – “The reinvention of Windows API Hooking” as they say themselves – which allows to hook APIs from managed code and write managed detours. This one is free, and from what is there it looks even more interesting than Microsoft’s Detour. And there is also a related CodeProject article.
Transactional Memory
There is a team at the Microsoft’s Parallel Computing Platform group (guys behind the Parallel Extentions for .NET) that is implementing an experimental transactional memory system in .NET. Recently they have put up a Transactional Memory blog – let’s hope that it will get more than one entry eventually :) .
While Microsoft still ponders about the thing, Ralf W created the NSTM – .NET Software Transactional Memory project on CodePlex. Additionaly, he has a set of articles on his Ralf’s Sudelbücher blog about this project and its implementation.
Just that I will remember these:
- Alexandria Media Library is a loosely coupled suite of media applications written in C#. The architectue of Alexandria allows plugins to be designed to perform any function imaginable and then integrate these with the existing plugins to provide a full application. Plugins exist for: media playback, playlists, tagging with metadata, search for media and metadata, etc.
- FMOD with FMOD Ex Programming API is a revolutionary multiplatform new audio engine featuring e.g. fantastic sounding DSP audio engine, choice of low-level or data-driven API, built-in DSP effect suite and VST support, as well as advanced features such as 2D/3D morphing, 3D reverb support and geometric occlusion, etc.
- MusicDNS by MusicIP provides a method for acoustically identifying digital music and acquiring the correct metadata. MusicDNS consistently identifies the same digital music recording, regardless language or audio file format. Track level fingerprints are finely tuned for accurate matching, and eliminate the cost and challenges of legacy CD data. The database is kept current as new albums are released. Sounds cool!
- MusicBrainz is a community music metadatabase that attempts to create a comprehensive music information site. You can use the MusicBrainz data either by browsing this web site, or you can access the data from a client program — for example, a CD player program can use MusicBrainz to identify CDs and provide information about the CD, about the artist or about related information. You can also use the MusicBrainz Tagger to automatically identify and clean up the metadata tags in your digital music collections.
Today’s Blogs
- The Old New Thing by Raymond Chen – really nice blog with a lot of in-depth info, e.g. wonderful posts about The implementation of iterators in C# and its consequences (part 1, part 2, part 3), The implementation of anonymous methods in C# and its consequences (part 1, part 2, part 3), a lot of native Win32 topics (e.g. DLLs, processes, controls, etc.), etc. Probably there is no aspect of Windows that would not be covered at that blog! :)
- jaredpar’s WebLog by Jared Parsons – blog of the author of RantPack – a library that features functional programming patterns (tuples, immutable/persistent collections), threading utils (futures, cancelable futures, active objects, various other primitives), etc. The blog is very interesting, and there are many insights into software development topics
Today’s Links
These are mostly related to systems’ programming:
- Professional System Library – a free, open-source COM library that offers a simple, generic and logical API for accessing most commonly used information about the system and the environment in which the client application is running, e.g. security, privileges, processes, threads, drivers, services, network, memory, etc. There is also Professional System Library: Introduction article at CodeProject giving brief introduction to the library.
- Authors of 32 OpenMP traps for C++ developers article did really good job. I have not use OpenMP (multi-platform shared-memory parallel programming API for C/C++ and Fortran) myself yet, but can easily imagine that this article can save many hours of painful digging into the non-working code.
- A Fiber Class (and Friends) (C++) is introducing fibers and illustrates the implementation of round-robin scheduler for fibers.
- Telling The Difference Between CD and DVD Drives (C++) – might save some time if needed eventually
- Using Raw Input from C# to handle multiple keyboards – despite the article is in C#, it is 1:1 translating to C++.
- Tracing Events Raised by Any C# Object presents the simple-but-general event hooking/tracing class.
DirectShow Resources
There is no need to say anything about any of the following:
- Geraint Davies Consulting Ltd or GDCL – the home of Geraint Davies, the author of DirectShow, and famous GMFBridge. The site has a lot of interesting information about DirectShow, e.g. introduction to filters, technical Q&A, as well as some pretty elaborative samples like demuxers
- The March Hare – the guy is always present at DirectShow forums :) . Filter Graph Library, despite being written by another guy can be downloaded from this site as well
- Alessandro Angeli’s Programming FAQ – a lot of useful DirectShow tips and tricks
- GraphEditPlus – is GraphEdit done right :) . Especially nice time-saving feature is its graph code generation – you build the graph and GraphEditPlus generates its C++ creation 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:
- 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.
- 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.
- 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.
- 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:
- TDD : Introduction to Moq by Stephen Walther
- Moq: Linq, Lambdas and Predicates applied to Mock Objects by Scott Hanselman
- kzu Weblog by Daniel Cazzulino, the author of Moq
- Comparing Moq to Rhino Mocks by Phil Haack
- Ayende @ Rahien blog by Oren Eini, the author of Rhino
- Inversion of Control Containers and the Dependency Injection Pattern by Martin Fowler
- Mock Objects – Steve Freeman and Nat Pryce are writing a book, let’s call it “Growing Object-Oriented Software, Guided by Tests”. So far two chapters are available online.
NGenerics
NGenerics is a class library providing generic data structures and algorithms not implemented in the standard .NET framework, e.g. queues, deques, matrices, trees, graphs, various sorting algorithms, etc.
Duck Typing Project
Recently I has been looking at various mocking frameworks, and found Duck Typing Project (by David Meyer AKA “deft flux”) – a .NET class library written in C# that enables duck typing for any .NET language. Current release is a bit oldish, but David promised to finalize version 1.0 and start working on 2.0, which will include a name change to something along the lines of “dynamic typing” instead of “duck typing” to reflect the implementation of more dynamic typing concepts than just duck typing, as well as add some .NET 3.5 features like extension methods.
How Duck Typing Benefits C# Developers by Phil Haack provides quick into to duck typing and its benefits.
Visual C++ 2008 Feature Pack
Microsoft has released Visual C++ 2008 Feature Pack already in April, but I somehow did not try it then and completely forgot about it. The pack features a number of MFC improvements, and also includes an implementation of TR1, portions of which are scheduled for adoption in the upcoming C++0x standard. TR1 includes a number of important features such as: smart pointers, regular expression parsing, new containers (tuple, array, unordered set, etc.), sophisticated random number generators, polymorphic function wrappers, type traits, etc.
Beef Up Windows Apps with the Visual C++ 2008 Feature Pack article in May 2008 issue of MSDN Magazine has a bit more information about the pack.
WPF Weather Reader User Control
Found Weather Reader User Control (on CodePlex), that has the functionality of Vista weather gadget. The control parses a XML weather feed from the Internet and updates an object model that is data bound to the UI. The design is extensible and can be adapted to any general feed with minimal changes.
ORMs
Yesterday I was thinking about how complicated and painfull is accessing databases in .NET, and thus in WPF. It is absolute mess. Really. Much more messy that it was in good old ADO (anyone remembers those times?), and not even remotely close to data access nirvana of FoxPro and Visual FoxPro.
LINQ is very nice, but it is just a query language completely missing insert, update, and delete concepts. Then there is a weird thing called LINQ to SQL – it really sucks if you are changing database schemas (and you normally do that in the beginning of the progect frequently). Sheer amount of the code and “infrastructure” generated for you is mindboggling. Things get even worse if you want to use SQL Server CE – then you are stuck with something called SqlMetal. Brrrrrrr! Then, add plain old ADO.NET with LINQ to ADO, and EF to the “package” and you are completely and thoroughly lost. Bad… very bad… total mess… Does it have to be like that? And why Microsoft cannot decide on one thing and do it right?
That’s why I decided to spend some time and to see if there are any alternative ORMs available.
Everyone knows NHibernate (little brother of Hibernate), and DevExpress’ eXpress Persistent Objects (as one friend of mine said, “When I hear word DevExpress I am reaching for my gun!” :). These two ORM frameworks are suffering from the same problems as EF, LINQ to SQL and other things offered in this domain by Microsoft: too general, too complex, too steep learning curve, too many demands and expectations toward the code developed. They might be good for big and complex systems, but if you develop an application where database is just one small part of functionality they quickly become too big of a burden.
Clearly, there is a need for something more lightweight. And seems that I found something that looks rather promising: one thing is called Mindscape’s LightSpeed, and the other one has intriguing name LLBLGen Pro. Both frameworks look really easy – I got pretty much of the LightSpeed’s idea in about 20 minutes, although have not checked LLBLGen Pro yet. Both are offering most essential features – as Mindscape says, “Solve the 95% case, i.e. more like Ruby on Rails than NHibernate”. Both provide Visual Studio integration. LLBLGen Pro supports more databases than LightSpeed, but both seem to be OK for our needs. Probably they are not as flexible and not as all-encompassing as their “older brothers”, but it is obvious that not everyone needs this flexibility anyway – I think “less is more” is very frequently true. Both frameworks fully support LINQ as well as INotify* interfaces, so they can work in WPF.
Personally I liked LightSpeed’s web-site and documentation more, but probably LLBLGen Pro has appropriate content as well. Cost wise they are not that bad, and LightSpeed exists in free version as well (with limit of 8 tables).
WPF Application Localization
WPF Runtime Localization article on CodeProject describes one way to do it. Interesting approach is to use WPF Localization Extension available freely on CodePlex. And then there is an article that goes in the same direction: WPF Localization – On-the-fly Language Selection.
Just few days ago I found WinUnit, and voilaz – here is googletest, Google’s xUnit-based multiplatform framework for writing C++ tests. Supports automatic test discovery, a rich set of assertions, user-defined assertions, death tests, fatal and non-fatal failures, various options for running the tests, and XML test report generation.
Hardware Breakpoints
Toggle hardware data/read/execute breakpoints programmatically and Hardware breakpoints articles show how to use hardware breakpoints. Source code is available from both places.
Wintellect’s Jeffrey Richter created the Power Threading Library containing many classes to help with threading and asynchronous programming. More information about the library’s classes can be found via Jeffrey Richter’s Concurrent Affairs column in MSDN magazine. Then there is the Yahoo! Group established to support the use of this library
On top of that, Wintellect has the Power Collections Library that extends the Base Class Library with an algorithms class and a series of new containers. Now the library has moved to CodePlex and is available with the source code. Wintellect’s Peter Golde has excellent blog going into deeper details about the library.
Freewave is a free and open-source collection of popular image and signal processing routines designed to accelerate application development, debugging, and optimization on x86-class processor platforms. API is compatible with the Intel Integrated Performance Primitives (see SourceForge and AMD pages for more information).
WinUnit: Simplified Unit Testing for Native C++ Applications article at the MSDN Magazine introduces WinUnit. It is possibile to browse or download the code.
Today’s Sites/Blogs
- Pedram Rezaei’s Ramblings – a bit of everything: Parallel Extensions for .NET, WCF, WPF…
- Fabulous Adventures In Coding by Eric Lippert [MSFT] – generics, advanced .NET topics, covariance vs contravariance, etc.
- Managed World blog by Jason Olson [MSFT?] – a lot of interesting information about new .NET things like lamdas, Managed Extensibility Framework, F#, etc.
- Ayende @ Rahien by Oren Eini – testing, mocks, a lot of code snippets (including Code of the Week), etc.
- Kirill Osenkov – QA, advanced C#, etc.
- Sree’s ventures in code space by ? – debugging, C#, extension methods, etc.
Disk Defragmenting Tool with DLL
JkDefrag is a disk defragmenter and optimizer for Windows released under GPL/LGPL. Has both UI, command line, and DLL, so that it can be integrated in own software.
