I'm also bothered by half-constructed objects. In my previous job, I was on a team creating a Go project that integrated two different parts of the company. It was an HR company, with lots of random fields in objects.
The API given to us often returned objects with only certain values filled out. Go encourages this, because there it is so easy to do that. `StructName{}` will create a struct, and is easier than filling out values. It will fill out all the values with the "zero value" of the thing.
And there's no way to know if you have a zero value! I would commonly get back an object and have to dig into the code or ask people to find out when certain values would be filled out!
Compare to a language where you have to provide a constructor. Fewer people would write:
public ClassName() { var1 = 0; var2 = ""; }
It lead me to be able to trust values less than I had to in other languages I've used.
I'm also bothered by half-constructed objects. In my previous job, I was on a team creating a Go project that integrated two different parts of the company. It was an HR company, with lots of random fields in objects.
The API given to us often returned objects with only certain values filled out. Go encourages this, because there it is so easy to do that. `StructName{}` will create a struct, and is easier than filling out values. It will fill out all the values with the "zero value" of the thing.
And there's no way to know if you have a zero value! I would commonly get back an object and have to dig into the code or ask people to find out when certain values would be filled out!
Compare to a language where you have to provide a constructor. Fewer people would write:
public ClassName() {
var1 = 0;
var2 = "";
}
It lead me to be able to trust values less than I had to in other languages I've used.