Why I prefer Julia’s language design more than Matlab’s and R’s

Why I prefer Julia‘s language design more than Matlab’s and R’s

  1. Unlike Matlab, it uses [i] for array/vector/matrix indexing. | Matlab uses (i)
  2. Unlike R, it uses = as the assignment operator. |  R uses <-
  3. Unlike in R, . has a real meaning in Julia.
  4. Unlike in Matlab, we don’t need to put ; in the end of statement.  |  In Matlab, we have to put ; to suppress printing values.
  5. Unlike in R, matrix declaration is simple and convenient.
  6. Unlike in R, matrix operation is simpler in Julia.
  7. Unlike in Matlab, we can easily write inline function (without creating new file) in Julia
  8. Unlike Matlab and R, array values are passed by reference.
  9. 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:

R :

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)

Matlab :

A = [1, 2, 3; 4, 5, 6; 7, 8, 9];
[V, L] = eig(A);
AA = V * L * V';

Julia:

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
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s