A Philosophy of Software Design

Walter Bright newshound2 at digitalmars.com
Sun May 24 05:57:09 UTC 2026


Microsoft is not wrong. You're not wrong, either.

But consider the copyright dates on the books: 1993, 2003, 2004. I know my ideas 
on what is better certainly have evolved over the years. A number of problems 
have come up with exceptions. I suppose it's like macros - they are a great 
idea, until you've used them for 10 years, and then they don't look so good.

Let's take Unicode again. The current method in Phobos is autodecode, which 
turned out to be a bad idea. It also throws an exception on malformed code points.

The first problem is you cannot use any string code in Phobos without supporting 
exceptions and memory allocations. The second problem is throwing an exception 
is the wrong solution.

Consider displaying text in your editor. Do you want the editor to throw an 
exception if the text has bad code points in it? Do you want the browser to 
throw an exception if the html has bad code points in it? No. Better to render 
the bad code point as the invalid code point.

If you really, really need to throw an exception, run the text through a 
*separate* filter to throw when it sees an invalid code point.

(Personally, I really do not want my string handling functions throwing 
exceptions. Like searching for a substring - what good would an exception be?)

Anyhow, I recommend checking the book I mentioned. It's only ten bucks! I'm 
pretty sure it will be worth your while.


More information about the Digitalmars-d mailing list