When you’re programming, there are times that you want to print out the type of a variable.
Depending on what IDE (Integrated Development Environment) you’re using, you can probably hover over the variable or figure out the type of the variable some other way, but let’s say you want to know how to print it out without however your IDE provides.
The key to how to accomplish this lies in the
fmt package in Golang, which is described in its documentation as:
Package fmt implements formatted I/O with functions analogous to C’s printf and scanf. …
If you start reading Go code coming from languages where variable names are long and very descriptive, you may be in for a bit of a ride because Go can have some really short ones. We’re talking often single letters like
Now, it’s not like the Go language fundamentally can’t support long variable names. It very much can. You can name variables really whatever you want, but this post is talking more about the standard convention or the way that Go developers typically write production Go code.
This is how Golang’s Code Review Comments document puts it:
If you’re a regular user of the command line, like Terminal in MacOS, then you have most certainly used the
ls command which allows you to see a list of the files and folders in a given directory.
To reinforce that, IBM documentation describes
ls as the following:
The ls command writes to standard output the contents of each specified Directory parameter or the name of each specified File parameter, along with any other information you ask for with the flags. …
The concept of receivers in Golang is one for a different article, but you can play around with them in the Go playground. There, they mention that:
A method is a function with a special receiver argument.
The receiver appears in its own argument list between the
funckeyword and the method name.
OK, so we know that a function with a receiver argument is called a method. What isn’t always so apparent is what exactly you should call that receiver argument — as in, what literally do you name the variable? …
If you’re faced with re-factoring some code that you or someone else has written, it can be a tall task. Having said that, it is extremely common; in fact, there’s a very popular and well-known book called Refactoring: Improving the Design of Existing Code by Martin Fowler that dives deep into it by systematically enumerating strategies on how to approach it.
In this post, we’ll actually go over a point that Fowler mentioned in that book, and that’s to have tight feedback loops when you’re re-factoring code.
The idea here is that when you’re re-factoring, you’re going to want to…
Let’s face it: cheat sheets are awesome.
I’m not talking about like crib sheets or something that people use in high school or college. No, I’m talking in more ethical terms here: a highly boiled-down reference that you can look at when you’re in the thick of things.
A cloud engineer by the name of Justin O’Connor made a great cheat sheet for Terraform, which you can find here. You can literally print it out or just bookmark it or just save it to your computer. …
One of the first commands you may ever start using when getting up and running with Terraform is
When you write a new Terraform configuration or pull one down from a version control system like Github, you’ll likely run
terraform init first. This article will briefly go into what it is and why you would run it.
First of all, the
init is short for initialize, and the basics of what it does are exactly inherent in the name: it initializes things.
To be more specific, you’re initializing various steps to prepare the working directory.
For instance, one…
Recently, I had to go a Git command in my terminal but was temporarily thwarted in my efforts.
The reason? The folder I was trying to act against had a space in it!
Here, let me explain: the folder was, let’s say, named
I wanted to do a
git rm on it, so I tried running this from my command line:
git rm Members 2021
However, Git complained! It isn’t too hard to see why, since it looks like it should try to remove
2021 is just some awkward argument that’s left over.
So I was…
In this article, we’ll go over a simple tip to write better Go code.
When writing Go code, you want to make sure that you’re being consistent in your approach while also encouraging readability. It’s a balancing act, so making sure that you and members of your team, if applicable, adhere to certain style guidelines is important.
One simple improvement to Go code is to group together declarations of constants, variables, and even type constants. What I mean by that is that Go supports the following:
a = 5
b = 10
In that code block, we’re…
For a lot of developers, you’re running the same commands over and over again — those multiple times a day turn into multiples times a week, a month, a year, and a career, and it takes away valuable time that you can spend doing other tasks.
At a small scale, these keystrokes don’t matter, but over long periods of time, they certainly do. Figuring out how to cut down the typing is an effort worth doing — as they used to say (or maybe still do?), “a stitch in time saves nine.”
If you’re using version control software, which you…