lucy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marvin Humphrey <mar...@rectangular.com>
Subject [lucy-dev] Method access macros, Clownfish capitalization conventions
Date Tue, 17 Apr 2012 22:03:44 GMT
Howdy,

Seeing Nick generalize METHOD, SUPER_METHOD and OVERRIDDEN, I wonder if we
can't improve on them.  For example, here's a version of METHOD which allows you
to type the exact method name:

  /* Usage:
   *
   *   Obj_equals_t equals
   *      = (Obj_equals_t)METHOD(vtable, Lucy_Obj_Equals);
   */
  #define CFISH_METHOD(vtable, full_name) \
     cfish_method(vtable, full_name ## _OFFSET)

Or, perhaps even better, if we change the capitalization convention for the
"inside-out vtable" offset variables, we can autogenerate the cast:

  /* Usage:
   *
   *   Obj_equals_t equals = METHOD(vtable, lucy_Obj_equals);
   */
  #define CFISH_METHOD(vtable, full_name) \
     ((full_name ## _t)cfish_method(vtable, full_name ## _OFFSET))

I'm partial to that latter version.  The capitalization of the second argument
is currently misleading, but we can clear that up...

Right now, we differentiate between method invocation and implementing
function using capitalization.

    Lucy_Obj_Equals <---- method invocation
    lucy_Obj_equals <---- implementing function

This has proven confusing to developers; it would likely be clearer if we
spelled those differently instead.

                  | Current                | Proposed
   ===============|========================|=======================
   implementation | lucy_Obj_equals        | S_Obj_equals # static
   method         | Lucy_Obj_Equals        | lucy_Obj_equals
   typedef        | lucy_Obj_equals_t      | lucy_Obj_equals_t
   offset         | Lucy_Obj_Equals_OFFSET | lucy_Obj_equals_OFFSET

This means we would give up being able to autogenerate both
lower_case_with_underscores and lowerCamelCase from our method names reliably.

    Open_InStream => open_instream  # good
    Open_InStream => openInStream   # good

    open_instream => open_instream  # good
    open_instream => openInstream   # bad, the s should be capitalized

But this no longer seems as important as it once did because the method
binding interface that CFC has evolved allows easy overriding for rare
problematic cases such as open_instream.

Making such a change would generate a huge amount of codebase churn,
so let's think about it carefully. :)

Marvin Humphrey

On Tue, Apr 17, 2012 at 11:38 AM,  <nwellnhof@apache.org> wrote:

>         "#ifdef CFISH_USE_SHORT_NAMES\n"
> -        "  #define METHOD                   LUCY_METHOD\n"
> -        "  #define SUPER_METHOD             LUCY_SUPER_METHOD\n"
> -        "  #define OVERRIDDEN               LUCY_OVERRIDDEN\n"
> +        "  #define METHOD                   %sMETHOD\n"
> +        "  #define SUPER_METHOD             %sSUPER_METHOD\n"
> +        "  #define OVERRIDDEN               %sOVERRIDDEN\n"
>         "#endif\n"

Mime
View raw message