Julia, a Promising Language for Scientific Computing
2015/06/17I have been learning about Julia for two weeks, and I really like it. For this summer, I'm doing research on machine learning for classifying fetus' health based on its heart rate. I was given lagacy code for feature extraction, which was written in Matlab. The organization of the source code was pretty messy. Many files are scatter all over in a single folder. As a result, It took me two weeks to clean up and make sense of it. In the process, I realized Matlab itself has contributed to this mess too. First of all, It doesn't have a good package system, where functions can be grouped together in a single namespace. Secondly, the type is not explicit, so checking type is real hassle; I think type is important, because it guarantees what a function does and also helps understand it. But this is not a big deal, if programmer only write small piece of code, which I think it's common for those who programm in Matlab. For a moderate-size project like the one I was given, Matlab is not suitable. Plus, It's closed source!
As a result, I searched for other alternatives. I have used Python for implementing machine learning algorithms before. It was decent language, but for me It doesn't have a natural feeling of a scientific computing like Matlab. The reason might be that Python is not specifically designed for scientific computing. It is designed as general purpose and it is used in many fields, like web programming, scripting, etc. So when I program in python, I think of numbers less, and more often I think of objects and other computer science specific things. Not to say, computer science knowledge hinder me do scientific computing; only some of them do. There are features of Python that I like, for example list comprehesion, fairly good support for doing functional programming.
That's when I found Julia. I have heard of Julia in 2014. It was posted on hacker news. I remember there is quite a enthusiasm about it on the forum. It claimed to be a high performance and easily parallelizable language, which are critical for scientific computing. But I didn't get into it too much. This time is different, I need a good language to start my summer research. So I decided to check it out. It turned out Julia is great. After reading through its documentation, I really like the language. To me, It combines best features from Python and Matlab. Julia has feeling of scientific computing like Matlab, for example matrix can be easily expressed, function overload is much like what happens in math. One thing strikes me most is its type system. It's a well designed type system, which makes program written in Julia rigid and predictable. There are many other things I like about Julia, like list comprehesion and functional programming to name few. I didn't really checkout its performance and parallel computing capacity, but I did feel it's faster than Matlab!
Let see how a function(subroutine) can be written in Julia. This is a piece of code I wrote for predicting class label with parameters:
Even though this is just three lines of code, It has a lot of information in it. The first line is computing the product of selected elements in a array. The second line is computing probabilities of different labels using list comprehesion. The third line is one-liner if-else statement to get element with maximum probability. All these can be written in loops, but "Life is too short to spend writing for loops"(on Matlab office website page before). And also I think code like this prevent visual noice of all the loops and details, and let us focus on what the code is intended to do, thus increase the readability. Like math formula, one single formula can have huge amount of information. One line of code like this has huge amount of information. But once you get used to it, you will understand it much more quickly.
Julia is still in its early phase. As a language with only 3 years old, it is actively developing. The source code is actually hosted on github, and one can easily find it by googling. I have been reading its source code, which appeared very complex for me. I'm still learning, and I wish one day I can contribute to this great project.