How I am learning Go and Julia Together
Tags: Data Science, Julialang, Programming Languages, Golang, Data Engineering

I will start a simple python problem and will see how we can design it in Julia and Go. If you are a beginner programmer and Do not know Object Oriented Programming you might want to read about OOP in Python before you go further.

Let’s say we have a database of article where each row represent a article and it has five columns (think as it is stored in a sql database) Content, Link, Title, Image (CDN link of image) so we want to read any article and hold it into memory and implement some operation on the attributes, How we design that in Python?

class Article:

def __init__(self, content, links, title, image):

self.content = content

self.links = links

self.title = title

self.image = image

I would create an object where I pass my data and implement some methods on it. So how we create an instance of an object:

# an instance of the the Article Object

go_n_julia = Article(

content="How I learn go and Julia Together",

link="https://asdasdasdasdf.com/go-julia....",

title="Modern Languages",

image="https://aws.amazon.com-us-west....."

)

Now Go and Julia does not have these principle. In Julia we have to define our own type and Create a value of that type.

# Julia Version of Implementation struct Article

content::String

link::String

title::String

image::String

end

"How I learn go and Julia Together",

"

"Modern Languages",

"

) go_n_julia = Article("How I learn go and Julia Together", https://asdasdasdasdf.com/go-julia ....","Modern Languages", https://aws.amazon.com-us-west ....."

So as in Go, It will be the same concept. Create your own type and create value of that types to hold custom data:

// Go Version of Implementation type Atricle struct {

content string

link string

title string

image string

} // Here we are using short deceleration variable signature :=

"How I learn go and Julia Together",

"

"Modern Languages",

"

} go_n_julia := Atricle{"How I learn go and Julia Together", https://asdasdasdasdf.com/go-julia ....","Modern Languages", https://aws.amazon.com-us-west .....",

So switching from Python to Go and Julia What have changed?

Object (changes to) →Type (struct signature)

Instance of Object →Value of Type

Moving from Julia to ( →) Go What have changed?

The signature definition: struct Article … end → type Atricle struct {} but they are both new defined type

→ but they are both new defined Primitive type deceleration inside of struct :: →nothing

→nothing Creating a value: Article() → := Atricle{}

But the design principle will be same in Go and Julia. If we want to switch from python to Julia and Go. We have to switch our thinking from Object Oriented to Type Oriented, I call it Data Oriented programming. Instead of defining methods for Object in Python, we have to define methods for types in Julia and Go. As both Julia and Go are not object oriented, object inheritance will be replace by type Inheritance and Polymorphism will be our primary interest.

Lets see another example How we can attach some method to some type in both language. Lets implement a show title method in python object which will print the name of the article when calling.

class Article:

def __init__(self, content, link, title, image):

self.content = content

self.link = link

self.title = title

self.image = image



def show_title(self):

print(self.title)





go_n_julia = Article(

content="How I learn go and Julia Together",

link="https://asdasdasdasdf.com/go-julia....",

title="Modern Languages",

image="https://aws.amazon.com-us-west....."

)



go_n_julia.show_title()

Here we have defined a function called show_title which print title of the article. Lets implement it Julia and Go.

# Implementation In Julia struct Article

content::String

link::String

title::String

image::String

end # a::Article ensure that the function can only except a value of

# type Article function showTitle(a::Article)

println(a.title)

end

"How I learn go and Julia Together",

"

"Modern Languages",

"

) goJulia = Article("How I learn go and Julia Together", https://asdasdasdasdf.com/go-julia ....","Modern Languages", https://aws.amazon.com-us-west ....." showTitle(goJulia)

To make a full functional call in go, we need to add few convention to the program for example adding package main , assigning variable and then declare it inside of main function. But still the concept is same, we can attach method to functions.

package main import "fmt" type Atricle struct {

content string

link string

title string

image string

} // define a variable goJulia of type Article var goJulia Atricle // the function name is showTitle() but the (a Article)

// ensure that it is attached to only value of type Article func (a Atricle) showTitle() {

fmt.Println(a.title)

}

goJulia = Atricle{

"How I learn go and Julia Together",

"

"Modern Languages",

"

} func main() {goJulia = Atricle{"How I learn go and Julia Together", https://asdasdasdasdf.com/go-julia ....","Modern Languages", https://aws.amazon.com-us-west .....", goJulia.showTitle()

}

So what is the difference in Go and Julia for defining Methods?

Function signature: function name(receiver::type) … end vs func (receiver type) name(){...}

vs Executing method: methodName(value) vs value.methodName()

There are so many differences exist in both language though, but here I was trying to find the common ground to make my learning smooth and easy.

When writing Julia code we always need to think about Multiple Dispatch which has a vital role in Julia on the other hand where in Go we have to think about Pointer and Interfaces. Julia offer mutable and abstract struct but go offers pointers and interfaces for struct (Julia has the concept of using interface but not used widely). Also there is major differences in how the code execute and compiled in both language. But here my point is,

Can you learn the both language together? and The answer is Yes. As both of them are not object oriented rather type oriented language and That common ground makes design thinking very similar in Go and Julia. If you know one Slavic language it’s easier to get another.

I usually use python for everything Data Processing, Analysis, Machine Learning and Web Application (Flask). But I am hoping end of the year, I will be able to move my Data Science stack to Julia (Analysis, Modeling, Visualization) and Data Processing, system programs, CLIs, Streaming, ML model deployment and Web application to Go successfully.