[cairo] Adding a boolean type
Carl Worth
cworth at redhat.com
Tue Feb 1 09:12:43 PST 2005
On Tue, 01 Feb 2005 10:42:41 -0500, Owen Taylor wrote:
> Don't those two things go in opposite directions?
To some extent, yes.
> I could agree with
> the statement "a function with more than two parameters should never
> have boolean parameters".
That certainly seems a useful rule of thumb.
> But something like:
>
> gtk_color_button_set_use_alpha (color_button,
> GTK_COLOR_BUTTON_NO_ALPHA);
>
> feels pedantic.
I see your point. But there are still some games that can be played in
cases like this. It's a matter of getting the right information
balance between the function name and the parameter value names.
I don't know the details of gtk_color_button_set_use_alpha, but let me
demonstrate what would be an equally ugly function call for cairo:
cairo_set_use_winding_fill_rule (cr, CAIRO_WINDING_FILL_RULE_NO);
I think we can both agree that's awful, yet it can still be re-written
to avoid a Boolean parameter, as it currently is in cairo:
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
And compare to a straight Boolean version:
cairo_set_use_winding_fill_rule (cr, FALSE);
The set_fill_rule variant is not significantly more to type, but is
more descriptive of what the "false" option actually is,
(eg. describing things in terms of what they are rather than what they
aren't). And this is extensible if we ever invent a fill rule beyond
the two standard rules, (not that I ever expect to, but the
extensibility can help in other cases).
I won't claim to know how representative this example is for
everything we'll want to do eventually.
> Anyways, if your confident of the lack of need for
> boolean parameters in Cairo, I guess I can't object to omitting
> cairo.h #defines for now.
I never say never. But we've certainly avoided them so far.
-Carl
-------------- 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/f7eb0a60/attachment.pgp
More information about the cairo
mailing list