From Java to Google Golang - it's that easy!

Google has developed its own programming language and we highlight the advantages over Java.

We explain what changes and improves the transition from Java to Golang for developers

// navigation

Blog


// content

Keep it simple

Google's own programming language, Golang, is still young and unknown. Whoever knows her loves or hates her. We introduce Google Golang in this short article.

My Curriculum Vitae

For the last few years, I had completely embarked on programming java . Java was the only language taught in my dual bachelor's degree program , and in the company I worked in at the time, Java was also the dominant language . For two years, I worked full-time as a Java Developer, and was not so quick to reorient myself. The practical part of my Master Thesis , a Question Answering System , was developed entirely in Java using Spring as the framework. After my studies I was looking for a new job, also as a Java developer. Originally. But then everything changed ...

What are the benefits of Google's Golang?

I've been assigned to a developer team that primarily uses Google Golang , or Go for short. I had looked at the language shortly before in the main features, because the entry into this team was an option in the room. And the first thing I noticed: everything wrong! From Java, I knew that variables and constants are at the beginning of their type, followed by the name and assignment. In Go, the guy is behind the name. public and private variables and methods can all be forgotten, visibility is case-sensitive. Classes and Interfaces do not exist in the form known from Java even though I like to say a go-file class for lack of a better term.

The simpler, the better.

At Go, everything works according to the principle "The simpler, the better". And that is a principle that I gladly accepted! If you have been working for a while with Java Spring Boot you can google it very efficiently and know every nose on Stackoverflow. There is hardly a problem that is NOT searched and handled on Stackoverflow . Most of the time the solution to the problem always seems quite simple: Do the & nbsp; @ AnotherAnnotation over & nbsp; Method / Class / Constant / Interface, and there's quite a bit of magic happening somewhere in the background strong>. It's like putting a horde of Hogwarts first-graders in the Great Hall and teaching them to Apparate. Something will happen already. Only what, you can not see that exactly.

Go has no frills . All the basics that the programmer needs are learned in a few easy-to-understand tutorials and then the world is open to you. Like a week Dumbledore Quick Internship . Once you have understood the principle of Slices and Pointern , you could also program completely without Google and Stackoverflow. Anyone who thinks he gives up functionality is wrong. What could you secretly always want in Java? Right, return multiple values. And lo and behold: Go makes it possible! Almost every function (no, not method!) Returns an error in addition to the actual return value. Gone are the times of meter-long exceptions that you can catchen ignore or edit and throw away.

Conclusion on the programming language Go

What is the consequence of these things? Easy-to-understand code that gives the developer back the power over his work. No black box more, in which a lot of unnecessary magic happens, no overhead of classes you do not really need. What you need, you write yourself. Of course, there are extensions that can be integrated. But most of them are not monsters, they are small libraries that really only do what they have to.

All in all, I am very happy that I went back to basics. One likes to say, what should be done right, you have to do it yourself. This has been the case with group work at school, and the principle is even more true when it comes to programming. Therefore: Happy Coden!

Example Golang Code - all you need

golang


func Create(item database.Item) (*database.Item, error) {
dbAddress, err := database.GetDatabaseAddress()
if err != nil {
logrus.Error(err.Error())
}
db, err := gorm.Open("mysql", dbAddress)
if err != nil {
logrus.Error(err.Error())
return nil, err
}
defer db.Close()

err = db.Create(&item).Error

return &item, err
}

The above code is quite simple: it connects to a database, writes an item, and then closes the database connection again (defer moves execution to the end of the function). Note the two return values. The item is a pointer, the error is a normal struct.

Rating: 3.0. 2 vote(s).
2 anonymous votes
No rating done at all.
Your vote was '' (0 of 5) You are an anonymous user.
You may log on to do personalized votings
Click the rating bar to rate this item Please log on to do ratings

Kommentare

comments powered by Disqus