Preface It’s been almost 6 years since I added to this series, but I thought it was time to resume working on it. Since “perfect is the opposite of done” I thought I would talk about a simple pattern that I haven’t covered yet. A couple of years ago I worked on a toy library to see if the new-ish generics proposal would finally allow to express some of the most common…
Preface In my previous post I summarized the latest generics proposal for Go. In this post I’m gonna use it a bit, and misuse it a lot. The problem Sometimes I find myself writing code to run the same function in parallel with itself with different inputs, for example to process a batch of data. This is not super complicated code, but it’s not exactly straightforward and can sometimes…
Preface Go doesn’t have generics yet, but there is a proposal that looks promising, and this post refers to that. Here is a version of the playground you can use to try this proposal out if you want to experiment without installing any tools. Functions Converting a slice into a channel. This is not necessarily the most useful function but it’s a good and simple example: func…
Disclaimer: this is not an official Google post or communication, it is just me commenting on something that is now available. The Google infosec team just released the Go “safehtml” package. If you are interested in making your application resilient to server-side XSS you might want to adopt it instead of “html/template”. Migration to safehtml should be quite…
After 5 years of using Go I am finally moving on. Go has served me well and has been the best language I could have possibly used for the longest time, but it is now the moment for me to let it Go. Over time Go has not failed to show me its limitations and its issues, to the point where I decided to switch to something more future proof and with a more thriving community.
Race conditions are the main problem you have to care about when writing concurrent code. Go provides high level primitives that make it easier to get concurrency and parallelism right, but those are often times not enough. This is one of the reasons why Go has a race detector. You should always run your tests and, where possible, a portion of your production fleet with -race enabled. Beware that…
Edit (16 Dec 2024) This post is still here for historical reasons, but it’s now quite old. The sync package has evolved since then and some primitives have become available. While all the channel and select semantics have stayed the same, please consider this as a post on how to better understand channels semantics rather than documentation or replacement for the sync package. Previous Post…
This post is part of my developer-friendly security series. You can find all other posts here. XSS is a vulnerability that allows attackers to run arbitrary JavaScript code in applications they shouldn’t be able to control. This can lead to complete account compromises for every victim that follows a malicious link or visits a compromised page. There are two major families of XSS: server…
Welcome to this introductory series on web security. I’ll use simple snippets and hands-on examples to introduce fundamentals on the topic. Most server-side code will be in Go but you’ll be able to understand it if you know any C-like language. This first post is about the fundamentals: URI, HTTP, TLS, HTML, escaping and cookies. If you are already familiar with those concepts please…
I’m not a big fan of JavaScript but I like parallel programming and JS has some interesting concepts of it. In addition to the event loop I’ve recently got to know the concept of Web Workers. They are real threads that execute in parallel with the main thread, and are allowed to wait and block as much as they want. Modern devices are going in the direction of having a lot of FPS and…
As I stated in my previous article timers are hard to use the right way so here are some handful tips. Edit (16 Dec 2024) This post is still here for historical reasons, but it’s now quite old. Many of the issues in this post have been corrected and some footguns don’t hold true anymore. Please consider this as a window into a “previous Go experience” and nothing more.
Writing code is hard. Writing code that has to deal with parallelism and concurrency is harder. Doing all of that an keeping it efficient is challenging. Today I decided to start sharing a couple of tricks to handle some peculiar cases. Timed channels operations Sometimes you want to time your channels operations: keep trying to do something, and if you can’t do it in time just drop the…
Preface One of the features that I love the most about Go is the fact that it is unsurprising. One could even say that it is boring in some sense. This is a good trait of a programming language. When you code you should focus on the problem at hand, and not on what your language is doing that you don’t want. This article talks about one of the most “surprising” features of Go for…
I want to tell you a story somebody shared with me. Nobody knows where the story comes from, or who invented it, but now it’s widely used as an exercise to improve communication skills. I changed the names of the characters in order to be gender neutral, so, please, bear with me as some sentences are bulky. Once upon a time, a long long time ago, there was a town. The town was cut in two…
Coming from a VB.Net, Java, C# and Python background, when I first started using Go I was very annoyed by the lack of some patterns on a language level. It took me a while using the language to find out those patterns can be easily expressed. Here is a collection of some common patterns and the best way I’ve found to express them. Decorators This feature is extensively used in most object…
The story Sometimes you have to solve a problem that comes in several flavours. Usually complicated problems do not offer a single solution, but there are several solutions that are optimal or terrible depending on which subset of that problem the program will have to solve at runtime. One example I faced was to analyse some data flowing in some connections that I was proxying. There are two main…
You wake up one Sunday morning and think: “how the hell does that thing work?”. So you go and google for it and find several blog posts, talks and papers about the topic. During your research you find out some more detailed parts of the topic, so you search the web for it again and find out more. After several hours you find out something very interesting, many layers deeper than where…
Preface I love using regular expressions. They are such a powerful tool, they are complex, concise, complex, expressive, complex, broadly supported, complex and easy to write. They are the perfect tool if you want to write a simple script and you need to elaborate text. Some downsides are that they are complex, surprising, and very inefficient compared with simpler string manipulations primitives…
Short preface: The first version of JavaScript was completed in ten days in order to accommodate the Netscape Navigator 2.0 Beta release schedule. Keep in mind that well structured languages usually take a little bit more than that. What follows is a small piece of the aftermath of the rushed job. NOTE: There is more madness in destroy all software’s wat video, which I suggest watching…
The impact The first language I used to build something more than just school exercises was VisualBasic.Net. There are some good things and bad things in it, but I don’t want to discuss that today. I switched to C# after that and Java and Python after it. This is to say that basically up until three years ago I knew one and only one way to handle errors which is expressed in the following…
The problem Some days ago I was looking at some configuration files that were presented in this form: # # This is a section # VALUE_ENABLED=y # VALUE_DISABLED The problem in reading this stuff is that both comments and non-comments are relevant and none should be ignored since a disabled feature could cause as much trouble as an enabled one. I would have liked to see comments in a different file…
Unmarshaling JSON files in Golang can be tricky. Golang is a statically typed language and does not allow dynamic JSON deserialization. In order to unmarshal a JSON blob into Golang it usually requires to know its structure beforehand. But, as the internal documentation states, it is possible to unmarshal JSON into an empty interface. An empty interface represents the empty set of methods and is…
This last weekend I flew to Hawaii for the first time in my life. What. An. Experience. Before leaving I read a couple of travel guides online, but nothing prepared me for the beauty of this island. The flight I chose was on a Friday night. By 0330 I was done with my work for the week; quickly grabbed enough clothes for 4 days, my travel backpack and I was on a Lyft to the airport.