<story><title>From Rust to TypeScript</title><url>https://valand.dev/blog/post/from-rust-to-typescript</url></story><parent_chain></parent_chain><comment><author>aerovistae</author><text>The first code example he uses immediately threw me for a loop. Why is he adding the return value of a function call to a function itself? bar() + bar????&lt;p&gt;function bar(someNumber: number)&lt;p&gt;{&lt;p&gt;&lt;pre&gt;&lt;code&gt;  return foo(someNumber) + 1;  &lt;/code&gt;&lt;/pre&gt;
}&lt;p&gt;function baz(someNumber: number)
   {&lt;p&gt;&lt;pre&gt;&lt;code&gt;  return bar(someNumber) + bar; 
&lt;/code&gt;&lt;/pre&gt;
}&lt;p&gt;baz();&lt;p&gt;Moreover, baz is called with its only argument being undefined-- so the exception throwing code won&amp;#x27;t even throw, because it isn&amp;#x27;t 0. And _moreover_, this is typescript, so this would have thrown a type error since a required numeric argument is omitted.&lt;p&gt;This has so many problems. This is not a promising start to this article&amp;#x27;s correctness or thought-outtedness. Yet here it is at the top of hacker news...</text></comment>
<story><title>From Rust to TypeScript</title><url>https://valand.dev/blog/post/from-rust-to-typescript</url></story><parent_chain></parent_chain><comment><author>flowerlad</author><text>This article is unconvincing.&lt;p&gt;From the article: &lt;i&gt;Compared to the first snippet, this one is harder to debug. It seems so because 1.) You don&amp;#x27;t know that callMe will throw an error or not. 2.) If it throws an exception you will not know what is the type of the exception. The more modular your code is, the harder it is to debug exceptions.&lt;/i&gt;&lt;p&gt;This is only a problem with unchecked exceptions as seen in TypeScript and C#. Checked exceptions are the solution.&lt;p&gt;The problem with error code return is tediousness:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  int foo() {
     int result = bar();
     if (result == ERROR_CODE)
        return result;
     int result2 = baz();
     if (result2 == ERROR_CODE)
        return result2;
     int result3 = bazz();
     if (result3 == ERROR_CODE)
        return result3;
  }
&lt;/code&gt;&lt;/pre&gt;
Compare to the same code written in a language that supports checked exceptions:&lt;p&gt;&lt;pre&gt;&lt;code&gt;  int foo() throws SomeException {
     int result = bar();
     int result2 = baz();
     int result3 = bazz();
  }
&lt;/code&gt;&lt;/pre&gt;
In the first version the logic is interspersed with error handling, which makes the logic hard to see.&lt;p&gt;How do people using Go and other languages that don&amp;#x27;t have exceptions solve this reduced readability problem?</text></comment>