How I built an agent to automate the grunt work of code review so that reviewers can focus more on intent and design. 1. The problem: thorough code review is necessary but expensive It’s 2pm. My review queue has about a dozen pull requests in it. My team just finished their day and submitted them before signing off. A few PRs run to several hundred lines. By the time I work through the…
The year is 1984. Brazil is under a military dictatorship. As part of their colossal mismanagement of the country’s economy, which would result in over 1.2 trillion US Dollars in foreign debt at current values, and hiperinflation that reached over 200% a year, the military government had instituted protectionist measures banning imports of computers. The intent was to preserve national…
This is part 23 of my journey learning Golang. Random number generators For some kinds of programs, like simulations, games, or test code, it is useful to be able to generate unpredictable sequences of numbers. While generating truly random numbers is a hard problem (see RANDOM.ORG ), a common alternative is to use a pseudorandom number generator . Go has a package for generating pseudo-random…
This is part 22 of my journey learning Golang. Variable scopes A common source of errors in programming is using the same variable in many different parts of a program. For a deep dive into the problems that this practice can cause, take a look at Global Variables Are Bad . A common solution that is adopted by most programming languages is to make it possible to declare variables that can only be…
This is part 21 of my journey learning Golang. Chained conditions It is a common pattern for a program to have a sequence of conditional statements testing for different values of the same variable or function result. For instance: 1 package main 2 3 import ( 4 'fmt' 5 ) 6 7 func main () { 8 x := 0 9 y := 0 10 for command := '' ; command != 'end' ; { 11 fmt . Print ( 'Command? ' ) 12 fmt . Scan (…
This is part 20 of my journey learning Golang. Boolean algebra Boolean algebra is about logical operations applied to the boolean values true and false . The most common operations are “and” (conjunction), “or” (disjunction) and “not” (negation). Fun fact: it is called “boolean” because it was introduced by George Boole in 1847. Logical operators Go…
This is part 19 of my journey learning Golang. Conditionals Any program can be written in terms of three control structures: the sequence structure , in which expressions are executed in sequence, one after the other, in the order that they are written; the selection structure , in which a statement can be executed or not, depending on some condition; and the iteration structure , in which…
This is part 18 of my journey learning Golang. Command line interface When building programs that run on a terminal it is often useful to be able to allow the user to enter text. For instance the ssh-keygen utility will prompt for a path and a passphrase. 1 ❯ ssh-keygen -t rsa -b 4096 -C 'your_email@example.com' 2 Generating public/private rsa key pair. 3 Enter file in which to save the key…
This is part 17 of my journey learning Golang. The fmt package has methods like Print , Println and Printf to print text to the standard output device. It also has corresponding methods that return the strings that would be printed out, instead of actually printing them out. Afterwards the program can use the returned values for any purpose like for instance sending an email or creating a PDF…
This is part 16 of my journey learning Golang. The Printf method The Printf method from the fmt package writes a formatted string to standard output. Printf makes it possible to interpolate strings. This is done by leaving placeholders in a string, and using values to fill in these placeholders. Printf syntax Printf accepts a string argument, potentially with formatting placeholders, and zero or…
Google has a free tool called Search Console that “help you measure your site’s Search traffic and performance, fix issues, and make your site shine in Google Search results”. This is super handy to make sure that your website is being properly indexed by Google, to keep on top of how much traffic it is getting, and to be on the lookout for errors. Registering your website with…
This is part 15 of my journey learning Golang. fmt Package Go’s fmt package implements formatted I/O with formatting functions in the venerable, old-school style of the C language, but modernized. This article covers the most basic functions for printing out text Println and Print : Println The Println method prints outs a line of text to the standard output device. It prints its arguments,…
This is part 14 of my journey learning Golang. As an exercise for Codecademy’s Learn Go course, I wrote my second Go program. It simulates a catalog for a comic book store. At this point the course has only covered the most fundamental parts of Go, like variables, simple data types, basic arithmetic, and printing. Arrays and functions are still out of the picture. For that reason, the…
This is part 13 of my journey learning Golang. Strings in Go Strings represent a sequence of bytes. More specifically, a read-only slice of uint8 integers. Their main use is for representing text. This text is usually, but not necessarily, encoded as UTF-8. In Go, strings can also be used to represent text in any encoding, and also raw bytes, not necessarily corresponding to text. It’s…
This is part 12 of my journey learning Golang. Compile-time errors Go is a compiled language. That means that it will parse the source code and produce an executable binary file from it. The compiler parses the code according to strictly defined rules. That allows Go programs to run more efficiently than if they were interpreted as they run. As a valuable side-effect, it will reveal many kinds of…
This is part 11 of my journey learning Golang. Variables A variable is a named value that can change during the execution of a program. The difference from a constant (which is also a named value) is that a variable’s value can be modified at run time. Variable declarations In Go, variables are declared following this pattern: var {identifier} {type}. Examples: 1 var songName string 2 var…
This is part 10 of my journey learning Golang. Literals In Go, values can be many things. Just to name a few, values can be numbers (like 109), or text wrapped in quotes (like “Hello world”). Literals are values written in the source code. For example: 1 fmt . Println ( 'Hello, world!' ) // String literal 2 fmt . Println ( 42 ) // Integer literal 3 fmt . Println ( 3.141592653589793238…
This is part 9 of my journey learning Golang. Data types are a designation by a programming language about the kind of values that are being stored. Go has several basic data types built in. This article explores boolean, numeric and string data types. See Go’s documentation for more details. Boolean data type Boolean values can be either false (equivalent to 0) or true (equivalent to 1).…
This is part 8 of my journey learning Golang. Reproducible build & run environments Over the years, it is not uncommon that different projects in the same language will have different requirements about the versions of the tools and libraries that they require. For instance, I learned that there are differences in the behavior of the GO111MODULE environment variable across Go versions 1.12 and…
This is part 7 of my journey learning Golang. My first assignment on Codecademy’s Learn Go course was to create a program that prints out ASCII art . The way that’s different from a “Hello, World” program is that it needs to print multiple lines. So it was a great opportunity to learn about how multi-line strings can be represented in Go. Go’s string literals String…
This is part 6 of my journey learning Golang. Books and tutorials A Tour of Go : An introduction that covers the most important features of the language. An Introduction to Programming in Go : A free e-book from 2012. For the Love of Go: Fundamentals : An interactive introduction to the Go programming language, suitable for complete beginners. Introducing Go : An O’Reilly book from 2016.…
This is part 5 of my journey learning Golang. Inline comments Go ignores text to the right of // : 1 // This entire line is ignored by the compiler. 2 // fmt.Println('Does NOT print') 3 fmt . Println ( 'This gets printed!' ) // This part gets ignored Block comments All lines between /* and */ will be ignored: 1 /* 2 This is ignored. 3 This is also ignored. 4 fmt.Println('This WON'T print!') 5 */…
This is part 4 of my journey learning Golang. Function declarations Functions are reusable blocks of code. For example: 1 func main () { 2 fmt . Println ( 'Hello, World!' ) 3 } The func keyword declares a function. It is followed by the function’s name, a list of arguments (delimited by parenthesis) and the function block (delimited by curly braces). main function In Go, the main function is…
This is part 3 of my journey learning Golang. Package declaration The first line of a Go source file is the “package declaration”, defined by the package keyword. This serves a few purposes: It provides a structure for grouping related source files. It provides a mechanism for code reuse. It differentiates between executable packages from utility packages (i.e. libraries). Example: 1…
This is part 2 of my journey learning Golang. Compiling Go programs An individual Go source file can be compiled with the go build command: 1 go build {filename}.go That will produce an executable binary file if the source’s package is main (see Part 3 for more on packages). The resulting binary can be executed with this command: 1 ./{filename} Example: 1 $ go build main.go 2 $ ./main 3…
This is part 1 of my journey learning Golang. The Go programming language (Golang) is becoming more relevant by the day. It is, famously, the language of the Docker and Kubernetes projects. Both have had a huge impact on how companies run applications, and I develop for them on a daily basis. Golang is also seeing increased adotoption at my company. I’m starting on a journey to become more…
I am hosting my blog on GitHub Pages. I wanted to use my own domain name instead of a github.io subdomain. GitHub’s documentation is very helpful. Even so, it took me some effort to figure out all the details, so I’m going to share what I learned. These instructions are for using an “apex domain” e.g. fernandocorreia.dev . The settings are a bit different when using a…
I decided to start a new blog to talk about software development. It’s been about 5 years since I last had a blog, so I went looking for what people are using in 2020. It turns out that Hugo is quite popular for building static sites. Two of its selling points are that it is super fast, and that people have built hundreds of good-looking themes so that you can hit the ground running.