On Friday, April 15, 2016 at 6:40:37 PM UTC+8, Tim Holy wrote:
>
> If in contrast item[i+1] has a different type than item[i], and the amount 
> of 
> processing is quite modest, then it may not be worth it. Because julia 
> can't 
> predict the type at compile-time, it has to look up the type at run-time, 
> search for the appropriate method in method tables, decide (via type 
> intersection) which one matches, determine whether it has been 
> JIT-compiled 
> yet (and do so if not), and then make the call. You're asking the full 
> type- 
> system and JIT-compilation machinery to basically execute the equivalent 
> of a 
> switch statement or dictionary lookup in your own code. Julia can do this, 
> but 
> it's a lot of churn under the hood. If this is the situation you're in, it 
> seems likely to be better to just write that switch statement or to use a 
> dictionary. 
>

Hi Tim, 

Thanks for writing this. I am finally starting to write some serious Julia 
code and I am in exactly the situation you described above. It is kind of 
depressing to read what you wrote, but it makes sense I guess. Now I need 
to rethink my strategy.

It's probably obvious, but could you or someone else help elaborate on 
"just write that switch statement or use a dictionary"?

What is the best way to deal with this situation?

Basically, I have a long list of concrete objects "PriceableType1", 
"PriceableType2", etc, all subtypes of "AbstractPriceableType" and I have a 
different "Price" function for each different concrete time that dispatches 
as I run through the list to come up with the price of the list.

Should I make methods "priceType1", "priceType2", etc and just switch based 
on "typeof" rather than use dispatch? :(

Thanks again and have a great weekend!
Eric

Reply via email to