[PD-dev] class_addmethod2

Mathieu Bouchard matju at artengine.ca
Sat Dec 17 15:32:22 CET 2005


On Thu, 15 Dec 2005, Hans-Christoph Steiner wrote:

> I have to say that I like the A_FLOAT, etc names better (you can
> probably guess why).  Code should document itself.

A_FLOAT doesn't really tell you that it's an atom. "A" is an ambiguous
abbreviation of "ATOM". ATOM_FLOAT is better, but it's misleading because
it isn't a t_atom, it's a t_atomtype, so it should be called
ATOMTYPE_FLOAT instead. But then it doesn't tell you it's from Pd.
PD_ATOMTYPE_FLOAT could be confused with something else called Pd,
possibly another program's name or something else called "PD" inside of
another program. PURE_DATA_ATOMTYPE_FLOAT doesn't explain to you what a
FLOAT is, and anyway, FLOAT is jargon of the nerds; so
PURE_DATA_ATOMTYPE_32_BIT_FLOATING_POINT_NUMBER is already better, but
then not everybody knows what a floating-point-number is, so it should be
PURE_DATA_ATOMTYPE_32_BIT_RELATIVE_PRECISION_NUMBER.

> > >   class_addmethod(myclass, (t_method)myclass_mymethod, gensym("mymethod"),
> > >     A_POINTER, A_FLOAT, A_FLOAT, A_SYMBOL, A_DEFFLOAT, A_DEFFLOAT,
> > >     A_DEFSYMBOL, A_NULL);

It's far better to write this as:

object_class_add_method_declaration(
  my_pointer_to_object_class,
  (t_method_pointer)my_object_class_mymethod,
  generate_singleton_character_string_pointer("mymethod"),
  PURE_DATA_ATOMTYPE_32_BIT_RELATIVE_PRECISION_NUMBER,
  PURE_DATA_ATOMTYPE_32_BIT_RELATIVE_PRECISION_NUMBER,
  PURE_DATA_ATOMTYPE_SINGLETON_CHARACTER_STRING_POINTER,
  PURE_DATA_ATOMTYPE_32_BIT_RELATIVE_PRECISION_NUMBER_DEFAULTING_TO_ZERO,
  PURE_DATA_ATOMTYPE_32_BIT_RELATIVE_PRECISION_NUMBER_DEFAULTING_TO_ZERO,
  PURE_DATA_ATOMTYPE_SINGLETON_CHARACTER_STRING_POINTER_DEFAULTING_TO_EMPTY_STRING,
  PURE_DATA_ATOMTYPE_TERMINATOR_TO_ENSURE_THAT_WE_DO_NOT_BLUESCREEN_INTO_OBLIVION);

which is obviously a lot clearer, we all should agree.

 _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard - tél:+1.514.383.3801 - http://artengine.ca/matju
| Freelance Digital Arts Engineer, Montréal QC Canada




More information about the Pd-dev mailing list