DEV Community

Cover image for Go is not OOP
Python64
Python64

Posted on

Go is not OOP

Go is a programming language that was created as an experiment.

If you programmed in languages like Java, C#, C++ or Python you may be used to having classes and objects everywhere in your code.

It may surprise you that Golang is not object orientated. In fact, Go intentionally leaves out many features of modern OOP languages.

  • No classes. All code is split into packages. Go has only structs.
  • No support for inheritance
  • No Execeptions
  • No generics
  • No annotations
  • No constructors

Everything is just a little bit different, but it's a very powerful language that is great for concurrency.

In 2009 Go came around, during that year multi-core processors were already available. Go is designed while keeping concurrency in mind.

Go has goroutines instead of threads. You can run as easy as

go function()

Compare that to threading in Java! You can spin millions of goroutines at any time.

  • Goroutines have faster startup time than threads.
  • Goroutines use channels (a built-in way to safely communicate between eachother).
  • Goroutines and OS threads do not have a 1:1 mapping. A single goroutine can run on multiple threads. Goroutines are multiplexed into small number of OS threads.

Top comments (2)

Collapse
 
fernandosolivas profile image
fernandosolivas

Python64 nice explanation about Go but I have some considerations.

Only inheritance is a characteristic of OOP because in Go, Composition have prevalence over inheritance. With that said, Go can achieve Polymorphism, Abstraction and Encapsulation.

I can agree, Go isn't a language naturally designed to OOP but you can achieve at least the most important things of OOP, so in my opinion.

Go is awesome, we just need separate concepts from languages characteristics.

Collapse
 
juniorrubyist profile image
Joseph Geis

And this is why I’m sticking to python πŸ˜€