Annotating function arguments

In a statically typed language without any polymorphism, such as C or Fortran, every argument must be specified with the exact type. Julia, however, is dynamically typed and supports duck typing—if it walks like a duck and quacks like a duck, then it is a duck. Type information is not required in the source code at all. Instead, the compiler looks at runtime types that you pass into the function and compiles the appropriate method specialized for those types. The process of deducing types throughout a method body based on the argument types is called type inference

Therefore, there is no need to annotate function arguments with type information at all. People sometimes get the impression that putting type annotations all over their Julia code will improve performance. That is not usually the case. For method signatures, types have no effect on performance: they are only useful to control dispatch.

So, what would you choose? Annotate arguments with types or not?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.142.146