Is the function a constructor if it uses convert (Julia)?
Reading BioSeq.jl source code I found that they use functions like this:
aminoacid{T<:Number}(value::T) = convert(AminoAcid, value)
These functions create a new type object by AminoAcid
performing a conversion. Is this function considered as a constructor (and therefore should be called AminoAcid
instead AminoAcid
)?
source to share
Functionally, yes, this method aminoacid
does the job of a constructor. This is especially true in light of the call forwarding improvements in 0.4-dev, where all types have very similar default constructor rollbacks toconvert
.
Julian's style seems to move away from these inline constructor functions, especially when they are just doing the conversion. See for example Issue # 9155: in 0.4, Symbol("foobar")
canonical? ...
Here's a good rule of thumb for when to use downstream methods ( Comment by Stephen J. Johnson on Interact.jl # 17: lowercase widget functions ):
The following versions, such as
int(...)
, are things that (a) are more coercive in conversions (no InexactErrors) and (b) may not return the appropriate type. for exampleint([1.0, 3.7])
works and returns an array of integers. See also JuliaLang / julia # 1470 .
source to share