Skip to content

Learning with AI

I recently got into working with Golang, and I think using the protobuf abstraction is really nice. It makes the serialization and consumption of data super easy, and I was having a good experience with it. I enjoy the fact that I can easily have a spec that generates the required types in the languages that I'm trying to use.

I'm kind of trying to learn, but I'm not really typing out the Go code myself. I'm just giving intent in very small windows, getting that code to work, and then tweaking it very slightly here and there. I realize Claude Code tends to make changes that are too big, so what I need to do is copy the code into Claude and just manually load up the context.

I've been trying to write out my questions, and some of them are pretty basic - like one of them was about why the numbers in protobuf work the way they do.

My Question:

can u have diffrernt ordered or duplicates?

Claude's Response:

Different ordering: Yes, you can define fields in any order you want. The field numbers are what matter, not the order they appear in the .proto file.

protobuf
// These are equivalent:
message SearchRequest {
  string query = 1;
  int32 page_number = 2;
  int32 results_per_page = 3;
}

message SearchRequest {
  int32 results_per_page = 3;
  string query = 1;
  int32 page_number = 2;
}

Duplicate field numbers: No, you cannot have duplicate field numbers within the same message - this will cause a compilation error.

protobuf
// This is INVALID:
message SearchRequest {
  string query = 1;
  int32 page_number = 1;  // Error! Field number 1 already used
}

However, you can:

  • Reuse field numbers across different messages
  • Have gaps in your numbering (like 1, 2, 5, 10)
  • Reserve field numbers that you don't want used
protobuf
message SearchRequest {
  string query = 1;
  int32 page_number = 5;  // Skipping 2, 3, 4 is fine
}

message SearchResponse {
  string query = 1;  // Same number as SearchRequest.query is OK
}

The key rule: field numbers must be unique within each individual message definition.

Claude answered me pretty well, so I think using AI to learn is a really good experience. I expected this mainly because I don't use it to substitute thinking - I use it to explain concepts in detail, and I load the context manually.