Antonin Carette

Machine Learning Engineer & Software Developer

Recent posts

Sep 15, 2019
A strange strings comparison problem, in Go

Thanks to https://github.com/egonelbre/gophers for this sketch Go is known for it’s strong type system, and explicit type conversion. For example, if you have to compare two different values of different types, you will have a compiler error: package main import "fmt" func main() { var x int = 0 var y int32 = 0 fmt.Printf("%+v", x == y) } If you try to compile this code sample, you will have to deal with the following error, reached during compilation:

Apr 16, 2019
(Un)marshal complex JSON objects, in Go

If you work a lot with APIs in Go, it may happen you have to work with complex JSON responses… Ok, let’s talk about that using a simple example. Imagine you have to work with the following data structure, which represents a Person data structure (like a real person, no trap) with the following characteristics: the name of a Person object: a string; the dog’s name of the Person object (if it exists): a Dog structure that contains only a string, which is its name; the age of the Person object: an integer; the last time the data structure has been updated: a datetime type.

Feb 20, 2019
2019, as minimalistic

I became fed up with my electronic materials. The way we evolve, as city dwellers, implies sometimes to adopt a non-minimalistic approach to live: * to have one device to make only one thing, * to have different devices that can be used to make the same thing, * to buy expensive things based on good ads, * to buy expensive things based on what you can do (and finally things you will never do), …

Nov 6, 2018
Struct embedding trick to avoid duplicate code

When you are writing go code, and try to make it more flexible, most of the time you are looking for interfaces. A go interface is a good solution to make your code more flexible, or scalable, and is also a way to achieve polymorphism. As the official go documentation discusses about interfaces, interfaces are “named collections of method signatures”. So, to implement an interface on different structs, you have to implement each interface’s method for a given struct.

Nov 3, 2018
`go mod`: manage all your dep as a single unit

Generally, when you want to package your go app, you are creating different packages, inside the same project. The problem is, if you want to use a single internal package, you simply can’t, because you have to import the entire package in order to user a single and very simple feature inside. But, sometimes, you don’t want to use a single extenal package. Indeed, you just want to use a certain number of packages to do a task, and all compatible between them.

All articles →