Good advice comes with a rationale so you can tell when it becomes bad advice

Raymond Chen

A customer asked for guidance in software design:

Is there an issue with creating and using COM objects from a UI thread which was initialized as STA? I have heard that it is a best practice to create and use COM objects on a background thread which is MTA. I would like to have some more information as to why. Any help?

(I still have trouble with the phrase best practice, especially when it is combined with the indefinite article: a best practice. It’s like asking “Where is a tallest building?”) Good advice comes with a rationale so you can tell when it becomes bad advice. If you don’t understanding why something should be done, then you’ve fallen into the trap of cargo cult programming, and you’ll keep doing it even when it’s no longer necessary or even becomes deleterious. In fact, you will find that if you try to follow this advice to the letter, most shell objects will stop working, because shell objects tend to require an STA. But in the absence of a rationale document or any other context, it’s unclear what the scope of the original advice was. Maybe it makes sense in context, but right now it’s just a statement with no discussion or rationale. When I asked the customer, “Can you provide the documents that provided this recommendation? Perhaps this ‘best practice’ makes sense in context. Right now, it’s just a bare recommendation with no discussion or rationale.”

The customer never wrote back.

0 comments

Discussion is closed.

Feedback usabilla icon