[cairo] Adding a boolean type

Carl Worth cworth at redhat.com
Tue Feb 1 07:11:14 PST 2005


On Tue, 01 Feb 2005 09:24:02 -0500, Owen Taylor wrote:
> But not adding some sort of public TRUE/FALSE defines publically 
> seems sort of a half-measure. And are we going to remember to add
> the defines if we add a usage of cairo_bool_t as a parameter?

Ah, boolean parameters. I tend to dislike boolean parameters
entirely. The problem is that code gets very hard to read, (and harder
to write), when it has calls that look something like:

	some_function (..., TRUE, FALSE, TRUE); [*]

To avoid them, I generally create enums, even when we "know" we only
expect two possible choices. See, for example, cairo_fill_rule_t and
cairo_font_weight_t. This makes the calling code much more
self-documenting.

It would be even better if the compilers were more strict about
type-correctness when passing enums around. I can't seem to find a -W
option in gcc to complain about that.

-Carl

[*] And, note that cairo also tries to avoid long parameter lists in
general, which also helps alleviate this problem.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20050201/e8dcea79/attachment.pgp


More information about the cairo mailing list