[MacRuby-devel] book idea - "making it look like Ruby"

Charles Oliver Nutter headius at headius.com
Fri Feb 18 15:22:01 PST 2011


On Fri, Feb 11, 2011 at 4:08 PM, Rich Morin <rdm at cfcl.com> wrote:
> At 6:09 PM -0200 2/11/11, Caio Chassot wrote:
>> On 2011-02-11, at 15:25 , Matt Aimonetti wrote:
>>>
>>> Magically converting a snake_case method call to a
>>> CamelCase method dispatch is bad for peformance
>>> and documentation.
>
> It's not clear to me that there would be a significant
> performance impact.  It might be possible to do (most
> of) the translations at start-up time, avoiding much
> impact during execution.

In JRuby it currently has no performance impact. The camel_cased
versions are defined as aliases to the original. I forget whether we
define them as traditional aliases (wrapped by another structure) or
if we just bind the same method object under all names.

We have also debated making the aliases *redispatch* so that if you
wanted to replace them all you'd just replace the original camelCased
version. That turned out to be a perf issue in practice, so we backed
it off until we can come up with a nice way to have multiple names
resolve to the same method object.

FWIW, JRuby users would go ape if we took away snake_cased versions of
Java names. They love having everything look like Ruby, and I
personally think it helps the code flow a lot more naturally to have a
single style...not to mention you don't have to remember whether
you're calling a snake_cased or camelCased method...you just always
use snake_case.

> The question of documentation is also somewhat iffy.
> There is already a difference in appearance between
> the ObjC and MacRuby calling syntaxes.  Would merely
> allowing (ie, not requiring) the use of snake_case
> make this much problem much worse?

As far as I know, there's never been any confusion about snake_cased
aliases in JRuby. People read the JavaDocs, mentally switch to
snake_case, and proceed.

- Charlie


More information about the MacRuby-devel mailing list