Hacker News new | ask | show | jobs
by groovy2shoes 3694 days ago
Any good reason not to just use a single sign bit?
1 comments

Honestly, no, there's no "good" reason.

In practice the reason it ended up designed this way is because varint was introduced first with no special support for negative numbers, and then zigzag was introduced years later. Zigzag worked well because it stacked on top of the existing varint parser without changing it.

But for a new format with no backwards-compatibility constraints, it would probably make much more sense to use sign extension (so, the first encoded bit becomes the sign bit).

(I am the person who rewrote and open sourced protobufs at Google, though I am not the inventor.)

Cool. Thanks :)