Paulo L F Casaretto (@pcasaretto) profile picture

Software Engineer

Joined March 2008
Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)Photo by Paulo L F Casaretto (@pcasaretto)
So after years of procrastination I've finally begun to write. Check out my thoughts on inheritance as it is on typical OO oriented languages: medium.com/paulo-casaretto-s…
1
Paulo L F Casaretto retweeted
Slack uses Apache Kafka at scale: • 6.5 Gbps • 700TB of data • 100s of nodes Here's their fun story 👇
18
212
25
1,691
518,405
Paulo L F Casaretto retweeted
The 'Maybe Not' talk by Rich Hickey is a sure way to make all Haskellers angry. He really knows how to push those buttons 😅 In any case, it was refreshing to learn why the 'Maybe' type in Haskell (or 'option' in OCaml) is not as great as we think. youtube.com/watch?v=YR5WdGrp…
14
14
129
18,255
Paulo L F Casaretto retweeted
A variety of answers here for which server/router folks use in #golang. Personally, since Go 1.22 I have tried to use the standard library as much as possible. Here's a video I made of the additions in Go 1.22 that made me change my thinking; previously I would have always used a framework. The video is an excerpt from my free course which I'll link to below. Apart from the standard library, Gorilla Mux, Gin and Fiber were the most prevalent options (with an honorable mention to Chi and Echo). You'll notice there is not a huge difference in simple examples like those I gave below - all the more reason to give the standard library another chance if you haven't for a while :) Gorilla Mux Before Go 1.22, this was my default choice and I imagine this is where the Go team got inspiration from. You'll notice the API is very similar. If you have a simple use case, I imagine you can remove the gorilla dependency and move to the standard library very easily. Gin @thnk2wn said it best: "Fast, solid, flexible, good support and docs". You can see from the example below that is really not too different from the standard library either. Fiber @HubertBosiacki "I use Fiber if I have a need for speed" From the Fiber README: "Fiber is an Express inspired web framework built on top of Fasthttp, the fastest HTTP engine for Go. Designed to ease things up for fast development with zero memory allocation and performance in mind." I have never used this but I can see why it's popular. It claims to be fast and also takes inspiration from eco-systems that new folks to Go are likely already familiar with. So which should I use? @joshduffney said it best: "I've always used the standard library. My reasoning is I don't have another dependency to manage and it's forced me to think deeper about what's actually going on instead of relying on the nice wrapped methods etc of the other libraries. That said it, I do see the value in the other libs once you hit a certain level of complexity." Because I added a video, the formatting of this post sucks, I can't add it in-line like I usually do. I'll be sending a longer (well-formatted) analysis to my newsletter in the next couple of days so be sure to sign up there if you want to receive it bytesizego.com/subscribe
This weeks #golang discussion: Which http server do you use? standard library? Gorilla Mux? Why? If you started a new project, which would you use? As always I'll summarize the results and share them!
5
10
86
12,314
Paulo L F Casaretto retweeted
Most go developers don't even know if they're using tabs or spaces. That is the right solution.
If you’re not using tabs instead of spaces, you’re still a junior developer
8
6
4
69
10,919
Paulo L F Casaretto retweeted
This is my regular announcement that you need @Tailscale in your life. I’m here in Korea on my iPhone but I’m watching Netflix using my Synology NAS back in Oregon as an exit node. Absolutely rock solid personal free VPN *and* amazing for teams and developers as well. Magical.
40
49
4
828
110,971
I’m learning Rust, building projects like a ray tracer and a game boy emulator. Really liking it so far. I was a bit bummed to find async/await. I’m with @munificentbob that Go has got it right. You shouldn’t have to change how you listen to a tcp socket to make that concurrent.
8
81
Paulo L F Casaretto retweeted
Interested in contributing to the next NixOS release on May 24th? Check out the release wiki and the announcement at buff.ly/4asv9Us You'll be paired with someone who has previous experience to learn the ropes, making it a fantastic opportunity to get involved.
7
21
2,181
Paulo L F Casaretto retweeted
"We don't do code reviews. We trust our developers". You have no idea how often I run a PR and find it's broken. It's *extremely* common. Even from senior devs. We all make mistakes. So I trust no one. Including myself.
94
87
12
1,153
106,023
Paulo L F Casaretto retweeted
It’s simple, I get to: - Spend 3 hours before work with my son - Spend another 2 hours after finishing work with my son - Do jiujitsu at lunchtime 5 days/week - Time with wife after putting kiddo to sleep What do I get for being in the office? None of that, all wasted time
Why do you need a remote job? What's so special?
8
71
1
859
39,300
Paulo L F Casaretto retweeted
After having programmed in a language for so long that doesn't have inheritance (golang), and now working in one that does (python), wow, I really hate inheritance.
11
7
95
9,987
After I started using @nixos_org I skim over any "Installation" section I see. I know most software will be easily accessible with a simple nix shell command. Easy. AND I know that my machine will be the same when I'm done with the shell. No other software will be affected.
1
2
73
Example github.com/Tensegritics/Cloj… Laborious? Not at all. With the latest devenv.sh from @nixos_org (@domenkozar) all I had to do was add pkgs.flutter to packages.
1
28
Paulo L F Casaretto retweeted
Replying to @ImLunaHey
Arrays should start at 1
29
3
2
112
7,415
Paulo L F Casaretto retweeted
💡Golang Tip #52: Adjusting GOMAXPROCS for Containerized Env (Kubernetes, Docker, etc.) (Alert: Long, boring stuff ahead) What is GOMAXPROCS? By default, Go can execute up to 10,000 threads concurrently, but the actual number running in parallel depends on a critical setting: GOMAXPROCS. GOMAXPROCS sets the limit on the number of OS threads that can run user-level Go code simultaneously (not just concurrently). Its default value aligns with the logical CPU cores your OS sees (runtime.NumCPU()): For instance, on my MacOS, that's 8 cores. This means Go will juggle up to 8 threads simultaneously by default. Running Go in Containers (Docker & Kubernetes) In containerized environments like K8s, we can specify CPU limits for each container, and we're telling the container, "You can only use this much of the CPU." E.g., limit: 250m = 1/4 core, 1 = 1 core Sadly, Go doesn't see the CPU limits set by the container on its own. It still looks at the total number of CPU cores on the host machine, not what's given to the container. (A host machine or node holds various pods) Because of this, a Go program might try to use more CPU cores than it's supposed to. > "But why? I thought it was better when using more CPUs" These are some reasons: 1. Context switching: When there are more threads than CPU cores, the operating system must switch more between threads. 2. Inefficient scheduling: The Go scheduler may create more runnable goroutines than can be executed given the CPU constraints, leading to contention for CPU time. 3. Inefficient use of CPU Bound: Go programs are typically CPU bound, meaning they perform best when each thread can be executed on a separate CPU core without needing to wait. By having more GOMAXPROCS than CPU cores given, we force the Go runtime to plan for more threads than there are cores available, making inefficient execution of CPU-bound tasks. So what to do? The Solution For those looking for a hands-off approach, uber-go/automaxprocs might be your solution. This lib fine-tunes GOMAXPROCS to match your container's CPU limit. (If you want to know how uber-go/automaxprocs works behind the scenes, just give me a sign) Otherwise, if you have an understanding of the deployment/pod spec, you may want to add the ENV GOMAXPROCS to match your limit. But I would say more about this from DevOps perspective, it's better to avoid CPU limits while always specifying CPU requests (more on this below), and this is not specific to Go services. This is something to ponder if your container lacks a defined CPU limit. ---- - For the love of god, stop using CPU limits on Kubernetes (updated version): reddit.com/r/kubernetes/comm… - Kubernetes CPU Limits and Go: ardanlabs.com/blog/2024/02/k… #golang
7
18
1
168
21,732
Paulo L F Casaretto retweeted
“Coding” was never the source of value, and people shouldn’t get overly attached to it. Problem solving is the core skill. The discipline and precision demanded by traditional programming will remain valuable transferable attributes, but they won’t be a barrier to entry. Many times over the years I have thought about a great programmer I knew that loved assembly language to the point of not wanting to move to C. I have to fight some similar feelings of my own around using existing massive codebases and inefficient languages, but I push through. I had somewhat resigned myself to the fact that I might be missing out on the “final abstraction”, where you realize that managing people is more powerful than any personal tool. I just don’t like it, and I can live with the limitations that puts on me. I suspect that I will enjoy managing AIs more, even if they wind up being better programmers than I am.
This post is from an account that no longer exists. Learn more
519
2,507
479
16,503
2,754,434
Paulo L F Casaretto retweeted
Everyone save this
Gmail is here to stay.
1
5
104
5,553
Paulo L F Casaretto retweeted
💡Golang Tip #26: Explicitly ignore values with blank identifier (_) instead of silently ignoring them When writing Go code, functions can return values that you may or may not want to use. In such cases, there are two approaches: - Implicitly: call the function without assigning its return value to any variable, this is short and concise. - Explicitly: a bit more verbose, explicitly ignore the return value by assigning it to the blank identifier _. > "Why is explicitly preferred when it's more verbose and not as concise?"? In coding, clarity is always preferred over brevity. This approach clearly indicates that we're intentionally ignoring the return value of PerformOperation(). The use of _ = signals to other devs (or to ourselves in the [near] future) that the omission was deliberate, and not an oversight. > "What about an error?" Regardless, if a function returns an error, always handle it, or at the very least, log it. Also, consider adding a comment to explain why, for better clarity. #golang
3
7
1
45
5,871
Paulo L F Casaretto retweeted
💡Golang (or any language?) Tip #18: Define interfaces in the consumer package, not the producer. I've tweeted about this before (teapaw.org/func25/status/17…), but its importance has led me to include it in this tips list. Now, there're 3 principles to remember: 1. Define interfaces in the consumer package, not the producer. Interfaces should be defined by the consumer (the code that uses the interfaces) rather than the producer (the code that implements these interfaces). This approach makes it easier to add new methods to implementations without affecting consumers. 2. Use concrete types for return values in the producer package. This is straightforward, as we don't define interfaces in the producer. It allows us to add new methods to these types without breaking the API. 3. Avoid premature interface definitions Define interfaces only when there is a clear use case, ensuring they are necessary and correctly designed. ---------- Ok, enough with theory and hypothesis. Have you ever done something like this? Defining the Logger interface in the same package as the consoleLogger. And then, whenever you want to use it, you create the interface (?) in the consumer? I did this many years ago, not with Logger but with a Repository interface :) > "Is this bad?" Maybe. But consider the approach that follows our principles, let's revise it. First, here is our new producer logger package: 1. We no longer maintain the Logger interface in the producer anymore. 2. We return a concrete type when creating a Logger in the producer, right? 3. We avoid prematurely defining interfaces, with no need to guess what functions the client needs. Now, let's see how our client (consumer) uses it: By defining interfaces where they are used (in high-level modules), you ensure that these modules depend on abstractions rather than concrete implementations. Ah, this also enhances modularity, mock testing & design mindset. #golang
In Go, an interface should be defined at the consumer rather than at the provider. The repository interface should be defined where it is used, not where it is declared.
5
12
80
10,252