A Go writer who has just moved to Twi... X, I write clickbaity content and am currently open to new opportunities.blog.devtrovert.comJoined August 2014
💡 Golang Tip #81: To check if a string is empty, prefer s != "" over len(s) == 0.
Both solutions are perfectly fine and both techniques are commonly seen in Go's standard libraries.
> But what's the difference? Why should we prefer s != ""?
Using len(..) works for different…
💡 Golang Tip #80: Declare variables NEAR their usage
This is a common mistake among those who have been using Go for a little while.
People often put all the variables at the top of the function, and even worse, they use 'var':
While this might look neat or seem like a simple…
💡 Golang Tip #79: If doing something unusual, comment why
I've been reviewing code for a while, and realized that one of the most common and frustrating issues is the lack of comments explaining unusual code choices.
When we've worked with Go long enough, we understand that…
💡Golang Tip #78: Non-blocking channel send trick
When we send a value to a channel, we typically wait for the receiver to be ready to take the value:
But there are times when we don't want to wait.
For example, if you've followed the previous tip on using semaphore, we could…
💡Golang Tip #77: Buffered channels as semaphores to limit goroutine execution
When we need to manage 'how many goroutines can access a resource simultaneously', using a semaphore is a reliable approach.
We can create a semaphore using a buffered channel, where the channel's…
💡 Golang Tip #76: Result forwarding in function calls.
When I first started using Go, I found one concept a bit tricky: result forwarding in function calls.
It's common to get multiple values back from a function, usually a result along with an error, look at how we handle the…
💡Golang Tip #75: Optimize multiple calls with singleflight.
Let's consider you've got a function that fetches data from the network or performs some I/O and it takes around 3 seconds:
The above function emits a different number after 10 seconds.
- Now, if you call this…
💡 Golang Tip #74: Make time.Duration clear and easy to understand
When you're coding with time intervals, you'll be using the time.Duration type a lot.
A common issue that can make things confusing is when you use seconds:
In Go, it's usually NOT the usual way to do it, but if…
💡 Golang Tip #73: Implement String() for enum with the stringer tool.
Have you noticed when you print a duration in Go, like fmt.Println(time.Second), it shows up as "1s" instead of "1000000000" while time.Duration is int64.
This is because the time.Duration type has a…
💡Golang Tip #72: Case-Insensitive string comparison with strings.EqualFold.
When you need to compare strings without caring about whether the letters are upper or lower case, you might think to:
- Make both strings lower case using strings.ToLower()
- Or make them both upper…
💡 Golang Tip #71: sync.Pool, make it typed-safe with generics.
What is sync.Pool?
Before going to the typed-safe pool, for those who aren't familiar with sync.Pool, it's a Go standard library feature used to reuse objects.
This can reduce the number of memory allocations,…
💡Golang Tip #70: Implement a context-aware sleep function.
The regular time.Sleep() doesn't care about context. If you set it to pause for 5 minutes, it will pause the process for the full duration, no matter what.
Even if we try to use it with a context, like in the example…
💡Golang Tip #69: Manage multiple goroutines with errgroup
When we're dealing with a bunch of goroutines, it can be a bit hard to handle errors and make sure they all work together well.
You might know sync.WaitGroup, right? But there's a package called errgroup that makes this…
1K Followers 2K FollowingTechnical Director in Games / Software Developer / Serial Optimist / Music Fan 🧠 (I don't take this very seriously.)
Fediverse: @[email protected]
53K Followers 3 FollowingFast AI chat, with GPT-4, Claude 3, Gemini, DALL-E 3, SDXL and more. At https://t.co/6zH7y5z69E, or for iOS, Android, MacOS, or Windows at https://t.co/TXqyyX21KS
7K Followers 78 Following#golang performance, runtime, concurrency. Talks, blogposts and open source projects for #gophers (mail: [email protected]). Not affiliated with @golang team.
13K Followers 2K FollowingSenior Staff @datadoghq working on Go Profiling, Performance, OpenTelemetry and more.
Before: @Apple, Co-founder @transloadit, @nodejs core dev
1.3M Followers 1K FollowingProfessor of Neurobiology & Ophthalmology at Stanford Medicine • Host of the Huberman Lab podcast • Focused on science & health research & public education
123K Followers 19 FollowingMakers of Devin, the first AI software engineer. We are an applied AI lab focused on reasoning, and code is just the beginning. Join us: https://t.co/tpfZwEwGiq
9K Followers 78 FollowingTinyGo - a Go compiler for small places. Embedded systems/microcontrollers, WebAssembly (wasm/wasi), CLI tools.
https://t.co/MyExlyms4H
https://t.co/pwEpxI7n4r
8K Followers 464 FollowingWeb developer | https://t.co/PmzkHgL2zg | Father | Husband | #buildinpublic | trying to help people learn to code.
building https://t.co/IHm3os3ioy
63K Followers 507 Following♥ Distributed Systems & Cloud
🦆 Author of Kubernetes Patterns
👔 Product Manager @diagridio
🏗️ Ex Architect Red Hat
✍️ Content Creator & Book Reviews👇
10K Followers 404 FollowingPanelist on @GoTimeFM • Teaching #golang • Want to learn Go with fun exercises? Try https://t.co/qYoY2xodvd and https://t.co/3cASkPfN2z
21K Followers 758 FollowingAuthor of https://t.co/arW0hnVET0 and https://t.co/RN9xXOzhON. Working @zeddotdev. Ex-@sourcegraph. Programming where the rubber hits the road.
2K Followers 0 Following#infosec enthusiast • #golang dev & trainer • minimalist • #degrowth advocate • atheist • chaotic good • trying to make sense of the Web • he/him • Free 🇵🇸!
1.0M Followers 914 FollowingCo-Founder of Coursera; Stanford CS adjunct faculty. Former head of Baidu AI Group/Google Brain. #ai #machinelearning, #deeplearning #MOOCs
192K Followers 3K FollowingAI Gardener & Designer. Follow to get the latest AI trends, learn how to use AI tools to augment yourself - @bedtimestoryai @typeform @flodeskinc @thingtesting_
3.5M Followers 0 FollowingOpenAI’s mission is to ensure that artificial general intelligence benefits all of humanity. We’re hiring: https://t.co/dJGr6LgzPA
113K Followers 136 FollowingWorking on a new terminal. 👻 Prev: founded @HashiCorp. Created Vagrant, Terraform, Vault, and others. Passionate about indie software.
16K Followers 3K FollowingComedy • Music • @VowlGame • Building things at @grafana • Indoor enthusiast • Music • Podcaster • @GoTimeFM • https://t.co/O21mwMMGUt
14K Followers 328 FollowingBuilt a 6 figure blog from the side of my desk in just over a year!
Currently at over 200,000 monthly pageviews
Newsletter Sign Up: https://t.co/5mi5cvlfpN
11K Followers 3K FollowingEngineering Manager @cloudflare; author of Domain-Driven Design with Golang. creator of Ultimate Guide to Debugging in Go Course (see link)
25K Followers 132 FollowingChief Architect & Co-Founder @AcornLabs @GPTScript_ai Formerly @SUSE, @Rancher_Labs. k3s Creator. Member of The Church of Jesus Christ of Latter-Day Saints
229K Followers 389 FollowingCo-Founder of ByteByteGo | Author of the bestselling book series: ‘System Design Interview’ | YouTube: https://t.co/9gPSJSrtPU