[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Defines/Enums/Flags in extensions



Quoting Robert John Andersen:
> The code that I'm writing the extension for uses defines, enums, and
> flags.
>
> [...]
>
> What have other people done, what do you think is the best way?

Here's the MrEd experience...

For the wxWindows bindings in MrEd 53 and earlier versions, we went
with integers for enums and flags, flag combinations via `bitwise-ior',
and top-level Scheme names bound to integer constants (such as
wx:const-align-bottom).

The code was difficult to read, and we'd get unhelpful error messages
when we confused numerical and flag arguments. The problems were
especially common in the editor toolbox's interface, where methods
often take a mixture of number and flag arguments. Also, I never liked
having so many little top-level bindings (or module imports,
depending).

For version 100, we switched to symbols (for enums) and lists of
symbols (for flags). I think it's been a significant improvement.

I can imagine tighter enum and flag mechanisms based on special opaque
values instead of symbols, but symbols are especially convenient, and
they've worked well enough so far for MrEd.

Sounds like you're already doing the right thing, IMO.

Matthew