diff options
Diffstat (limited to 'search.xml')
| -rw-r--r-- | search.xml | 287 |
1 files changed, 148 insertions, 139 deletions
@@ -1139,6 +1139,67 @@ </tags> </entry> <entry> + <title>OCaml News 2024-5</title> + <url>/2024/06/27/OCaml-News-2024-5/</url> + <content><![CDATA[<h2 id="语言的发展"><a href="#语言的发展" class="headerlink" title="语言的发展"></a>语言的发展</h2><ul> +<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13097">Immutable arrays #13097: This PR proposes to add immutable arrays to OCaml.</a></li> +<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13199">Support running native debuggers in ocamltest #13199</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13152">The Pattern-Matching Bug: fix totality information by gasche · Pull Request #13152 · ocaml/ocaml</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/11974%23discussion_r1621832545">Add loongarch architecture support #11974</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13101">Add Stdlib.todo #13101</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-26-enhancing-the-ocaml-org-community-page-boosting-ux-and-ui-based-on-user-research/">Enhancing the OCaml.org Community Page: Boosting UX and UI Based on User Research.</a></li> +<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-05-22-launching-the-first-class-windows-project/">Launching the First-Class Windows Project</a>.</li> +</ul> +<h2 id="新消息"><a href="#新消息" class="headerlink" title="新消息"></a>新消息</h2><ul> +<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-project-wide-occurrences-in-merlin-and-lsp/14847">[ANN] Project wide occurrences in Merlin and LSP</a>.</p> +</li> +<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-opam-2-2-0-rc1-release/14842">[ANN] opam 2.2.0 rc1 release</a>.</p> +</li> +<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-first-release-of-baby/14840">[ANN] First release of baby</a>.</p> +</li> +<li><p><a href="https://link.zhihu.com/?target=https://github.com/fpottier/baby">baby</a> is an OCaml library that offers several implementations of balanced binary search trees.</p> +</li> +<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-preview-of-stripe-client-and-mock-server-dkstdrestapis/14841">[ANN] Preview of Stripe client and mock server - DkStdRestApis</a>.</p> +</li> +<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-caisar-release-2-0-a-platform-for-characterizing-ai-safety-and-robustness/14831">[ANN] CAISAR release 2.0, a platform for characterizing AI safety and robustness</a>.</p> +</li> +<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-forester-4-1/14800">[ANN] Forester 4.1</a>.</p> +</li> +<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-dream-html-pure-html-3-5-2/14808">[ANN] dream-html & pure-html 3.5.2</a></p> +</li> +</ul> +<h2 id="有价值的文章"><a href="#有价值的文章" class="headerlink" title="有价值的文章"></a>有价值的文章</h2><ul> +<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-19-keeping-up-with-the-compiler-how-we-help-maintain-the-ocaml-language/">Keeping Up With the Compiler: How we Help Maintain the OCaml Language</a></li> +<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/10995">Explain mapping between OCaml memory model and C.</a></li> +<li><a href="https://link.zhihu.com/?target=https://xavierleroy.org/CdF/2023-2024/index.html">Control structures – Xavier Leroy</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://dev.to/chshersh/8-months-of-ocaml-after-8-years-of-haskell-in-production-h96">8 months of OCaml after 8 years of Haskell in production</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://hypirion.com/musings/getting-ocaml-through-the-eye-of-a-needle">Getting OCaml Through the Eye of a Needle</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-05-secure-from-the-ground-up-introducing-the-fides-project-combining-risc-v-and-mirageos/">Secure From the Ground Up: Introducing the FIDES Project Combining RISC-V and MirageOS.</a></li> +<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-05-29-effective-ml-through-merlin-s-destruct-command/">Effective ML Through Merlin’s Destruct Command.</a></li> +<li><a href="https://link.zhihu.com/?target=https://blog.osau.re/articles/reproducible.html">Dinosaure’s website - Reproducibility!</a></li> +<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/experiments-in-jitting/14853">Experiments in JITting</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/how-to-write-an-efficient-cp-r-clone-with-eio/14848">How to write an efficient ‘cp -R’ clone with Eio?</a></li> +<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/generating-infix-extension-nodes-with-ppxlib/14833">Generating infix extension nodes with Ppxlib</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/this-made-my-day-float-to-string-and-string-of-float-without-loss-of-precision/14825">This made my day (float to string and string of float without loss of precision)</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/help-with-cryptic-dependency-cycle-compile-errors-using-dune-build/14864">Help with cryptic dependency cycle compile errors using <code>dune build</code></a>.</li> +<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/why-does-relaxed-value-restriction-treat-function-types-differently/14802">Why does relaxed value restriction treat function types differently?</a></li> +<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/binding-existentials-in-a-non-uniform-gadt/14809">Binding existentials in a non-uniform GADT</a>.</li> +</ul> +<h2 id="有趣的项目"><a href="#有趣的项目" class="headerlink" title="有趣的项目"></a>有趣的项目</h2><ul> +<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/ocaml-index/latest">ocaml-index 1.0 (latest) · OCaml Package: A tool that indexes value usages from cmt files</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/fileutils/latest">fileutils 0.6.4 (latest) · OCaml Package: API to manipulate files (POSIX like) and filenames.</a></li> +<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/pure-html/latest">pure-html 3.5.2 (latest) · OCaml Package</a></li> +<li><a href="https://link.zhihu.com/?target=https://github.com/fpottier/baby">GitHub - fpottier/baby: A balanced binary search tree library for OCaml</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://github.com/akabe/ocaml-jupyter">GitHub - akabe/ocaml-jupyter: An OCaml kernel for Jupyter (IPython) notebook</a>.</li> +<li><a href="https://link.zhihu.com/?target=https://github.com/robur-coop/orb">Github - robur-coop/orb: check opam package reproductibility.</a></li> +<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml-multicore/dscheck%23motivation">Github - ocaml-multicore/dscheck: Experimental model checker for testing concurrent algorithms.</a></li> +</ul> +]]></content> + <tags> + <tag>Technique</tag> + </tags> + </entry> + <entry> <title>OCaml News 2024-4</title> <url>/2024/07/01/OCaml-News-2024-4/</url> <content><![CDATA[<h2 id="那么接下来"><a href="#那么接下来" class="headerlink" title="那么接下来"></a>那么接下来</h2><ul> @@ -1258,67 +1319,6 @@ </tags> </entry> <entry> - <title>OCaml News 2024-5</title> - <url>/2024/06/27/OCaml-News-2024-5/</url> - <content><![CDATA[<h2 id="语言的发展"><a href="#语言的发展" class="headerlink" title="语言的发展"></a>语言的发展</h2><ul> -<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13097">Immutable arrays #13097: This PR proposes to add immutable arrays to OCaml.</a></li> -<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13199">Support running native debuggers in ocamltest #13199</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13152">The Pattern-Matching Bug: fix totality information by gasche · Pull Request #13152 · ocaml/ocaml</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/11974%23discussion_r1621832545">Add loongarch architecture support #11974</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/13101">Add Stdlib.todo #13101</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-26-enhancing-the-ocaml-org-community-page-boosting-ux-and-ui-based-on-user-research/">Enhancing the OCaml.org Community Page: Boosting UX and UI Based on User Research.</a></li> -<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-05-22-launching-the-first-class-windows-project/">Launching the First-Class Windows Project</a>.</li> -</ul> -<h2 id="新消息"><a href="#新消息" class="headerlink" title="新消息"></a>新消息</h2><ul> -<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-project-wide-occurrences-in-merlin-and-lsp/14847">[ANN] Project wide occurrences in Merlin and LSP</a>.</p> -</li> -<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-opam-2-2-0-rc1-release/14842">[ANN] opam 2.2.0 rc1 release</a>.</p> -</li> -<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-first-release-of-baby/14840">[ANN] First release of baby</a>.</p> -</li> -<li><p><a href="https://link.zhihu.com/?target=https://github.com/fpottier/baby">baby</a> is an OCaml library that offers several implementations of balanced binary search trees.</p> -</li> -<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-preview-of-stripe-client-and-mock-server-dkstdrestapis/14841">[ANN] Preview of Stripe client and mock server - DkStdRestApis</a>.</p> -</li> -<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-caisar-release-2-0-a-platform-for-characterizing-ai-safety-and-robustness/14831">[ANN] CAISAR release 2.0, a platform for characterizing AI safety and robustness</a>.</p> -</li> -<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-forester-4-1/14800">[ANN] Forester 4.1</a>.</p> -</li> -<li><p><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/ann-dream-html-pure-html-3-5-2/14808">[ANN] dream-html & pure-html 3.5.2</a></p> -</li> -</ul> -<h2 id="有价值的文章"><a href="#有价值的文章" class="headerlink" title="有价值的文章"></a>有价值的文章</h2><ul> -<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-19-keeping-up-with-the-compiler-how-we-help-maintain-the-ocaml-language/">Keeping Up With the Compiler: How we Help Maintain the OCaml Language</a></li> -<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml/ocaml/pull/10995">Explain mapping between OCaml memory model and C.</a></li> -<li><a href="https://link.zhihu.com/?target=https://xavierleroy.org/CdF/2023-2024/index.html">Control structures – Xavier Leroy</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://dev.to/chshersh/8-months-of-ocaml-after-8-years-of-haskell-in-production-h96">8 months of OCaml after 8 years of Haskell in production</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://hypirion.com/musings/getting-ocaml-through-the-eye-of-a-needle">Getting OCaml Through the Eye of a Needle</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-06-05-secure-from-the-ground-up-introducing-the-fides-project-combining-risc-v-and-mirageos/">Secure From the Ground Up: Introducing the FIDES Project Combining RISC-V and MirageOS.</a></li> -<li><a href="https://link.zhihu.com/?target=https://tarides.com/blog/2024-05-29-effective-ml-through-merlin-s-destruct-command/">Effective ML Through Merlin’s Destruct Command.</a></li> -<li><a href="https://link.zhihu.com/?target=https://blog.osau.re/articles/reproducible.html">Dinosaure’s website - Reproducibility!</a></li> -<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/experiments-in-jitting/14853">Experiments in JITting</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/how-to-write-an-efficient-cp-r-clone-with-eio/14848">How to write an efficient ‘cp -R’ clone with Eio?</a></li> -<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/generating-infix-extension-nodes-with-ppxlib/14833">Generating infix extension nodes with Ppxlib</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/this-made-my-day-float-to-string-and-string-of-float-without-loss-of-precision/14825">This made my day (float to string and string of float without loss of precision)</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/help-with-cryptic-dependency-cycle-compile-errors-using-dune-build/14864">Help with cryptic dependency cycle compile errors using <code>dune build</code></a>.</li> -<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/why-does-relaxed-value-restriction-treat-function-types-differently/14802">Why does relaxed value restriction treat function types differently?</a></li> -<li><a href="https://link.zhihu.com/?target=https://discuss.ocaml.org/t/binding-existentials-in-a-non-uniform-gadt/14809">Binding existentials in a non-uniform GADT</a>.</li> -</ul> -<h2 id="有趣的项目"><a href="#有趣的项目" class="headerlink" title="有趣的项目"></a>有趣的项目</h2><ul> -<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/ocaml-index/latest">ocaml-index 1.0 (latest) · OCaml Package: A tool that indexes value usages from cmt files</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/fileutils/latest">fileutils 0.6.4 (latest) · OCaml Package: API to manipulate files (POSIX like) and filenames.</a></li> -<li><a href="https://link.zhihu.com/?target=https://ocaml.org/p/pure-html/latest">pure-html 3.5.2 (latest) · OCaml Package</a></li> -<li><a href="https://link.zhihu.com/?target=https://github.com/fpottier/baby">GitHub - fpottier/baby: A balanced binary search tree library for OCaml</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://github.com/akabe/ocaml-jupyter">GitHub - akabe/ocaml-jupyter: An OCaml kernel for Jupyter (IPython) notebook</a>.</li> -<li><a href="https://link.zhihu.com/?target=https://github.com/robur-coop/orb">Github - robur-coop/orb: check opam package reproductibility.</a></li> -<li><a href="https://link.zhihu.com/?target=https://github.com/ocaml-multicore/dscheck%23motivation">Github - ocaml-multicore/dscheck: Experimental model checker for testing concurrent algorithms.</a></li> -</ul> -]]></content> - <tags> - <tag>Technique</tag> - </tags> - </entry> - <entry> <title>OCaml News 2024-6</title> <url>/2024/07/23/OCaml-News-2024-6/</url> <content><![CDATA[<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line"> ^o3</span><br><span class="line">~/\_/\_|)</span><br><span class="line">|/=_=\|</span><br><span class="line">" "</span><br></pre></td></tr></table></figure> @@ -2091,6 +2091,49 @@ </tags> </entry> <entry> + <title>TypeScript With Rust Errors, No Try Catch, Heresy</title> + <url>/2023/04/30/TypeScript-With-Rust-Errors-No-Try-Catch-Heresy/</url> + <content><![CDATA[<blockquote> +<p>It’s hard to miss things when you don’t know different things exist</p> +</blockquote> +<p>The first problem is, and personally, I believe it’s the biggest JavaScript problem ever: we don’t know what can throw an error. From a JavaScript error perspective, it’s the same as the following:</p> +<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">let</span> data = “<span class="title class_">Hello</span>”;</span><br><span class="line">} <span class="keyword">catch</span> (err) {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">error</span>(err);</span><br><span class="line">}</span><br></pre></td></tr></table></figure> + +<p>JavaScript doesn’t know; JavaScript doesn’t care. You should know.</p> +<p>Second thing, this is perfectly viable code:</p> +<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> request = { <span class="attr">name</span>: “test”, <span class="attr">value</span>: <span class="number">2n</span> };</span><br><span class="line"><span class="keyword">const</span> body = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(request);</span><br><span class="line"><span class="keyword">const</span> response = <span class="keyword">await</span> <span class="title function_">fetch</span>(<span class="string">"https://example.com"</span>, {</span><br><span class="line"> <span class="attr">method</span>: “<span class="variable constant_">POST</span>”,</span><br><span class="line"> body,</span><br><span class="line">});</span><br><span class="line"><span class="keyword">if</span> (!response.<span class="property">ok</span>) {</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure> + +<p>No errors, no linters, even though this can break your app.</p> +<p>Right now, in my head, I can hear, “What’s the problem, just use try/catch everywhere.” Here comes the third problem: we don’t know which one is thrown. Of course, we can somehow guess by the error message, but what about bigger services/functions with many places where errors can happen? Are you sure you are handling all of them properly with one try/catch?</p> +<hr> +<figure class="highlight rust"><table><tr><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="variable">greeting_file_result</span> = File::<span class="title function_ invoke__">open</span>(“hello.txt”); </span><br><span class="line"><span class="keyword">let</span> <span class="variable">greeting_file</span> = <span class="keyword">match</span> greeting_file_result { </span><br><span class="line"> <span class="title function_ invoke__">Ok</span>(file) => file, </span><br><span class="line"> <span class="title function_ invoke__">Err</span>(error) => <span class="built_in">panic!</span>(<span class="string">"Problem opening the file: {:?}"</span>, error), </span><br><span class="line">};</span><br></pre></td></tr></table></figure> + +<p>The most verbose of the three shown here and, ironically, the best one. So, first of all, Rust handles the errors using its amazing enums (they are not the same as TypeScript enums!). Without going into detail, what is important here is that it uses an enum called <code>Result</code> with two variants: <code>Ok</code> and <code>Err</code>. As you might guess, <code>Ok</code> holds a value and <code>Err</code> holds…surprise, an error :D.</p> +<p>The summary here is that Rust always know where there might be an error. And it force you to deal with it right where it appears (mostly). No hidden ones, no guessing, no breaking app with a surprise face.</p> +<p>And this approach is just better. By A MILE.</p> +<p>We cannot make TypeScript errors work like the Rust. The limiting factor here is the language itself; it doesn’t have the proper tools to do that.</p> +<p>But what we can do is try to make it similar. And make it simple:</p> +<figure class="highlight typescript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">type</span> <span class="title class_">Safe</span><T> = </span><br><span class="line"> | { </span><br><span class="line"> <span class="attr">success</span>: <span class="literal">true</span>; </span><br><span class="line"> <span class="attr">data</span>: T; </span><br><span class="line"> } </span><br><span class="line"> | { </span><br><span class="line"> <span class="attr">success</span>: <span class="literal">false</span>; </span><br><span class="line"> <span class="attr">error</span>: <span class="built_in">string</span>; </span><br><span class="line"> };</span><br></pre></td></tr></table></figure> + +<p>we do need a few try/catches. The good thing is we only need about two, not 100,000:</p> +<figure class="highlight typescript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">function</span> safe<T>(<span class="attr">promise</span>: <span class="title class_">Promise</span><T>, err?: <span class="built_in">string</span>): <span class="title class_">Promise</span><<span class="title class_">Safe</span><T>>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">function</span> safe<T>(<span class="attr">func</span>: <span class="function">() =></span> T, err?: <span class="built_in">string</span>): <span class="title class_">Safe</span><T>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">function</span> safe<T>(</span><br><span class="line"> <span class="attr">promiseOrFunc</span>: <span class="title class_">Promise</span><T> | (<span class="function">() =></span> T),</span><br><span class="line"> err?: <span class="built_in">string</span>,</span><br><span class="line">): <span class="title class_">Promise</span><<span class="title class_">Safe</span><T>> | <span class="title class_">Safe</span><T> {</span><br><span class="line"> <span class="keyword">if</span> (promiseOrFunc <span class="keyword">instanceof</span> <span class="title class_">Promise</span>) {</span><br><span class="line"> <span class="keyword">return</span> <span class="title function_">safeAsync</span>(promiseOrFunc, err);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="title function_">safeSync</span>(promiseOrFunc, err);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> safeAsync<T>(</span><br><span class="line"> <span class="attr">promise</span>: <span class="title class_">Promise</span><T>, </span><br><span class="line"> err?: <span class="built_in">string</span></span><br><span class="line">): <span class="title class_">Promise</span><<span class="title class_">Safe</span><T>> {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">const</span> data = <span class="keyword">await</span> promise;</span><br><span class="line"> <span class="keyword">return</span> { data, <span class="attr">success</span>: <span class="literal">true</span> };</span><br><span class="line"> } <span class="keyword">catch</span> (e) {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">error</span>(e);</span><br><span class="line"> <span class="keyword">if</span> (err !== <span class="literal">undefined</span>) {</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: err };</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (e <span class="keyword">instanceof</span> <span class="title class_">Error</span>) {</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: e.<span class="property">message</span> };</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: <span class="string">"Something went wrong"</span> };</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> safeSync<T>(</span><br><span class="line"> <span class="attr">func</span>: <span class="function">() =></span> T, </span><br><span class="line"> err?: <span class="built_in">string</span></span><br><span class="line">): <span class="title class_">Safe</span><T> {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">const</span> data = <span class="title function_">func</span>();</span><br><span class="line"> <span class="keyword">return</span> { data, <span class="attr">success</span>: <span class="literal">true</span> };</span><br><span class="line"> } <span class="keyword">catch</span> (e) {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">error</span>(e);</span><br><span class="line"> <span class="keyword">if</span> (err !== <span class="literal">undefined</span>) {</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: err };</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (e <span class="keyword">instanceof</span> <span class="title class_">Error</span>) {</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: e.<span class="property">message</span> };</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: <span class="string">"Something went wrong"</span> };</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure> + +<p>This is just a wrapper with our <code>Safe</code> type as the return one. But sometimes simple things are all you need. Let’s combine them with the example from above.</p> +<figure class="highlight typescript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> request = { <span class="attr">name</span>: “test”, <span class="attr">value</span>: <span class="number">2n</span> }; </span><br><span class="line"><span class="keyword">const</span> body = <span class="title function_">safe</span>( </span><br><span class="line"> <span class="function">() =></span> <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(request), </span><br><span class="line"> “<span class="title class_">Failed</span> to serialize request”, </span><br><span class="line">); </span><br><span class="line"><span class="keyword">if</span> (!body.<span class="property">success</span>) { </span><br><span class="line"> <span class="comment">// handle error (body.error) </span></span><br><span class="line"> <span class="keyword">return</span>; </span><br><span class="line">} </span><br><span class="line"><span class="keyword">const</span> response = <span class="keyword">await</span> <span class="title function_">safe</span>( </span><br><span class="line"> <span class="title function_">fetch</span>(<span class="string">"https://example.com"</span>, { </span><br><span class="line"> <span class="attr">method</span>: “<span class="variable constant_">POST</span>”, </span><br><span class="line"> <span class="attr">body</span>: body.<span class="property">data</span>, </span><br><span class="line"> }), </span><br><span class="line">); </span><br><span class="line"><span class="keyword">if</span> (!response.<span class="property">success</span>) { </span><br><span class="line"> <span class="comment">// handle error (response.error) </span></span><br><span class="line"> <span class="keyword">return</span>; </span><br><span class="line">} </span><br><span class="line"><span class="keyword">if</span> (!response.<span class="property">data</span>.<span class="property">ok</span>) { </span><br><span class="line"> <span class="comment">// handle network error </span></span><br><span class="line"> <span class="keyword">return</span>; </span><br><span class="line">} </span><br><span class="line"><span class="comment">// handle response (body.data)</span></span><br></pre></td></tr></table></figure> + +<p>New solution is longer, but it performs better because of the following reasons:</p> +<ul> +<li>no try/catch</li> +<li>we handle each error where it occurs</li> +<li>we can specify an error message for a specific function</li> +<li>we have a nice top-to-bottom logic, all errors on top, then only the response at the bottom</li> +</ul> +]]></content> + <tags> + <tag>Technique</tag> + </tags> + </entry> + <entry> <title>Turborepo 简述</title> <url>/2024/09/27/Turborepo-%E7%AE%80%E8%BF%B0/</url> <content><![CDATA[<h2 id="Turborepo-简介"><a href="#Turborepo-简介" class="headerlink" title="Turborepo 简介"></a>Turborepo 简介</h2><p>Monorepos 有很多优势,但它们难以扩展。每个工作区都有自己的测试套件、自己的 linting 和构建过程。单个 monorepo 可能有数千个任务要执行。</p> @@ -2310,49 +2353,6 @@ </tags> </entry> <entry> - <title>TypeScript With Rust Errors, No Try Catch, Heresy</title> - <url>/2023/04/30/TypeScript-With-Rust-Errors-No-Try-Catch-Heresy/</url> - <content><![CDATA[<blockquote> -<p>It’s hard to miss things when you don’t know different things exist</p> -</blockquote> -<p>The first problem is, and personally, I believe it’s the biggest JavaScript problem ever: we don’t know what can throw an error. From a JavaScript error perspective, it’s the same as the following:</p> -<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">let</span> data = “<span class="title class_">Hello</span>”;</span><br><span class="line">} <span class="keyword">catch</span> (err) {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">error</span>(err);</span><br><span class="line">}</span><br></pre></td></tr></table></figure> - -<p>JavaScript doesn’t know; JavaScript doesn’t care. You should know.</p> -<p>Second thing, this is perfectly viable code:</p> -<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> request = { <span class="attr">name</span>: “test”, <span class="attr">value</span>: <span class="number">2n</span> };</span><br><span class="line"><span class="keyword">const</span> body = <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(request);</span><br><span class="line"><span class="keyword">const</span> response = <span class="keyword">await</span> <span class="title function_">fetch</span>(<span class="string">"https://example.com"</span>, {</span><br><span class="line"> <span class="attr">method</span>: “<span class="variable constant_">POST</span>”,</span><br><span class="line"> body,</span><br><span class="line">});</span><br><span class="line"><span class="keyword">if</span> (!response.<span class="property">ok</span>) {</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure> - -<p>No errors, no linters, even though this can break your app.</p> -<p>Right now, in my head, I can hear, “What’s the problem, just use try/catch everywhere.” Here comes the third problem: we don’t know which one is thrown. Of course, we can somehow guess by the error message, but what about bigger services/functions with many places where errors can happen? Are you sure you are handling all of them properly with one try/catch?</p> -<hr> -<figure class="highlight rust"><table><tr><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="variable">greeting_file_result</span> = File::<span class="title function_ invoke__">open</span>(“hello.txt”); </span><br><span class="line"><span class="keyword">let</span> <span class="variable">greeting_file</span> = <span class="keyword">match</span> greeting_file_result { </span><br><span class="line"> <span class="title function_ invoke__">Ok</span>(file) => file, </span><br><span class="line"> <span class="title function_ invoke__">Err</span>(error) => <span class="built_in">panic!</span>(<span class="string">"Problem opening the file: {:?}"</span>, error), </span><br><span class="line">};</span><br></pre></td></tr></table></figure> - -<p>The most verbose of the three shown here and, ironically, the best one. So, first of all, Rust handles the errors using its amazing enums (they are not the same as TypeScript enums!). Without going into detail, what is important here is that it uses an enum called <code>Result</code> with two variants: <code>Ok</code> and <code>Err</code>. As you might guess, <code>Ok</code> holds a value and <code>Err</code> holds…surprise, an error :D.</p> -<p>The summary here is that Rust always know where there might be an error. And it force you to deal with it right where it appears (mostly). No hidden ones, no guessing, no breaking app with a surprise face.</p> -<p>And this approach is just better. By A MILE.</p> -<p>We cannot make TypeScript errors work like the Rust. The limiting factor here is the language itself; it doesn’t have the proper tools to do that.</p> -<p>But what we can do is try to make it similar. And make it simple:</p> -<figure class="highlight typescript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">type</span> <span class="title class_">Safe</span><T> = </span><br><span class="line"> | { </span><br><span class="line"> <span class="attr">success</span>: <span class="literal">true</span>; </span><br><span class="line"> <span class="attr">data</span>: T; </span><br><span class="line"> } </span><br><span class="line"> | { </span><br><span class="line"> <span class="attr">success</span>: <span class="literal">false</span>; </span><br><span class="line"> <span class="attr">error</span>: <span class="built_in">string</span>; </span><br><span class="line"> };</span><br></pre></td></tr></table></figure> - -<p>we do need a few try/catches. The good thing is we only need about two, not 100,000:</p> -<figure class="highlight typescript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">export</span> <span class="keyword">function</span> safe<T>(<span class="attr">promise</span>: <span class="title class_">Promise</span><T>, err?: <span class="built_in">string</span>): <span class="title class_">Promise</span><<span class="title class_">Safe</span><T>>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">function</span> safe<T>(<span class="attr">func</span>: <span class="function">() =></span> T, err?: <span class="built_in">string</span>): <span class="title class_">Safe</span><T>;</span><br><span class="line"><span class="keyword">export</span> <span class="keyword">function</span> safe<T>(</span><br><span class="line"> <span class="attr">promiseOrFunc</span>: <span class="title class_">Promise</span><T> | (<span class="function">() =></span> T),</span><br><span class="line"> err?: <span class="built_in">string</span>,</span><br><span class="line">): <span class="title class_">Promise</span><<span class="title class_">Safe</span><T>> | <span class="title class_">Safe</span><T> {</span><br><span class="line"> <span class="keyword">if</span> (promiseOrFunc <span class="keyword">instanceof</span> <span class="title class_">Promise</span>) {</span><br><span class="line"> <span class="keyword">return</span> <span class="title function_">safeAsync</span>(promiseOrFunc, err);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="title function_">safeSync</span>(promiseOrFunc, err);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">async</span> <span class="keyword">function</span> safeAsync<T>(</span><br><span class="line"> <span class="attr">promise</span>: <span class="title class_">Promise</span><T>, </span><br><span class="line"> err?: <span class="built_in">string</span></span><br><span class="line">): <span class="title class_">Promise</span><<span class="title class_">Safe</span><T>> {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">const</span> data = <span class="keyword">await</span> promise;</span><br><span class="line"> <span class="keyword">return</span> { data, <span class="attr">success</span>: <span class="literal">true</span> };</span><br><span class="line"> } <span class="keyword">catch</span> (e) {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">error</span>(e);</span><br><span class="line"> <span class="keyword">if</span> (err !== <span class="literal">undefined</span>) {</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: err };</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (e <span class="keyword">instanceof</span> <span class="title class_">Error</span>) {</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: e.<span class="property">message</span> };</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: <span class="string">"Something went wrong"</span> };</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">function</span> safeSync<T>(</span><br><span class="line"> <span class="attr">func</span>: <span class="function">() =></span> T, </span><br><span class="line"> err?: <span class="built_in">string</span></span><br><span class="line">): <span class="title class_">Safe</span><T> {</span><br><span class="line"> <span class="keyword">try</span> {</span><br><span class="line"> <span class="keyword">const</span> data = <span class="title function_">func</span>();</span><br><span class="line"> <span class="keyword">return</span> { data, <span class="attr">success</span>: <span class="literal">true</span> };</span><br><span class="line"> } <span class="keyword">catch</span> (e) {</span><br><span class="line"> <span class="variable language_">console</span>.<span class="title function_">error</span>(e);</span><br><span class="line"> <span class="keyword">if</span> (err !== <span class="literal">undefined</span>) {</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: err };</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (e <span class="keyword">instanceof</span> <span class="title class_">Error</span>) {</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: e.<span class="property">message</span> };</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> { <span class="attr">success</span>: <span class="literal">false</span>, <span class="attr">error</span>: <span class="string">"Something went wrong"</span> };</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure> - -<p>This is just a wrapper with our <code>Safe</code> type as the return one. But sometimes simple things are all you need. Let’s combine them with the example from above.</p> -<figure class="highlight typescript"><table><tr><td class="code"><pre><span class="line"><span class="keyword">const</span> request = { <span class="attr">name</span>: “test”, <span class="attr">value</span>: <span class="number">2n</span> }; </span><br><span class="line"><span class="keyword">const</span> body = <span class="title function_">safe</span>( </span><br><span class="line"> <span class="function">() =></span> <span class="title class_">JSON</span>.<span class="title function_">stringify</span>(request), </span><br><span class="line"> “<span class="title class_">Failed</span> to serialize request”, </span><br><span class="line">); </span><br><span class="line"><span class="keyword">if</span> (!body.<span class="property">success</span>) { </span><br><span class="line"> <span class="comment">// handle error (body.error) </span></span><br><span class="line"> <span class="keyword">return</span>; </span><br><span class="line">} </span><br><span class="line"><span class="keyword">const</span> response = <span class="keyword">await</span> <span class="title function_">safe</span>( </span><br><span class="line"> <span class="title function_">fetch</span>(<span class="string">"https://example.com"</span>, { </span><br><span class="line"> <span class="attr">method</span>: “<span class="variable constant_">POST</span>”, </span><br><span class="line"> <span class="attr">body</span>: body.<span class="property">data</span>, </span><br><span class="line"> }), </span><br><span class="line">); </span><br><span class="line"><span class="keyword">if</span> (!response.<span class="property">success</span>) { </span><br><span class="line"> <span class="comment">// handle error (response.error) </span></span><br><span class="line"> <span class="keyword">return</span>; </span><br><span class="line">} </span><br><span class="line"><span class="keyword">if</span> (!response.<span class="property">data</span>.<span class="property">ok</span>) { </span><br><span class="line"> <span class="comment">// handle network error </span></span><br><span class="line"> <span class="keyword">return</span>; </span><br><span class="line">} </span><br><span class="line"><span class="comment">// handle response (body.data)</span></span><br></pre></td></tr></table></figure> - -<p>New solution is longer, but it performs better because of the following reasons:</p> -<ul> -<li>no try/catch</li> -<li>we handle each error where it occurs</li> -<li>we can specify an error message for a specific function</li> -<li>we have a nice top-to-bottom logic, all errors on top, then only the response at the bottom</li> -</ul> -]]></content> - <tags> - <tag>Technique</tag> - </tags> - </entry> - <entry> <title>WiscKey: Separating Keys from Values in SSD-conscious Storage</title> <url>/2023/07/21/WiscKey-Separating-Keys-from-Values-in-SSD-conscious-Storage/</url> <content><![CDATA[<p>We present WiscKey, a persistent LSM-tree-based key-value store with a performance-oriented data layoutthat separates keys from values to minimize I/O amplifi-cation. The design of WiscKey is highly SSD optimized, leveraging both the sequential and random performance characteristics of the device.</p> @@ -2542,6 +2542,36 @@ </categories> </entry> <entry> + <title>二〇二三年十二月二日</title> + <url>/2023/12/02/%E4%BA%8C%E3%80%87%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%8D%81%E4%BA%8C%E6%9C%88%E4%BA%8C%E6%97%A5/</url> + <content><![CDATA[<p>夏日凌晨的海风,裹挟着季风带的温热的潮气不远万里奔赴而来,搅碎了一汪流动的星星。</p> +<p>天空泛起一丝鱼肚白,那是每年夏至,凌晨四点多就会早起的日出。</p> +<p>而身后那栋为我而建的世界上独一无二的小屋子,正通宵达旦地亮着灯火,里面是我的痕迹,我的热爱,我的温暖和祝福。</p> +<p>身前,我的山林和小狗,正笨拙地试图从自然的馈赠里找到那份属于它们的礼物。</p> +<p>它们那样爱着我,那样忠诚于我。</p> +<p>那一刻,我突然就想起了曾经在书上看过的一句很喜欢的话——“世界先爱了我,我不能不爱他.”</p> +<p>曾经在冬季日出的时候,我见过海岸线浮满碎冰的模样,那是连太阳都会显得寂寥和落寞的冷清。</p> +<p>可是太阳始终当着太阳,守着一个恒星的职责,不知疲倦地用自己炽热的温度和光芒试图唤醒沉睡的冬日。</p> +<p>直到终于有一天,有人在冬夜里复苏,爱上了那个比夏天更炽烈的温度,然后海浪成了新娘白色的花环,我成了太阳一生的爱人。</p> +<p>所以我始终愿意相信,是这个世界先温柔地爱了我。</p> +<p>哪怕世界给予我的这份爱,在最初的时候,来得并不那么明显,也并不那么浓烈,我也曾因此孤独过,无助过,迷茫过,放弃过。</p> +<p>可是那份爱最终还是随着冰雪消融,春暖花开,随着夏天剧烈摇晃过后的气泡水,滋滋地冒了出来,连盖上盖子,也没有办法捂住。</p> +<p>所以我拥有了世界上最好的义无反顾的爱。</p> +<p>看着前方,轻轻叫了一声:“毛毛”</p> +<p>狗狗立马回了头,和乍出的日光,和突然转动的风力发电机,和突然被风吹动的山林,同步发生。好像只要我一声令下,这个世界就愿意为我而生动。</p> +<p>可这世间哪里会在乎茫茫人海中这不值一提的爱</p> +<p>我们都只不过是平凡世界里平凡生活着的人们,如果非要说有什么不同,那就是我只爱着这个世界而已。</p> +<p>于是我看着那只大笨狗,看着并没有被虚化成背景的世界,温柔地弯起了唇角:“有句话今天我一直忘记告诉你了。”</p> +<p>狗狗叼起一根树枝,歪头不解地看着我。</p> +<p>然后我就在山峰浮现出第一缕阳光时,笑着对这个世界说:“我爱你,会永远爱你,永远最爱你。”</p> +<p>我爱这个因为有我而变得温柔的世界。</p> +<p>这将是我与周遭的一切,热爱一生,共度一生的地方。</p> +]]></content> + <categories> + <category>gallery</category> + </categories> + </entry> + <entry> <title>二〇二三年十二月一日</title> <url>/2023/12/01/%E4%BA%8C%E3%80%87%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%8D%81%E4%BA%8C%E6%9C%88%E4%B8%80%E6%97%A5/</url> <content><![CDATA[<p>他说:“路挺远的,你慢走啊。”</p> @@ -2593,44 +2623,23 @@ </categories> </entry> <entry> - <title>二〇二三年十二月二日</title> - <url>/2023/12/02/%E4%BA%8C%E3%80%87%E4%BA%8C%E4%B8%89%E5%B9%B4%E5%8D%81%E4%BA%8C%E6%9C%88%E4%BA%8C%E6%97%A5/</url> - <content><![CDATA[<p>夏日凌晨的海风,裹挟着季风带的温热的潮气不远万里奔赴而来,搅碎了一汪流动的星星。</p> -<p>天空泛起一丝鱼肚白,那是每年夏至,凌晨四点多就会早起的日出。</p> -<p>而身后那栋为我而建的世界上独一无二的小屋子,正通宵达旦地亮着灯火,里面是我的痕迹,我的热爱,我的温暖和祝福。</p> -<p>身前,我的山林和小狗,正笨拙地试图从自然的馈赠里找到那份属于它们的礼物。</p> -<p>它们那样爱着我,那样忠诚于我。</p> -<p>那一刻,我突然就想起了曾经在书上看过的一句很喜欢的话——“世界先爱了我,我不能不爱他.”</p> -<p>曾经在冬季日出的时候,我见过海岸线浮满碎冰的模样,那是连太阳都会显得寂寥和落寞的冷清。</p> -<p>可是太阳始终当着太阳,守着一个恒星的职责,不知疲倦地用自己炽热的温度和光芒试图唤醒沉睡的冬日。</p> -<p>直到终于有一天,有人在冬夜里复苏,爱上了那个比夏天更炽烈的温度,然后海浪成了新娘白色的花环,我成了太阳一生的爱人。</p> -<p>所以我始终愿意相信,是这个世界先温柔地爱了我。</p> -<p>哪怕世界给予我的这份爱,在最初的时候,来得并不那么明显,也并不那么浓烈,我也曾因此孤独过,无助过,迷茫过,放弃过。</p> -<p>可是那份爱最终还是随着冰雪消融,春暖花开,随着夏天剧烈摇晃过后的气泡水,滋滋地冒了出来,连盖上盖子,也没有办法捂住。</p> -<p>所以我拥有了世界上最好的义无反顾的爱。</p> -<p>看着前方,轻轻叫了一声:“毛毛”</p> -<p>狗狗立马回了头,和乍出的日光,和突然转动的风力发电机,和突然被风吹动的山林,同步发生。好像只要我一声令下,这个世界就愿意为我而生动。</p> -<p>可这世间哪里会在乎茫茫人海中这不值一提的爱</p> -<p>我们都只不过是平凡世界里平凡生活着的人们,如果非要说有什么不同,那就是我只爱着这个世界而已。</p> -<p>于是我看着那只大笨狗,看着并没有被虚化成背景的世界,温柔地弯起了唇角:“有句话今天我一直忘记告诉你了。”</p> -<p>狗狗叼起一根树枝,歪头不解地看着我。</p> -<p>然后我就在山峰浮现出第一缕阳光时,笑着对这个世界说:“我爱你,会永远爱你,永远最爱你。”</p> -<p>我爱这个因为有我而变得温柔的世界。</p> -<p>这将是我与周遭的一切,热爱一生,共度一生的地方。</p> -]]></content> - <categories> - <category>gallery</category> - </categories> - </entry> - <entry> <title>二〇二五年三月十七日</title> <url>/2025/03/17/%E4%BA%8C%E3%80%87%E4%BA%8C%E4%BA%94%E5%B9%B4%E4%B8%89%E6%9C%88%E5%8D%81%E4%B8%83%E6%97%A5/</url> <content><