lua-users home
lua-l archive

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


2011/12/16 Ezequiel García <elezegarcia@yahoo.com.ar>:

Looking at your example code ,they are basically all the same, in
terms of someone typing
it (they vary only by the presence and absence of a few chars, like
comma, single quote, { and }.

To decide, you need to write code that constructs the values you pass
in and get out to see which makes
your usage of the API easier or harder.

If you want highly readable code, where the input and output values
are strings, and mostly you just
 print output values to a console, using the style of
"flag,flag2,flag3" makes sense. But if you had to programmatically
construct and split those values all the time, you will quickly think
this API is too cute to be usable.

If you need speed, or commonly need to construct values quickly,
module numeric variables
makes sense, along with helper functions to convert to/from human
readable strings for debug purposes.

If you need to do lots of manipulations on input/output, clearing and
setting flags, and don't care
about peformance of lots of table creations, then tables with key=>bit
mappings make most sense:
  {flag1=true, flag2=false}

For what its worth, I've seen APIs that pass strings or tables of
strings, and I've seen apis that define names for numbers,
and pass numbers in, and I've seen keyword apis that use tables where
strings keys are true or false, but I've NEVER seen a lua API that has
strings concatenated together to represent flags... I think its weird.
YMMV.

Cheers,
Sam