« Return to Thread: Question on lazy val

Re: Question on lazy val

by David MacIver :: Rate this Message:

Reply to Author | View in Thread

On Fri, Jun 6, 2008 at 4:53 AM, Nils Kilden-Pedersen <nilskp@...> wrote:

> On Thu, Jun 5, 2008 at 5:03 PM, David MacIver <david.maciver@...>
> wrote:
>>
>> On Thu, Jun 5, 2008 at 10:53 PM, Nils Kilden-Pedersen <nilskp@...>
>> wrote:
>> > On Thu, Jun 5, 2008 at 4:17 PM, David MacIver <david.maciver@...>
>> > wrote:
>> >>
>> >> It will. instanceof is pretty quick these days.
>> >
>> > Everything is relative. I work with code where we sometimes do
>> > microsecond
>> > optimizations.
>>
>> The way to get microsecond optimisations out of anything like this is
>> "don't use the language feature. Roll your own evaluation strategy
>> that will be better suited to your needs". If you arrange it right an
>> instanceof check is about two instructions. That's pretty quick by any
>> metric which involves writing for the JVM. :-)
>>
>> > Why exactly would it be needed?
>>
>> Because you need to distinguish between the case where you have a
>> value and the case where you have a thunk waiting to be a value...
>
> A boolean or int won't solve that?

I'm not sure how to answer this question. I get confused by questions
of the form "Why do you do it this way? Couldn't you have done it a
more complicated way instead?"

 « Return to Thread: Question on lazy val