Today's Question:  What does your personal desk look like?        GIVE A SHOUT

 PROGRAMMING


  Understand GoLang WaitGroup internals and how it works

BackgroundBefore getting into the main content, let me give a brief introduction to WaitGroup and its related background knowledge. Here, the focus is on the basic usage of WaitGroup and the fundamental knowledge of system semaphores. For those who are familiar with these, you can skip this section directly.WaitGroupWaitGroup is one of the most common concurrency control techniques in Golang, and its function can be roughly compared to the join() in concurrency control of other languages' multithreading. The sample code is as follows:package mainimport ( "fmt" "sync" "time")func main(...

2,229 0       SOURCE CODE GOLANG WAITGROUP


  Mastering a New Programming Language: A Professional Guide

IntroductionLearning a new programming language can seem daunting, but with the right approach, anyone can become proficient in a new language. Whether you're a beginner or an experienced programmer, mastering a new language can open up new opportunities in your career and enable you to tackle new and exciting programming challenges. In this guide, we'll provide you with a step-by-step process for mastering a new programming language.Step 1: Choose a Language and Set GoalsThe first step in mastering a new programming language is to choose a language that aligns with your career goals and inter...

653 0       PROGRAMMING TIPS GUIDE


  Mastering Go Channels: How to Build Concurrent Applications Like a Pro

IntroductionIn the world of concurrent programming, Go channels have quickly become a popular tool for building fast and efficient applications. Utilizing channels can help you take full advantage of the power of Go's lightweight threads, or goroutines, and enable you to easily and effectively manage data sharing and synchronization. In this article, we'll dive deep into the world of Go channels and show you how to build concurrent applications like a pro.Understanding Go ChannelsTo start, let's take a closer look at what Go channels are and how they work. In Go, channels are a way to communic...

641 0       GOLANG CHANNEL CONCURRENCY


  Understanding PGO in GoLang 1.20

BackgroundThe Go 1.20 version was officially released in February 2023, it introduced the PGO(Profile Guided Optimization) mechanism.The basic principle of PGO can be divided into the following two steps:First, profiling is performed on the program to collect data about the program's runtime and generate a profiling file.When compiling the program, enable the PGO option, and the compiler will optimize the program's performance based on the content in the .pgo file.When compiling a program, the compiler will perform many optimizations, including well-known optimizations such as inline optimizat...

2,468 0       GOLANG PGO GO 1.20


  A simple tutorial on GoLang connecting to Clickhouse

Go, also known as Golang, is a statically-typed, concurrent programming language created by Google. ClickHouse is a high-performance, column-oriented database management system that can be used for real-time data analysis.This tutorial will provide a deep dive into how to connect to ClickHouse from a Go program, including how to perform common database operations such as SELECT and INSERT statements.Before proceeding, it is assumed that you already have Go and ClickHouse installed on your machine. If not, you can download the latest version of Go from the official website and install it by fol...

4,533 0       TUTORIAL GOLANG CLICKHOUSE


  Introduction to GoLang generics and advanced usage

Generics in Go allow you to write code that can work with multiple types of data, without having to write separate versions of the code for each type. This can make your code more flexible and easier to maintain, as you only need to write and test the code once, rather than maintaining multiple versions.To use generics in Go, you first need to define a type parameter, which is a placeholder for the type that the code will work with. For example, you might define a type parameter called "T" like this:func MyFunction(x T) T { // code here}You can then use the type parameter "T" wherever you wou...

4,243 2       GOLANG GENERICS


  Go channel explained

In Go, a channel is a type of concurrent data structure that allows two or more goroutines (Go's term for lightweight threads) to communicate with each other. Channels provide a way for goroutines to send and receive values, and they are an essential part of Go's concurrency model.Here's a simple example that demonstrates how to use channels in Go:package mainimport ( "fmt")func main() { // Create a new channel with the `make` function ch := make(chan int) // Start a new goroutine that sends the value 5 to the channel go func() { ch <- 5 }() // Read the value fro...

1,755 0       GOLANG CHANNEL


  Go Lacks Ternary Operators. Here Are Some Equivalents

If you were like me, a pure Java developer before writing Go, you must be wondering why Go doesn’t support the ternary operator like return a > 1 ? 0 : 1.Most mainstream languages like C and Java are supportive of ternary operators; languages like Python and Ruby support the simplified if-else one-liner, such as a = 0 if a > 1. However, Go is not among them. And it is not only about adding operators but also a concept of coding in a more convenient way, such as the ?: expression can be perfectly replaced by if-else, but what if you are required to duplicate it dozens or hundred tim...

1,663 2       GOLANG TERNARY OPERATOR