A.I. Tools

# Embracing Julia: An Invitation Letter | by Essam Wisam | Oct, 2023

## Warmly Extended to Python Lovers, Scientific Computing Wizards and Data Scientists

Julia is a general-purpose, dynamic, high-performance and high-level programming language that is just-in-time compiled. It’s a fairly recent language with its major 1.0 release rolled out only in 2018. In this story, we aim to demonstrate that this language is absolutely worth adding to your arsenal if you are into data science, scientific computing or are just an avid Python user. It may be true that this is most beautiful programming language you will ever come across.

In this story, we will go over the heights of ideas with Julia and why it’s worth learning. Once you are done, we highly recommend you check the next story From Python to Julia: An Ultimate Guide for an easy transition from Python to Julia.

· Julia is High-level∘ Basic Syntax∘ Elegant Syntax for Mathematics· Julia is Fast∘ Benchmark∘ The Two Language Problem∘ Julia is Just-in-time Compiled· Julia Solves the Expression Problem∘ The Expression Problem∘ Multiple Dispatch∘ Abstract and Concrete Types· Julia is Fully Featured∘ Array Support∘ String Support∘ Multi-threading∘ Easy Integration with C Code∘ The Standard Library· Julia is General Purpose∘ Introduction∘ Automation and Scripting· Julia is Extensively Extendible∘ Introduction∘ Macros· Wrapping Up

The introduction already may have made you feel that this will be like Python — a general purpose, dynamic and high-level language as well. To verify, let’s get a taste how basic Julia code looks like compared to Python.

## Basic Syntax

Consider the following guessing game in Python:

import random

def guessing_game(max):random_number = random.randint(1, max)print(f”Guess a number between 1 and {max}”)while True:user_input = input()guess = int(user_input)if guess < random_number:print(“Too low”)elif guess > random_number:print(“Too high”)else:print(“That’s right!”)break

guessing_game(100)

The following is the equivalent in Julia:

function guessing_game(max::Integer)random_number = rand(1:100) println(“Guess a number between 1 and \$max”)while trueuser_input::String = readline()guess = parse(Int, user_input)if guess < random_numberprintln(“Too low”)elseif guess > random_numberprintln(“Too high”)elseprintln(“That’s right!”)breakendendend

guessing_game(100)

Main differences here are that Julia does not assume any indentation or require colons but instead requires an explicit “end” to end scopes for constructs such as if-conditions, loops and functions. You should feel right at home with this if you come from Matlab or Fortran.

Another difference that you may have noticed is that Julia naturally supports type annotations in variable declarations, function arguments (and return types, although rarely used). They are always optional but are generally used for type assertions, letting the compiler choose the right method instance to call when the same method is overloaded for multiple types and in some cases of variable and struct declaration, for performance benefits.

## Elegant Syntax for Mathematics

# Elegant Expressions x = 2z = 2y + 3x – 5

# Official Unicode Supportα, β, γ = 1, 2, π/2

# one-line functionsf(r) = π*r^2

f'(3) # derivative (with Flux.jl package)

# Column vector is literally a columnv₁ = [1234]

v₂ = [1 2 3 4]

# transposeprintln(v1′ == v2)

# This is literally a 3×3 matrixM⁽ⁱ⁾ = [1 2 34 5 77 8 9]

# Explicit modeling of missingnessX = [1, 2, missing, 3, missing]

One serious edge that Julia has over Python is syntax support for mathematics. * need not be used when multiplying constants by variables, latex symbols are supported for variable names (may need to use a VSCode extension to convert \pi to π, v\_1 to v₁, etc.) and matrices in general respect the layout in the code definition.

For instance, if you were to implement gradient descent for a neural network.

Check Also
Close
Translate »