Go Programming Language

that programming language with a rodent mascot.

Created: by Pradeep GowdaUpdated:Aug 04, 2024Tagged: programming-language · golang .

Go is the only programming language that has been designed from the ground down. – vzverovich

Go advocates for making thread creation easy and light-weight and for using message passing over shared memory for inter-thread communication. Indeed, we saw more gor-outines created in Go programs than traditional threads andthere are significant usages of Go channel and other message passing mechanisms. However, our study show that if not used correctly, these two programming practices canpotentially cause concurrency bugs.

Shared memory vs. message passing: Our study found that message passing does not necessarily make multi-threaded programs less error-prone than shared memory.In fact, message passing is the main cause of blocking bugs.To make it worse, when combined with traditional synchro-nization primitives or with other new language featuresand libraries, message passing can cause blocking bugs thatare very hard to detect. Message passing causes less non-blocking bugs than shared memory synchronization and sur-prisingly, was even used to fix bugs that are caused by wrongshared memory synchronization. We believe that messagepassing offers a clean form of inter-thread communicationand can be useful in passing data and signals. But they areonly useful if used correctly, which requires programmersto not only understand message passing mechanisms wellbut also other synchronization mechanisms of Go.

Project structure

A very common question Go beginners have is “how do I organize my code?”. Some of the things folks are wondering about are:

  • How does my repository structure reflect the way users import my code?
  • How do I distribute commands (command-line programs that users can install) in addition to code?
  • How do modules change the way I organize my code?
  • How do multiple packages coexist in a single module?

Moving to Go

History

Learning

The Go Programming Language by Donovan and Kernighan.

Training

Reading

Development practices

The Go team has published official guidelines for organizing / structuring a Go project: https://go.dev/doc/modules/layout This includes recommended project layouts for different kinds of projects: a simple package, a command-line tool, a mix of the two, etc. via

Deployment practices

Performance monitoring

User Groups

Presentations

Libraries

Read Code

List of Lists on Go

Editors

FFI

Garbage Collection

Why Discord is switching from Go to Rust - Discord Blog

In Go, on cache key eviction, memory is not immediately freed. Instead, the garbage collector runs every so often to find any memory that has no references and then frees it. In other words, instead of freeing immediately after the memory is out of use, memory hangs out for a bit until the garbage collector can determine if it’s truly out of use. During garbage collection, Go has to do a lot of work to determine what memory is free, which can slow the program down. These latency spikes definitely smelled like garbage collection performance impact, but we had written the Go code very efficiently and had very few allocations. We were not creating a lot of garbage. After digging through the Go source code, we learned that Go will force a garbage collection run every 2 minutes at minimum. In other words, if garbage collection has not run for 2 minutes, regardless of heap growth, go will still force a garbage collection.

garbage collection - How fast is the go 1.5 gc with terabytes of RAM? - Stack Overflow

3-4ms pauses under 1.6, with about an 8GB heap and 150M allocations/minute.

Concurrency

Programming notes

Debugging notes

Copying core dumps

Build notes

Cross compiling a binary for Linux on Mac.

git clone [email protected]:xyproto/algernon.git
cd algernon
env GOOS=linux GOARCH=amd64 go build

Tools

Package management

Web

Frameworks

Templating

templ – “A HTML templating language for Go that has great developer tooling.” github

package main

templ Hello(name string) {
<div>Hello, { name }</div>
}

templ Greeting(person Person) {
<div class="greeting">
@Hello(person.Name)
</div>
}