title: Protocol buffers - unique numbered tag - clarification?
body: <p>I'm using protocol buffers  and everything is working fine. except that the fact that I don't understand  - why do I need the numbered tags in the <code>proto</code> file : </p>
  
  <pre><code>message SearchRequest {
    required string query = 1;
    optional int32 page_number = 2;
    optional int32 result_per_page = 3;
  }
  </code></pre>
  
  <p>Sure I've read the <a href="https://developers.google.com/protocol-buffers/docs/proto" rel="noreferrer"><strong>docs</strong></a> : </p>
  
  <blockquote>
    <p>As you can see, each field in the message definition has a unique
    numbered tag. These tags are used to identify your fields in the
    message binary format, and should not be changed once your message
    type is in use. </p>
  </blockquote>
  
  <p>I didn't understand what difference does it make if I change it . ( I will create a new proto and compile it  - so why does it care ?)</p>
  
  <p><a href="http://blog.codeclimate.com/blog/2014/06/05/choose-protocol-buffers/" rel="noreferrer">Another article states that :</a> </p>
  
  <blockquote>
    <p>Numbered fields in proto definitions obviate the need for version
    checks which is one of the explicitly stated motivations for the
    design and implementation of Protocol Buffers. As the developer
    documentation states, the protocol was designed in part to avoid “ugly
    code” like this for checking protocol versions:</p>
  </blockquote>
  
  <pre><code>if (version == 3) {
    ...
  } else if (version &gt; 4) {
    if (version == 5) {
      ...
    }
    ...
  }
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>Is it just me or it is completely unclear ?</p>
  
  <p>let me ask it in a different way : </p>
  
  <p>If I have a proto file like the above file , and then I change it to : </p>
  
  <pre><code>message SearchRequest {
    required string query = 3; //reversed order
    optional int32 page_number = 2;
    optional int32 result_per_page = 1;
  }
  </code></pre>
  
  <p>What does it care ? I re-compile and add the file ( i've done it multiple times in the last week).</p>
  
  <p>what am I missing ? can you please supply a human-to human explanation  for this numbered tags ?</p>