Interesting. I come from R, and one of the main advantages I feel Julia has
is that I do not have to do any in-function testing of what types of
arguments the user has passed into the function, generating error messages
etc. In Julia, all of this is handled automatically if I specify a function
argument.

I would think the ideal way of doing it would be to specify a function
argument with a broad type (e.g. Number) that is meaningful for all the
operations in the function, and prevents the user from e.g. passing in a
string and getting a weird error message, or a bool and getting something
spurious. Unfortunately, most of my functions do not take simple types,
they take Vectors, and a Vector{Int} does not inherit from a
Vector{Number}! - meaning that the whole idea of inheritance is a bit lost
for me. I guess I can do foo{T <: Number}(a::Vector{T}) but that goes very
far from the easy non-specifying format that you support.

In short, I am really confused about how to use types well in Julia
functions - and I did read the style guide. Can you guide me a bit more
towards a good approach?

Thanks

On Wed, Jan 6, 2016 at 1:27 PM, James Gilbert <jgrgilb...@gmail.com> wrote:

> You'd think, reading this forum, that the preferred style is to specify
> the type of function arguments. I think that's what feels right for people
> with experience in other languages. Specifying argument types doesn't
> necessarily improve speed, and harms the reusability of code.
>

Reply via email to