3 ms·
I don't see it in Java or C# for instance. You have to explicitly opt into it by (1) declaring default (parameter-less constructors), and (2) exposing fields yo
by apta 7y ago
I don't see it in Java or C# for instance. You have to explicitly opt into it by (1) declaring default (parameter-less constructors), and (2) exposing fields you want mutated via setters.
On the other hand, golang does not have the ability to prevent "default constructors", and the fact that it has no ability to make types file private further makes this an issue.
- tptacek 7y agoJava initializes variables to their zero values. If you want to hide Go struct members from other "files", you can do that trivially by putting them in subdirectories.
- apta 7y ago> Java initializes variables to their zero values I know, but that's not what I'm referring to here. I'm referring to someone writing: type A struct { A int B int } a := A {A: 1, B: 2} then modifying `A` by adding another field `C int` The code continues to compile, with `C` being initialized to 0, which can be incorrect. In Java or C#, you'd add a third value to the constructor, resulting in a compile time error for all constructor invocations. As I said, I've seen this issue come up in production resulting in bugs.
- tptacek 7y agoI don’t doubt it causes bugs. I wish Go had option types, as well. I’m just saying that it’s not unusual behavior, and you’re going to single languages out for the bugs they enable, you’ve a long future of boring arguments ahead of you.
- deleted 7y ago[deleted]