On Thu, Jan 21, 2010 at 9:39 PM, Luis Lavena <luislavena / gmail.com> wrote:
> On Thu, Jan 21, 2010 at 9:57 PM, Hongli Lai <hongli / plan99.net> wrote:
>> [...]
>>
>>> * Provide another mechanism for querying specific features, like
>>> Platform.support? :fork
>>
>> How is this better than calling the method and catching NotImplementedError? Your
>> check method, although returning a boolean, still calls the method under the hood.
>> This makes #support? an expensive call which is something I wanted to avoid with
>> #fork_supported?.
>>
>
> I might be able to answer that.
>
> While experimenting with Rubinius and MinGW, I've created a C library
> that collected at compile time the related information of the
> platform, and exposed it as CAPI extension.
>
> That can, using extconf, #define, #ifdef etc the functionality exposed
> by the platform you're running on.
>
> In the case of JRuby, that Platform module can evaluate the underlying
> OS capabilities and return you true/false without the need of
> triggering NotImplementedError
>
> At the end, I believe both fork_supported? and Platform.support? :fork
> aim at the same, but the later can serve as API for other
> functionality, like symlink, hardlinks, etc.

Yes, you understand...this is why I proposed it. The general idea is
similar to the RUBY_ENGINE debates: a way to provide a "feature
enumeration" for users.

Using this code:

Platform.supported? :fork

...gives us the opportunity to handle specific keys in specific ways
*at runtime* rather than having to attach special behavior to all such
methods *at compile time*. And it does not require that we call fork,
since we can at least know some subset of names people are expecting
to have.

Based on what Tanaka has described about the C implementation, we
could comfortably implement respond_to? to always return true if we
define the method, regardless of whether it would raise an error or
not. Users should expect to rescue errors even if MRI does respond_to?
various methods, since the system itself may have stubbed them out to
produce errors. I'm not sure how the new behavior is actually useful.

- Charlie