Why I prefer Julia‘s language design more than Matlab’s and R’s
- Unlike Matlab, it uses
[i]for array/vector/matrix indexing. | Matlab uses
- Unlike R, it uses
=as the assignment operator. | R uses
- Unlike in R,
.has a real meaning in Julia.
- Unlike in Matlab, we don’t need to put
;in the end of statement. | In Matlab, we have to put
;to suppress printing values.
- Unlike in R, matrix declaration is simple and convenient.
- Unlike in R, matrix operation is simpler in Julia.
- Unlike in Matlab, we can easily write inline function (without creating new file) in Julia
- Unlike Matlab and R, array values are passed by reference.
- Unlike Matlab and R, function arguments can be type-assigned.
As a programmer who has written code in a dozen programming languages, it’s good to have consistency across different languages. 1) , 2) , and 3) are mainly to get the consistency. I often made mistakes when writing R or Matlab code because of the inconsistencies.
4) 5) and 6) are mainly for convenience. Consider these examples:
A <- matrix(c(1,2,3,4,5,6,7,8,9), nrow=3, byrow = TRUE) sol <- eigen(A) AA <- sol$vec %*% diag(sol$val) %*% t(sol$vec)
A = [1, 2, 3; 4, 5, 6; 7, 8, 9]; [V, L] = eig(A); AA = V * L * V';
A = [1 2 3; 4 5 6; 7 8 9] l, V = eig(A) AA = V * diagm(l) * V'
Lastly, covering 7) 8) and 9), let’s write an example of function definition in Julia
distance(x::Number, y::Number) = abs(x - y) distance(x::Vector, y::Vector) = sqrt( sum((x - y).^2) ) a = distance(1, 2) # call distance(x::Number, y::Number) method b = distance([1,2,3], [1,2,4]) # call distance(x::Vector, y::Vector) method