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

 PROGRAMMING


  What is goroutine?

Casual TalkGolang is quite enjoyable to write, aside from the tedious if err != nil checks. One of the fundamental reasons for the joy is goroutine, a core feature of Golang. Understanding goroutines in detail is worthwhile, as they contribute significantly to the pleasure of working with Golang. So, let's talk about goroutines, hoping to provide some insights to the readers.TL;DR: We'll start by talking about assembling a computer, then delve into some concepts of the operating system, such as processes and threads, before exploring goroutines themselves.Assembling a ComputerLet's focus on de...

900 0       EXPLANATION GOLANG GOROUTINE


  Deep Dive into Spin Locks in Golang

In concurrent programming, a Mutex is a commonly used synchronization mechanism to protect critical resources and prevent data races. However, in certain specific scenarios, especially when the lock-holding time is short and the number of threads is limited, a more lightweight lock known as a Spin Lock can provide higher performance.What is a Spin LockA Spin Lock is a form of busy-wait lock. When a thread attempts to acquire a lock held by another thread, it continuously checks the lock's status (i.e., "spins") until the lock is released, at which point it takes ownership. This waiting method ...

886 0       SPINLOCK MUTEX GOLANG


  How to Understand and Use nil in Golang Correctly?

In Golang, nil is a predefined identifier that carries different meanings in various contexts, but typically represents "none", "empty" or "zero value". It can be assigned to variables of pointer, slice, map, channel, function, and interface types. Understanding the significance of nil is crucial for writing robust Go programs, as mishandling nil can lead to unexpected issues.nil in PointersIn Go, pointers are a fundamental type that stores the memory address of a variable. When a pointer is declared but not initialized, its value is nil. The following example code illustrates this:package mai...

1,217 0       FUNCTION MAP GOLANG SLICE NIL CHANNEL


  Where Have You Installed Your Python Packages?

PrefaceI am writing this article because I recently noticed in the Python community that there are several frequently asked questions:Why does running the command after installing pip result in a "executable not found" error?Why does importing a module result in a "ModuleNotFound" error?Why can I run my code in PyCharm, but it doesn't work in the command prompt?Rather than just providing solutions, it is better to teach people how to fish. To address these types of issues, you need to understand how Python locates packages. I hope that after reading this article, you will find it helpful.How P...

10,022 1       PYTHON PATH PATH_PREFIX PACKAGE LOCATION


  In-depth Exploration of Direct and Indirect Dependency Management in GoLang

The dependency management in Golang is handled using go mod. go mod is the official dependency management tool introduced by the Golang team. It assists developers in managing project dependencies to ensure the stability and maintainability of the project code. In go mod, dependencies are categorized into two types based on how packages are imported in the code: direct dependencies and indirect dependencies. Direct dependencies are explicitly referenced in the project code, while indirect dependencies are dependencies of the direct dependencies. Below we will provide detailed explanations of t...

1,296 0       GO MODULE DIRECT DEPENDENCY INDIRECT DEPENDENCY


  Ensuring Go Interface Implementation: A Quick Guide

IntroductionGo's simplicity and power shine in its interface system, offering a clean way to define contracts between types. However, when it comes to checking whether a struct satisfies an interface, Go's static typing philosophy means there isn't a direct runtime check. In this concise guide, we'll explore practical methods, including some lesser-known tricks, to verify whether a struct implements an interface.Method 1: Type Assertion and a Dummy Methodpackage mainimport "fmt"type MyInterface interface { MyMethod()}type MyStruct struct{}func (ms MyStruct) MyMethod() { fmt.Println("MyMe...

960 0       INTERFACE GOLANG IMPLEMENTS


  new() and make() in GoLang

GoLang is a modern, statically typed, compiled programming language designed for building scalable, concurrent, and efficient software. It provides various built-in functions and features that help developers write concise and efficient code. Among them are the new() and make() functions, which may appear similar at first glance but serve different purposes in GoLang and are crucial for memory allocation and data initialization.In this blog article, we will explore the differences between the new() and make() functions, and understand when and how to use them effectively.new() and make()new() ...

1,153 0       MAKE GOLANG NEW


  Guide to Implement an SSH Client Using Golang

SSH, short for Secure Shell, is a network protocol used for securely remote logging into other computers on a network. I believe most backend developers are familiar with SSH. Common shell tools used for logging into servers, such as Xshell, SecureCRT, and iTerm2, are all based on the SSH protocol. In Golang, the crypto/ssh package provides functionality for implementing an SSH client. In this article, we will explain in detail how to implement an SSH client using Golang.Creating SSH Client ConfigurationFirst, we need to configure the parameters for the SSH client to connect to the server. The...

3,448 0       SSH GUIDE GOLANG SSH CLIENT