Hello everyone,

I've just started to write a bit of code in Julia and I'm still exploring 
the best ways of doing this and that. I'm having this small problem now and 
wanted to ask for your advice.

I'd like to have two methods that retrieve some items. The first method 
takes the max number of items that should be retrieved. And the second 
method takes the max item id.

getitems( maxnumitems )
getitems( maxitemid )

In both cases the argument has the same type: Int. So how do I take the 
advantage of multiple dispatch mechanism in this situation? And is multiple 
dispatch really the recommended way of handling a situation like this one? 
Here're some alternatives that I thought of:

1. Use different function names: getitems, getitems_maxid. Not too elegant 
as you mix purpose and details of function usage in its name.
2. Use named arguments. This will cause the function implementation to grow 
(a series of if / else), again not too elegant.
3. Define a new type: ItemId which behaves exactly as Int but can be used 
to 'activate' multiple dispatch (one function would use Int and the second 
one would use ItemId). Generally not the best approach if you have methods 
each having an argument that should be really represented as an Int rather 
than a new type.
4. ...?

What would you recommend ?

Thank you,
ks

Reply via email to