> 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.

Excellent, welcome aboard!

> 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.

For dispatch to work you have to use #3.  By the same logic you use in
#1 this is good: a 3 of ItemId has different "units" to a 3 of
maxnumitems.  For instance, you shouldn't be able to do ItemId +
maxnumitems.  Using different types gives you that and is the most
Julian approach but #1 and #2 work fine and might be the right solution
at times too. Note that a type such as

immutable ItemId
 id::Int
end

is as performant as an Int.  (also note the spelling of variables: types
are in CamelCase, values in lowercase with _)

Reply via email to