Posts on general programming topics

published: Thu, 21-Jul-2005   |   updated: Sat, 6-Aug-2016

Here are the articles I've written with regard to general programming.

Double-Casting Anti-Pattern

There's a coding anti-pattern in C# that's very prevalent but inefficient. I'm going to guess its popularity is due to the fact that most C# developers have come to C# from a non-managed code language, such as C++ or Delphi. I'm referring to the double-casting anti-pattern. Read more...

Elegance in programming

Over the next couple of weeks, a small team of us will be going through a subsystem in our product to clean it up and to harden it against exceptional situations. It currently works, but when something goes wrong, it can fail in mysterious ways. We're also going to take the opportunity to do some much-needed profiling for speed and memory. The original subsystem was written in C# back in the day when the company hadn't much experience in all things .NET and I'm afraid it shows. Read more...

Using the Singleton pattern (part 1)

Whenever a couple of developers have a chat about Design Patterns next to the water cooler, the conversation is almost guaranteed to turn to the Singleton pattern. In fact, when two Delphi developers discuss Singleton, it's like they are talking about two different languages since Delphi can't do the basic trick of making a Singleton work. But no matter which language the developers use, they'll always talk about the implementation of it. Never, it seems, do they take a step back and wonder if Singleton is a "good" pattern to use. Read more...

To Underscore or Not to Underscore

Recently I've been involved in an effort to compile formal coding standards for the languages we use here at Configuresoft. We've had standards for some languages for some while (for example, our C++ standards have been complete for many years), whereas if you'd been developing in other languages you'd had to consult "race memory" (that is, look at what has been written before and mimic it). Read more...

Testing for equality with floating-point types

Every now and then, someone "discovers" that equality expressions using floating point types don't resolve into the correct boolean value. At least most of the time. (This is a requested reprint, updated, from my old Falafel posts.) Read more...

C# generics and covariance, part one

Time to blow your mind. You've downloaded Visual C# Express or maybe you're using the full Visual Studio 2005 beta 2. You've seen that C# 2.0 now includes generics, or a way of writing classes that accept type parameters. You've played around with List<T> and seen that it's pretty good. You're feeling comfortable with generics, right? (Updated  28-Jun-2005) Read more...

The need for basic Computer Science

Is it worth the time and effort for a self-taught developer to learn the basics of Computer Science? An unequivocal yes, in my view. Knowledge of the standard structures and algorithms will help anyone; but understanding how to analyze the behavior of your code will, to be frank, enable you to make it run faster and more efficiently. Read more...

Overengineering IOpenable

A week or so ago, I published an article about an IOpenable interface and OpenableBase class I'd been developing. I went ahead and posted the article despite a few misgivings: I felt as if I were missing something important about the code I was posting. I worked on the code a little bit afterwards but was unable to find out what was wrong. It took Mike Scott, an old friend from yesteryear, to point out that I seemed to be making it more difficult than it should be. He was quite gentle about it for a Scotsman, but in reality he should have beat me about the head with a haggis. Yes, gentle reader, I've been guilty of over-engineering. Read more...

Experiencing Delphi 2005

A couple of weekends ago I completed another article for The Delphi Magazine, this one on Dependency Injection and pico containers. For the article I made a good start on a pico container written in Delphi for Win32 (henceforth, called Delphi32). It wasn't all plain sailing, though. (Updated 18-May-2005)  Read more...

It's another exceptional post

Several things have turned up at work in the past few days, all related to exceptions in .NET. Heh, this blog certainly seems to be turning into a blog about exceptions. Read more...

The IOpenable interface

There seems to be a common pattern in some of the stuff I've been reviewing recently at work. In essence, there are several classes that implement some behavior such that an instance of one of the classes can be "opened" and then "closed" after use, after which it is no longer used. Also each class encapsulates a non-memory resource and hence needs a finalizer. A prime example of the resources being protected in this manner is a file, but others include sockets and the like. Read more...

Object-Oriented State Machines

In the March issue ofThe Delphi Magazine, I discussed refactoring state machines that had been implemented as giant case (or switch) statements into an object-oriented model. Essentially, the class model I used was the State pattern as described by the Gang of Four in Design Patterns. Anyway one of my readers sent me an email that made a valid point. Read more...

Aborting a Windows service start-up request in .NET

Yesterday we were debugging a Windows service written in .NET. The issue being debugged was that sometimes (it seemed to happen mostly on Windows 2000 Server, but not every time) the service would hang during stopping. After some work we found the bug and also found how to abort a service start-up request in .NET. Read more...

Asynchronous Exceptions

This article is an interesting email that was sent out to the CLR team at Microsoft about asynchronous exceptions. The email is, shall we say, information-dense. It's targeted at the Framework developers, but there are some ideas we can take from this as application developers. Read more...

Using FxCop

I've been code reviewing a part of Enterprise Configuration Manager (ECM) over the past week or so, mainly in an effort to help polish the code and also to identify possible problems before they surface and bite our collective butt. The part I've been involved with is the largest part that is implemented in C# and the .NET Framework. Read more...

Book source code uploaded

It seems that the Russian translator of my book has been promising more than he can deliver, namely that the source code to my book is available from this web site. Read more...

Function inlining

Last night, Delphi R&D gave a preview of Diamondback, the next release of Delphi. Lots of news, but there was one language change that got my goat. Read more...

Tests for the sorts from my book

Sometimes there's nothing for it but to write a comprehensive set of tests in order to check some code. I wrote such a test program to test all the sorts in my book. Read more...

Understanding programmer's block

We've all been there before. You're staring at the blank screen in your favorite editor, but you just don't know what to type. Nothing suggests itself. You're stymied. You have Programmer's Block. Read more...

Implementing interfaces and using TDD

Sometimes in TDD (Test-Driven Development), you find yourself having to implement an interface. At this point, you have to implement all the interface's methods, a clear violation of what TDD stands for. How do you get around this? Here's my technique. Read more...

Explicit interface implementations solved for Delphi 8

An example of why blogs work: a couple of days ago, I ran into a problem with Delphi 8 (or Delphi for .NET), blogged about it, and I got an e-mail with the answer. Now you all can see the solution too. Read more...

Explicit interface implementations in Delphi 8

There I was writing an article about Delphi 8 (Delphi for .NET) when I ran into a roadblock with an explicit interface implementation. Easy-peasy in C#; in Delphi..., well find out. Read more...

Using delegates and events in multithreaded apps

If you're using delegates or events in a multithreaded application, be aware of a small subtlety when you invoke a delegate and when you remove a method from a delegate or event. Read more...

Testing quicksort

Recently I was in an e-mail conversation with a reader of my book. He was trying to implement quicksort in a class of his devising using the implementation from the book. He was running into a problem where it wasn't sorting properly. Read more...

Generic Properties

On last week's Visual C# chat on MSDN, someone asked a question about generic properties: why weren't we providing them in C# 2.0? A little thought game can reveal one answer. Read more...

So, how do you code?

It's a valid question. Do you just put fingers to keyboard and type away as fast as you can, or is there method to your madness? Read more...

Julian's very first article

For a bit of fun, I've uploaded my very first published article. Check it out; if you can remember Turbo Pascal 6 and the program overlay manager (Borland called it VROOM), you'll feel really nostalgic. Read more...