TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

What's the Difference: JSON diff and patch

39 点作者 ggleason超过 3 年前

5 条评论

xmcqdpt2超过 3 年前
While I agree that people generally think of version control (and git) in terms of diff and patch, I think it&#x27;s important to note that git itself doesn&#x27;t have diff and patches. The fact that git doesn&#x27;t have diffs is one of its defining characteristics.<p><a href="https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Getting-Started-What-is-Git%3F" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Getting-Started-What-is-Git%3...</a><p>It makes git significantly faster (because it doesn&#x27;t apply sequence of patches when checking out) and much more robust than a patch and diff system.<p>I think it&#x27;s an important point here because it does play a bit of a counterpoint to the OP&#x27;s argument. In fact, the git storage system is precisely very simple because it&#x27;s content addressed only and has no notion of history or difference,<p><a href="https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Internals-Git-Objects" rel="nofollow">https:&#x2F;&#x2F;git-scm.com&#x2F;book&#x2F;en&#x2F;v2&#x2F;Git-Internals-Git-Objects</a><p>In the article, the author mentions something about Alice and Bob sharing only differences in JSON has a way to simplify changes. If anything the lesson from git&#x27;s success should be that the aurhor&#x27;s approach (the diff&#x2F;patch way of Subversion etc.) is exactly the wrong one. Communicating only with full, valid JSONs and showing diffs only as a convenience to the user would be the actual &quot;git way&quot;.
评论 #30377411 未加载
bradjonesca超过 3 年前
The ability to accommodate CRDT&#x27;s in the architecture (future) is a gamechanger
jitl超过 3 年前
The article discusses the shortcoming of CRDTs - sometimes you <i>do</i> want a conflict that a human can resolve, instead of an algorithms best guess:<p>&gt; This conflict can be surfaced to Alice, and Bob can be allowed to go about his business. Could this particular problem be resolved in a purely automatic way with a CRDT? Definitely, but it probably will not result in what you want. Last first will work of course, but then which is more right might need human review, and even worse it might result in both results being interleaved (a likely outcome!).<p>The article goes on to suggest that with a system of sharing patches, we can synchronize our distributed data stores with more precise semantics, even if we do need human intervention on conflicts sometimes. Part of this is agreeing on patch order:<p>&gt; We can stack either patch in any order without difficulty. Perhaps we ask Bob and Alice to agree on the application order (using pull &#x2F; push as is done with git). But maybe we just allow them to apply when they arrive. The answer depends on the workflow.<p>Do you know what a system that works like pull-&gt;rebase-&gt;push sounds like to me? If you squint a little? This sounds like operational transforms [1]. Especially if you are considering multiple different patching semantics -<p>&gt; Which of these you want, however, requires semantic direction of the diff algorithm. While lots of structured diff problems will be solved by the simplest algorithm, ultimately we need to have a schema that helps to direct the meaning of our diffs. String fields might be best line-based, word-based, or perhaps they must always be atomic (as with identifiers).<p>Each patching semantic is a different type of Operation. Rebasing your local changes before sending your pending patches is the Transform. The main advantage of OT systems over CRDTs is that OT also allows for conflicts &amp; human in the loop conflict resolution. @josephg built a JSON Operational Transform library [2] that has interesting operations like Move (something diff&#x2F;patch really struggles with) as well as conflict resolution.<p>The thing I like about the OT model is that it’s pretty easy to <i>nest</i> other approaches inside OT. Want to express 5 different patch semantics? Make an operation type for each. Want to support CRDT as well? Sure, make an operation type called CRDTUpdate that contains whatever delta data the underlying CRDT system would send.<p>No matter what strategy you pick, remember to fuzz test your distributed sync system for convergence.<p>[1]: <a href="https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Operational_transformation" rel="nofollow">https:&#x2F;&#x2F;en.m.wikipedia.org&#x2F;wiki&#x2F;Operational_transformation</a><p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;ottypes&#x2F;json1" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;ottypes&#x2F;json1</a>
评论 #30377212 未加载
评论 #30376603 未加载
littlestymaar超过 3 年前
&gt; web3<p>oh no.
评论 #30364290 未加载
ninja_daro_yco超过 3 年前
We already have json patch(<a href="http:&#x2F;&#x2F;jsonpatch.com&#x2F;" rel="nofollow">http:&#x2F;&#x2F;jsonpatch.com&#x2F;</a>) and we can sent diffs as json patch document, so I don&#x27;t understand what is the purpose of this proposal.
评论 #30363868 未加载
评论 #30363820 未加载
评论 #30366101 未加载