-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started with Julia
Julia is a dynamic, high-level programming language. While it was designed to dethrone Python and R in data science/machine learning, it still remains a general purpose language. It is designed to give users the speed of low-level languages like C/C++, while remaining as simple to understand and learn as Python. Julia achieves its speed through JIT (just-in-time) compilation at runtime using LLVM
framework.
"Julia is a high-level, dynamic programming language, designed to give users the speed of C/C++ while remaining as easy to use as Python" - from article. This page will serve as a guide to the first steps in anyone's journey of learning Julia.
Why bother learning a whole new programming language when you are already very comfortable with Python? This is a question I was asking myself prior to beginning this project. I knew Python had a much larger community, more 3rd party libraries, more support, more tutorials - the list goes on. I was ready to completely rule out the use of Julia. After some thorough research, I found out that Julia is a much faster language thanks to its JIT compilation. It has great built in functions for linear algebra - no need to import numpy! - and makes great use of available resources like multiple cores. The key point of deciding on using Julia however was its ability to call on subroutines from other languages including FORTRAN
, C
and Python
!
- Great Resources
- Installation
- Execution
- Variables
- Arithmetic
- Strings and Chars
- Functions
- Modules
- Documentation
- More Advanced Topics
Learning a new programming language can be tricky, but the following are great resources to aid in your process of learning Julia.
- Official Julia Getting Started Guide
- Julia Tutorial on Youtube (I strongly recommend watching this video)
- Julia Data Science Basic Full Course
- Julia Inheritance
If you are on Mac and have Homebrew
, you can simply enter the following command into your terminal:
brew install julia
Note: There are a lot of dependencies
If you are on Linux, you can simply enter the following command into your terminal:
sudo apt-get install julia
The installation process is fairly simple. Download links can be found on the Julia website with stable releases being available for all major operating systems and architectures. Make sure to add Julia to PATH - instructions for each OS found here.
Enter the julia
command into your terminal. If your installation was successful, you should be in the Julia terminal with no errors occuring.
Julia files are specified with the .jl
file extension. To compile and execute a Julia file, type the following in the command line:
julia [filename]
Note: if file is not in current working directory you must include the relative path Passing in command line arguments can be achieved just as easily:
julia [filename] arg1 arg2 ...
Like in Python, Julia allows for variables to be declared with implicit types. For example, x = 5
, y = "Hello, World!"
, n = [1, 3, 4]
are all valid declarations. The basic integer and floating point types in Julia are Int8
, Int16
, Int32
, Int64
, Int128
, UInt8
, UInt16
, UInt32
, UInt64
, UInt128
, Float16
, Float32
and Float64
where Int
represents a signed integer, UInt
represents an unsigned integer, Float
represents a floating point number and the numbers after prefix represent their size in bits. For more info on variables in Julia, visit the Getting Started page in the Julia documentation.
Arithmetic operations are just as you'd expect, with some interesting unary prefix operators that you can read more about here. Comparisons are also very straightforward except the fact Julia gives them the power to be chained arbitrarily - read more here. Numeric conversions also work similar to that of Python, with a list of functions available here. Just below those conversions, you can find a list of all the useful mathematical functions built into Julia.
The type Char
in Julia is 32 bits and can represent any Unicode character in UTF-8 encoding. The type String
in Julia represents a finite sequence of these Chars. Like Java, these Strings are immutable. String slicing and indexing works very similarly to Python - read more here. The key feature the Julia brings to the table is the concept of triple-quoted string literals which allow you to define a String over multiple lines of code - read more here. Julia of course supports regular expressions, the details of which can be found here.
Functions in Julia can be defined through one of two main ways:
function f(x, y)
x + y
end
f(x,y)=x+y
Both function declarations are equivalent
The first is the conventional way, using the function
keyword, and the second is a more compact form. Interestingly, function names can be any unicode character. ∑(x,y) = x + y
is valid syntax.
You may explicitly type functions. For example, function f(x, y)::Int64
. You may also explicitly type parameters. For example, function f(x::Int64, y::Int64)
. Anonymous functions are also possible through Lambda expressions, like x -> x^2 + 2x - 1
- most commonly used when other functions take in functions as input (Julia has functional programming capabilities!). Arguments can be given default values and can be named just like in Python. Read more about the details of functions in Julia here.
Modules are used to organize your Julia code into separate units. Each module has a name, and defines its own exports and imports. Exports are what other modules that use this module can call. They are specified with the export
keyword. Imports are all the modules being imported and used in this module. There are two keywords for importing other modules, using
and import
. To read about the differences of those two keywords, or any other info on modules in Julia, follow this link.
Julia provides developers with built-in support for documenting functions, types and other objects. Any string appearing right before(no empty line between) and object will be interpreted as a docstring. These documentations are interpreted as markdown text through the Markdown
standard library (see here for documentation). For more info on how to document your code and how to access your documentation, check out the Julia Documentation Page.
After having reviewed the fundamentals of Julia, and familiarizing yourself with its similarities and differences to languages you already know, you are ready to step into more advanced topics like Julia's Multi-Threading capabilities or Networking. The Getting Started Guide breaks down the learning of Julia into different topics, and is the best resource for studying these advanced topics in-depth.