DEV Community

jones268
jones268

Posted on

what's the advantage of golang instead of java or C# ?

#go

There are a few reasons why I prefer Go over Java and C#, not least of which is the standard library. You can install plenty of packages to do almost anything you want, but Go's standard library is minimalistic and very readable (what is golang?).

The big advantage of golang is that the code is less verbose and easier to read and write. The syntax is easier than java, and borrowing some syntax from python make it more natural for me than C#.

package main

import "fmt"

func main() {
    fmt.Println("Hello World!")
}
Enter fullscreen mode Exit fullscreen mode

What is Go?

Go is a programming language (golang) with a culture that is growing out of the love for software tooling. I'll say that again. Go was built from ground up with the singular purpose of creating an ecosystem of reusable tooling that serves as the foundation for the language itself.

Go is a language that is powerful enough to be the foundation of such things as the Docker system, but simple enough that you can learn it quickly.

Why Go?

To be honest, the real reason I start to use golang is that it's supported by Heroku (and has a free tier) and DigitalOcean (not free). That make it very easy to try, with almost no cost.

If you try go in production, you'll probably have a little cost. At least it's possible to pay 0 if you're lucky (0$/month and 0$/hour for its free plan) and that's great.

Go is also very easy to learn if you know another language such as java or C#.

Go is really focused on back-end development. For front-end you can use something like Angular or Vue

Top comments (7)

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

There’s another huge advantage to Go over C# and Java that I often do not see mentioned: It does not require a special runtime on the target system.

Java needs a JVM install, C# needs a CLR install (usually .NET, sometimes Mono), but if you build things right, Go needs absolutely nothing beyond the basic OS.

Collapse
 
rhyek profile image
Carlos González

Not sure about Java, but dotnet apps can be self-contained (they include the runtime) and you can now do trimming to lower the resulting file size somewhat. Nevertheless, this is usually not a concern since having a runtime ready to run your compiled application is pretty much a ubiquitous practice empowered by docker.

Collapse
 
jcbritobr profile image
Júlio César de Brito Gardona • Edited

Its a different thing. Golang compile directly to machine code. Self contained executables in dotnet uses the clr embedded to final deploy. Go solution is very small and statically compiled.

Thread Thread
 
coen_c7a57bc84f2f2 profile image
Coen de Wit

Dotnet can be compiled to machinecode for most platforms too. But the self-contained, compiled AOT and trimmed file is still quite a bit larger than a Golang package.

Collapse
 
avinersan profile image
Andrei Vinersan

My opinion is that go is most of the time better performing out of the box although .net core 5 might be quite close.
However I think that go is way more verbose and has way less features/extensibility.
Major things that I lack in go are generics, typed attributes/annotations, DI, linq, automatic open api (swagger) generation based on types (Goa is probably closest but not the same), extension methods, object equality/hashing override, string interpolation and there are probably many others.

On the other hand go arguably offers a nicer experience with goroutines (no need to spread async/await everywhere) and is probably easier to learn as it has less features.

Collapse
 
kevinmiles_20 profile image
kevinmiles

When it comes to performance, a benchmark is better than one person's opinion, because we all have our personal preferences of course.
For example:
benchmarksgame-team.pages.debian.n...
This shows that sometimes Go is faster, sometime C# is faster, depending on what you are doing.

I prefer C# because it gives me a choice from a wide range of language features. More than I need sometimes. But at least I have these features available to me, if I did need them. So for example, LINQ is there, but I don't have to use it. But I can't imagine using a language that lacks generics, that would be a big leap backwards.

I came from a C++ background and it took me one week, on the job, to become a productive C# developer. I was choosing to use the basic language features and that was fine for what we were doing.

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

You can use a Dockerfile in Heroku as well. No need for buildpacks.