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
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
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.
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
Everyone knows that prototyping in python is the way to get something working fast - fantastic development time.
It seems to me that Go's dev time, while longer, is not that much longer once you are familiar with the libraries and frameworks you want to use. My question is, where do you think that falls? Just how much faster is it to build in python versus Go? 3x? 2x? 50%? Just depends on use case?
My background is in C++, Java and Python. Starting to learn Go.
I found a comparison of nodejs and go performance on this site (https://www.techempower.com/benchmarks/#section=data-r23&test=update&l=zijo5b-pa5). I was interested in the fact that go loses to nodejs. Could there be something wrong there?
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?
I would like to ask those who have experience working with both C# and Go, what are the upsides and downsides of Go compared to C#? If you would use Go over C#, why? Is there a situation where you think C# is better? I have limited free time to invest in learning a new language and I am a C# dev currently and trying to decide whether it is worth it to me to invest time into learning Go as a C# dev. I really like the language and its concepts but I need some help making my decision. Thank you in advance for your replies.
I'm not a fan of any language but I know that there are some advantages and disadvantages of languages and framework alongside platforms matter - PHP is slow, yes it is slow comparing to any other languages but if you setup frakenPHP or swoole then is may compare with other languages -
I was just visiting dotnet page and saw that there is benchmark says 6x times faster than go and go even slower than nodejs
Why is it like this ? I'm not saying this is wrong and they are lying but, what is the explanation of this ? What does matter most such test cases?
Sources:
- https://imgur.com/a/Dx5B2kt
- https://dotnet.microsoft.com/en-us/