First things first, what is context?
Context — in this context ( ͡❛ ͜ʖ ͡❛) — is a construct that controls deadline in Go. It’s provided by the context package.
Deadline of what, you may ask? It can be used for anything, but its initial intent was for deadlines of operations within a single server request. If you’re not sure what that means, don’t worry! That will be explained in the following sections.
There are three main elements to a context:
Cancellation is the capability that lets you cancel the context manually.
Deadline and timeout can…
Go’s dependency management has evolved over time like other languages. But ever since Go Modules was introduced in v1.11, the community has quickly adapted it as its primary dependency management system.
If you are relatively new to Go, you might have been using modules with some gap on how they really work. I will try my best to fill some of those gaps here.
In general, Go module keeps track of the dependencies in files named
go.sum is automatically generated and derived from
go.mod, so you typically never need to do anything directly to that file. If…
I had a chance to review some tech challenges submitted for developer positions of various seniority in my company. The challenge is to write a simple command line utility program, and was in Go. I won’t disclose the details, but it involved iterating over multiple “things” and do something with each.
What surprised me was that so many applicants used concurrency for the challenge, in the effort to parallelize the works. The challenge didn’t ask to optimize for the best runtime, and definitely didn’t ask for parallelism (although we left most of the direction to the applicant’s liberty). …
Wow, reading this made me realize how subjective "readability" can be. I wasn't sure if this article was a satire or not til the end.
To me, the first snippet is MUCH cleaner and more readable. I'm quickly able to tell that all the blocks at the start are for error handling, and skip through to the last part of the function to see what this function does. On the second snippet, though, I need to read all the conditions for the "if" cases in order to reach the happy path you mentioned.
I think this is also partly because it's C, where there tends to be a lot of cleanups and memory management in each of the return case. In most of the modern languages we don't need to free memory and/or there are mechanisms meant for cleanups (like "defer" statement in Go).
I didn’t spend crazy amount of time on it, but I definitely needed to work in consistent pace. My Saturday mornings were pretty much dedicated for this.
And here are my learnings (other than technical stuffs) from this journey!
Most of my previous side projects were hype-driven. I would find a new and cool technology, and say “I gotta try this out!”. …
In one of my previous companies, we had the worst service outage in its lifetime. The unexpected downtime lasted for an entire day, came back up at the night, and then went down again for roughly half a day on the next day. I was on vacation during the entire event and was in the area without any internet access, but the solution they implemented was adding a rate limiter to the service. Everyone had agreed the network wasn’t part of the culprit — it was something in the database. Because rate limiter would address the immediate crisis, the problem…
If you were like most people, at least once in a life you probably had a doubt whether the world is what it seems to be. Perhaps you thought everyone else might be tricking you like in “The Truman Show”, or perhaps you thought the world is secretly controlled by aliens and some people are aliens in disguise. Or perhaps you thought we are actually game characters living in the game, which is a simulation. …
You might have felt, at some point in your life, or at least heard about, the work experience dilemma. You’re just out of school, you start looking for jobs, search the online job platforms for the positions that look like a good fit for you. Turns out, all those “Entry” or “Junior” positions require 1~2 years of work experience. How can you possibly get work experience if all of the job positions out there require prior work experience?!
Let me be upfront with this. I had 2 years and 8 months of co-op experiences before starting a full time job…