I came to Go from Ruby but I've been writing mainly Go for quite some time now and I forgot how it was to work on a Ruby project. For those doing this daily, with PHP, Python, Ruby, JS, ..., do you feel that there is a huge productivity gap between those languages and Go when dealing with web applications? (server side rendering)
As a beginner I want to satisfy myself that I am going on right path.
Videos
So I wrote an app a few weeks ago that had a frontend written in Alpine JS and PHP on the BE. I used PHP because I wanted something easy to deploy (typically use Ruby for web dev). I decided to port it to GO for fun because I did a bit of go before.
It took 3x as many lines as PHP! 3x as many. Crazy. That's partly because you can't have 1 line if statements with my linter and because of all the error handling.
BUT, what I noticed is that even though it's much more verbose the cognitive load with GO is SO MUCH LOWER.
I love to code and have been doing it for 25+years but I realize that sometimes when I have hard features to code I sort treat it like a mission I have to go on. I know it's going to be stressful and unpleasant.
With GO however it all seems pretty easy. For one the fact that it's staticly typed is a lifesaver. I'm used to that with C++ and Java though, but the way Fiber handles taking your POST JSON and sticking it into a struct is great. You don't have to wonder "wait, is this actually a string when I thought it was a number?" That really mitigates a lot of the stress of building webapps. That communication layer between FE and BE can be a pain.
I feel like my mental CPU clock just stays at 15% instead of averaging 50% and spiking up to 100 frequently (sort of like GO vs Node on a server). I just can't get past that. Even though the language itself is nothing special. It doesn't even have ternaries, but I can always look at the code and it's basically as simple as it gets.
Idk, writing go I just feel a big weight has been lifted off of my shoulders, I don't mind the stress of programming, I enjoy the fight but now I'm like "huh, I'm really productive and I'm not stressed at all..."
As I mentioned earlier I used PHP because it's easy to deploy. Well... GO is not QUITE as easy to deploy as PHP, you can't just stuff your files on a shared host BUT I've been deploying to a DO node by just FTPing in and dropping my self contained executable. That's really, really easy. Also, I use NGINX so I just make a nginx entry for it and there you go. Plus it takes so little ram that you can deploy like 10 go apps to one $5 vps.
Plus when you need to look at the code of a package you use it's pretty easy to understand what's going on in most cases.
I'm honestly surprised GO isn't more popular. Like it's not the cool kid. People are loving typescript (which is a nightmare to me personally) and want to use it everywhere but like to me it's not worth it.
And the best part, is that it gets amazing performance out of the box. I tried Rust which is an enigma wrapped in a mystery inside a riddle (thanks WC). It's so painful to get working with it, and GO isn't as good as Rust in terms of performance but it's close enough and it's about 20x easier as a language.
Anyway, just wanted to share that. I really like it.
Edit: Also recompiling is a pain but the fact that so many errors are caught before or during compile makes up for it. With dynamic languages it's like "Okay now it's reloaded... What did I break, lets see"
Usually, C++ is the preferred language in this case. Just wanted to understand whether Go can fill that space.
Doing some digging around the Debian Computer Language Benchmark Game I came across some interesting findings. After grabbing the data off the page and cleaning it up with awk and sed, I averaged out the CPU seconds ('secs') across all tests including physics and astronomy simulations (N-body), various matrix algorithms, binary trees, regex, and more. These may be fallible and you can see my process here
Here are the results of a few of my scripts which are the average CPU seconds of all tests. Go performs 10x faster than Python and is head to head with Java.
Python Average: 106.756 Go Average: 8.98625 Java Average: 9.0565 Go Average: 8.98625 Rust Average: 3.06823 Go Average: 8.98625 C# Average: 3.74485 Java Average: 9.0565 C# Average: 3.74485 Go Average: 8.98625
In this benchmarking test, Anton the youtuber is testing REST API built using Java (Quarkus) and Go (Fiber). I always thought that Go Massively outperforms other compiled and GC languages like java and C#. But according to this test, go barely outperforms java api. This test uses Fiber which uses fast http which is faster than the standard lib net/http. The benchmark uses two tests: 1). A simple get api which returns a UUID as json 2). An api which fetches a file from local computer, saves it to amazon S3 and then saves metadata to Postgres. The 2nd test is closer to real world use case. I am studying go and could use your comments to know what could Anton do to further optimize his go app. I know a performance gain of a few seconds doesn't matter. I am just curious.
So I have recently watched an interview where Ken Thompson was saying he got convinced to build Go after he read some C++ codebase. I also read some blogs saying the same.
But how can Go compete with C++ which has manual memory management ?
The reason people are using C++ is because of its Speed and ability to manually manage the memory right ?
How can Go which has GC be used to write Game development, HFT softwares, automobile softwares, embedded and expect the same result as that of a manually memory managed language?
Or is there any plan to add manual memory management to Go ? Which would make it really awesome ig ?
Here is the Google I/O conference
Ps: Beginner.
Edit: By competitor I meant the same things C++ does that go does it easier and better.
I think many people thought I was trying to make a language war here lol.
As i specifically mention above I'm a beginner and I was just trying to get the thoughts of experienced devs who used both.
For a personal project I wanted to know what is the best language for searching a keyword in a text file.
I did some research and I found out that the best languages ATM for efficiency and speed are:
rust
c++
go
I tried to create a scenario with a file (filled with lorem ipsum) of 54MB and performing the search with the languages listed above. I was flabbergasted when the results came out.
The most difficult scenario (i leave the boxplot below) happens when the haystack that I need to find is in the end of the file (cause the programm will need to cycle to the end to find a result).
The scenario's result (based on 100 tries for each language on the most difficult file) is that go is very fast, at least 4 times faster! Im still learning so I'm not aware of the possible shenanigans that go uses to handle files.
If someone can explain if the behaviour is correct or have any feedback I will leave the code in the end of the post
https://github.com/learning-bos/file-search-comparison.git
Hi all,
First of all, forgive me to ask this. I am a noob to Golang and find it very promising to learn. I read that Golang is not as performant as C or C++ code. What's the reason behind this? AFAIK Golang is very close to C or inherits many features. If this is the case, why is Golang gaining popularity? How about the future of Golang developers? What's the primary domain of use - cloud?
Some people like to blame all of the slowness of languages like Go, C#, and Java on garbage collection, but that isn't a very complete story. People will correctly tell you that normally garbage collection takes up a very very small % of total runtime, and that is true, so what else is going on? There are some indirect and related things as well.
-
Languages that have garbage collection are attempting to be memory safe languages, so:
-
They will also tend to have array bounds checks when the compiler can't prove they can be elided
-
They will tend not to allow as many clever casts
-
They will tend not to allow pointer arithmetic
-
Providing ways to leverage SIMD instructions by hand is hard (Go gives access only through Go assembler at the moment)
-
They will tend not to have a way for the compiler to do floating point optimizations that can change results like --ffast-math in C compilers
-
-
Garbage Collection has some indirect effects aside from how much time is spent doing GC
-
Every time the GC runs it pollutes the CPU caches, slowing down code that runs later
-
GC will normally imply a degree of overhead when doing FFI (interop with other languages). Go has even more overhead due to how it manages it's stack, which facilitates goroutine features. Lots of things require FFI still (3d rendering, for example) so those things will always be slower.
-
The control you get over memory layout of your data is usually limited to some degree. For instance in Go you can't explicitly control whether data goes on the stack, or heap, or *where* to goes on the heap. On the bright side in Go you can at least work with any type you create as a value or a reference, so you can at least control things like making sure your array is an array of values in contiguous memory vs an array of references, which you can't in Java. Accessing RAM is very slow, controlling memory layout on modern computers can be a big deal, assuring that you hit the L1 and L2 cache as much as possible.
-
There are also just some cultural things, people working on the C and C++ ecosystems are doing so because performance is priority one. People working on ecosystems of memory safe languages obviously have a bit of priority for safety, correctness, or productivity or they wouldn't want the GC!
None of these things in isolation is normally a very big deal but they can add up.
There are tons of differences in the implementations of C and Go that slightly slow down Go in favour of safety. A few things:
-
goroutine scheduling
-
growing stacks
-
Runtime checks for memory access (you panic on nil not segfault)
-
runtime reflection
-
Bounds checking on arrays/slices
-
No naive casting (safe type assertion)
-
Different calling conventions
-
this allows panics at any pint
-
Go relies more on the stack (no fastcall)
-
-
Defer
-
Much fewer optimizations in favour of fast compile times
-
latency optimized GC, this limits throughput
All of this and much more lead to the fact that cgo has quite some overhead.
C is still the most dominant language and this will be remain true longer than we all live. Go improves C in lots of aspects that address issues faced today.
-
Go is memory safe making it way less dangerous to program critical systems
-
Great multicore capabilities in times after Moore's law
-
Go scales great
Has Rust really overtaken Go for high-concurrency backends, or is Go still the go-to for fast, reliable scaling? Would love to see your real-world experiences and what’s driving your team’s language choice these days. Share your thoughts below!
I benchmarked identical Go and Rust servers under heavy load:
- 15,000 concurrent users
- 15 minutes sustained load
- Real Hetzner K3s cluster (not localhost)
- Separate nodes for apps, monitoring, and load testing
- k6 for load generation, Prometheus + Grafana for metrics
Both servers do the same thing: 100 iterations of SHA256 hashing, return JSON.
Go: standard library only
Rust: Hyper + Tokio + sha2
I tracked p50, p90, p95, p99 latencies in real-time.
The results were not what I expected.
Code is on GitHub if you want to run it yourself: https://github.com/huseyinbabal/benchmarks/tree/main/rust-server-vs-goserver
Curious what you all think.
Hello, I've recently made the switch to Go. And all I can tell is that it's really amazing.
Some context
I come from python/Django and now I use a simple net/http and gorilla/mux. My API is now a 1000% faster lol, I dropped from 871ms for an authenticated query using Postgresql to only 32ms with MariaDB (using GORM) Update 1: after researching more, PostgresQL seems better to use :)
Why I think it's worth it
Python is inevitably nice to use for quick ideas, but go is there when you want the performance. Go, not like Python, is a compiled language. Which means it builds an optimized binary and then runs it. Python interpretes it and that's why it's so slow. Another thing is the syntax. I've been using Jetbrains GoLand and the power it gives is impressive. The syntax is easy to read (thanks to go fmt which lints the code in a very specific way) which means that Go code cannot be messy and difficult to read (in my opinion) I also like the fact that it uses "packages", which allows you to split functions in as much files as you like in the same directory, which helped me a lot, I don't have to search for specific functions in a big 2K lines+ file.
Should you learn go?
I'd obviously tell you to do so, but it depends what you want to do :) For APIs, I'd use it for sure, never doing it in Python ever again. I suggest you use the same light stack as me: net/http, gorilla/mux, GORM and MariaDB. If you're wanting to make a simple website, I guess you can by using a web framework? But if you know JS I'd use Next.JS :)
I hope this post might have helped you in your choice :)
Update: I've switched to PostgresQL and there is no extra delays, around 20ms extra?
What you can do with Golang?
While some different languages like C, Java, and so on have strong command over the field of programming, a few new models have been introduced that can spell better outcomes for the modern computing, particularly in the cloud. The expanding ubiquity of Go for the most part owes to its lightweight and the fact that it’s reasonable for pretty much every microservices architecture. Container darling docker, as well as Google’s Kubernetes, are also built with the use of Go. Go is also holding the ground in data science owing to its advantageous features, which the data scientists are hoping to use to acquire increasingly successful outcomes.
Being a profoundly advanced programming language, GoLang can facilitate the developers in various manners, which additionally incorporate native concurrency, garbage collection etc. While utilizing Go, a developer need not depend on a few other native capabilities to limit the need of composing codes to fix memory leakage, and so on. Some of different features offered by GoLang can fit flawlessly with data science and microservices architectures.
As a result of these previously mentioned advantages, Go is progressively being used by legions of companies everywhere throughout the globe. An Application Programming Interface for the Tensorflow has been incorporated, and products,such as Pachyderm are being created with using Go. There are a series of parts of Cloud Foundry that have been written in GoLang too. Also, the interesting thing is that this list is normally including various names composed with the help of Go. To know the comparison between Python and Go, just go through- Python vs Go : Which one to choose?
What Makes GoLang Absolutely Irreplaceable?
It was not exceptionally long that GoLang had set its journey to bring an improvement and also reduce some of the long-standing issues of the development industry. In the journey of giving the millennial developers a unified and consistent experience of development, Go appeared, and as time passes, it’s carving a niche for itself without a doubt. Be that as it may, is it worth the whole buzz? Is Go genuinely irreplaceable? Is it capable of staying ahead in technology race? Let’s find it out.
Simplicity is the Major USP of GoLang-
Simplicity is unsurpassable and GoLang has absolutely taken it to the next level. Numerous successful programming languages, for example, Rust, Scala, and so on are full of different complex features. Likewise, they have spelled amazing outcomes in development by having provided advanced memory management and type systems. These programming languages have absolutely taken the mainstream languages of their time, for example, Java, C#, C++, and so forth., and boosted their overall capabilities. Having taken a different and simpler way, GoLang has effectively eliminated many of such features, yet, for quite a few reasons. The following are some features and capacities that Go has eliminated:
1. No Generics-
Generics or templates allude to the pillar of various programming languages. By including the complex and error messages related to generics, they can frequently be obscure to understand. By having chosen to hold back on this part, the Go developers have made it simple to work with it. Without a doubt, it has been an extremely disputable yet a savvy decision taken by the designers.
2. Single Executable-
There is very discrete runtime library in GoLang. It is capable of generating a single executable that one can deploy by copying. Thanks to this for eliminating the risk of version mismatches or dependencies. Additionally, it could be an incredible help for container based development projects.
3. No Dynamic Libraries-
There has been a slight change in 1.8 version of GoLang, as now the developers can load dynamic libraries in it by plug-in packages. But, as this feature was not in GoLang from the get go, it’s as yet considered as an extension for the extraordinary features.
Go Owes its Popularity to Goroutines-
From an efficient perspective, Goroutines is regarded as one of the most interesting parts of GoLang. It can allow the experts to harness the capabilities of multicore machines in a helpful manner.
1. CSP-
The establishment of GoLang’s concurrency model is C. A. R. The prime thought is to misdirect any kind of synchronization over the shared memory between a few threads of execution that is work-intensive and mistake inclined.
2. Synchronize Go-routines-
Another powerful method to wait for goroutines is to utilize sync groups. One can declare a wait group object and along these lines pass it to each goroutine that is responsible for calling its Done() techniques when it’s totally done.
3. Channels-
Channels can permit goroutines to exchange data easily. One can make a channel and pass it on to a goroutine. The user can not just write the channel, yet in addition read from it.
Handles Error Seamlessly-
The whole concept of error handling is dealt with diversely by GoLang. By convention functions, GoLang will never fail at returning an error as its final return values. Despite the fact that one can’t return errors from a go-routine, he/ she can convey them to the world outside through a few different mediums.
It’s to be sure a decent practice to pass an error channel to a go routine. The users can likewise write errors to the database, log records or call remote services while utilizing GoLang.
Blog Spam.
I‘m into Go for three years now and I’ve never been more productive and able to get things done than with most languages before. I try out new langs here and there just to keep an open mind. However, nothing comes close to Go when it comes to developer productivity, especially when you work with other developers. Rarely we have discussions like „why did you do it this way and not that way...“.
Certainly others like Perl6 (sorry I mean Raku 😀), Nim etc are worth spending time with. For educational purposes, not for business.
Once you get Go‘s „errors as data“ compared to „try catching exceptions“, there is no way back, ever.
What some people might complain about Go not having Generics can be easily achieved with interfaces, in a way your fellow young developer will be able to understand.
Of course, Go might not be a good choice for UI development or some big enterprise financial application. But I‘m still grateful for the invaluable contribution the Go creators brought to the developer community.
Background: I've been using Java for about 8 years and just started learning Golang.
So far, I'm in love with the language, and these are the top reasons:
More low-level control of memory. I hated how much the JVM's GC relied on the compactor. Objects can only be created on the heap and object arrays are arrays of pointers to non-contiguous locations in memory. Many like to say that Java has better GCs than Go, but that's because Go's memory model doesn't require such complicated GCs. It's also nice to have pointers in Go.
More paradigm-neutral. Java was designed from the beginning to be a language primarily for OO programming. Using Java for functional programming results in unnatural syntax and inefficient use of memory. Golang feels ambidextrous.
I'm still very new to Golang but as of right now, I even see it as a replacement for Node and Python in the areas of scripting and web server development. Golang's fast compile time closes makes it competitive against interpreted languages in terms of development speed, but 1-ups these languages because it gives the developer more low-level control of memory and has static typing.