<instructions>Your goal is to analyze the following comment and estimate how highly it will be upvoted by the Hacker News community.</instructions><comment><author>dagw</author><text>&lt;i&gt;It&amp;#x27;s not unusual to see C programs written in a &amp;quot;typical&amp;quot; C style become dramatically faster when rewritten in a more modern language.&lt;/i&gt;&lt;p&gt;This was equally true back when C vs Fortran was the big debate, and something not easily captured in benchmarks. C, as written by an expert in high performance C, was equally fast as Fortran written by an expert in high performance Fortran. C, as written by a domain expert with limited programming skills, was often very much slower than Fortran written by a domain expert with limited programming skills.</text><parent_chain><item><author>jiggawatts</author><text>Not to mention that both C++ and Rust can specialise algorithms and containers for specific types, whereas in C most developers resort to void* and function pointers. It&amp;#x27;s not unusual to see C programs written in a &amp;quot;typical&amp;quot; C style become &lt;i&gt;dramatically&lt;/i&gt; faster when rewritten in a more modern language.&lt;p&gt;For example, typical C programs also don&amp;#x27;t use hashtables even when this makes the most sense, causing weird performance cliffs due to O(n^2) algorithms all over the place. Why not hashtables? Because they&amp;#x27;re not generic, so they&amp;#x27;re a pain to use. Not &lt;i&gt;impossible&lt;/i&gt; of course, it&amp;#x27;s just that C developers avoid them.&lt;p&gt;Similarly, &amp;quot;strongly typed&amp;quot; containers full of simple struct types enable compiler auto-vectorisation that&amp;#x27;s often unavailable in C for the same kind of reason.&lt;p&gt;Last but not least, you would have to be a masochist to write heavily multi-threaded code in C... so hardly anybody does. These days, that&amp;#x27;s throwing away over 90% of the computer power in a typical PC, let alone a server.</text></item><item><author>woodruffw</author><text>&amp;gt; Any C alternative will be expected to be on par with C in performance. The problem is that C have practically no checks, so any safety checks put into the competing language will have a runtime cost, which often is unacceptable. This leads to a strategy of only having checks in &amp;quot;safe&amp;quot; mode. Where the &amp;quot;fast&amp;quot; mode is just as &amp;quot;unsafe&amp;quot; as C.&lt;p&gt;I don&amp;#x27;t think this is true, in the general case: Rust has shown that languages can be safe in ways that &lt;i&gt;improve&lt;/i&gt; runtime performance.&lt;p&gt;In particular, languages like Rust allow programmers to express stronger compile-time constraints on runtime behavior, meaning that the compiler can &lt;i&gt;safely&lt;/i&gt; omit bounds and other checks that an ordinary C program would require for safety. Similarly, Rust&amp;#x27;s (lack of) mutable aliasing opens up entire classes of optimizations that are extremely difficult on C programs (to the extent that Rust regularly exposes bugs in LLVM&amp;#x27;s alias analysis, due to a lack of exercise on C&amp;#x2F;C++ inputs).&lt;p&gt;Edit: Other examples include ergonomic static dispatch (Rust makes things like `foo: impl Trait` &lt;i&gt;look&lt;/i&gt; dynamic, but they&amp;#x27;re really static under the hood) and the entire notion of a &amp;quot;zero-cost abstraction&amp;quot; (Rust&amp;#x27;s abstractions are no worse than their &amp;quot;as if&amp;quot; equivalent, meaning that the programmer is restricted in their ability to create suboptimal implementations).</text></item></parent_chain></comment><story><title>The case against a C alternative</title><url>https://c3.handmade.network/blog/p/8486-the_case_against_a_c_alternative</url></story>
<instructions>Your goal is to analyze the following comment and estimate how highly it will be upvoted by the Hacker News community.</instructions><comment><author>woodruffw</author><text>Precisely. This is perhaps the strangest part of the original post: C++ has the same performance advantages as Rust! It has them not because it&amp;#x27;s more safe (although it is, in some regards), but because it allows programmers to express behaviors that the compiler can reason about statically.</text><parent_chain><item><author>jiggawatts</author><text>Not to mention that both C++ and Rust can specialise algorithms and containers for specific types, whereas in C most developers resort to void* and function pointers. It&amp;#x27;s not unusual to see C programs written in a &amp;quot;typical&amp;quot; C style become &lt;i&gt;dramatically&lt;/i&gt; faster when rewritten in a more modern language.&lt;p&gt;For example, typical C programs also don&amp;#x27;t use hashtables even when this makes the most sense, causing weird performance cliffs due to O(n^2) algorithms all over the place. Why not hashtables? Because they&amp;#x27;re not generic, so they&amp;#x27;re a pain to use. Not &lt;i&gt;impossible&lt;/i&gt; of course, it&amp;#x27;s just that C developers avoid them.&lt;p&gt;Similarly, &amp;quot;strongly typed&amp;quot; containers full of simple struct types enable compiler auto-vectorisation that&amp;#x27;s often unavailable in C for the same kind of reason.&lt;p&gt;Last but not least, you would have to be a masochist to write heavily multi-threaded code in C... so hardly anybody does. These days, that&amp;#x27;s throwing away over 90% of the computer power in a typical PC, let alone a server.</text></item><item><author>woodruffw</author><text>&amp;gt; Any C alternative will be expected to be on par with C in performance. The problem is that C have practically no checks, so any safety checks put into the competing language will have a runtime cost, which often is unacceptable. This leads to a strategy of only having checks in &amp;quot;safe&amp;quot; mode. Where the &amp;quot;fast&amp;quot; mode is just as &amp;quot;unsafe&amp;quot; as C.&lt;p&gt;I don&amp;#x27;t think this is true, in the general case: Rust has shown that languages can be safe in ways that &lt;i&gt;improve&lt;/i&gt; runtime performance.&lt;p&gt;In particular, languages like Rust allow programmers to express stronger compile-time constraints on runtime behavior, meaning that the compiler can &lt;i&gt;safely&lt;/i&gt; omit bounds and other checks that an ordinary C program would require for safety. Similarly, Rust&amp;#x27;s (lack of) mutable aliasing opens up entire classes of optimizations that are extremely difficult on C programs (to the extent that Rust regularly exposes bugs in LLVM&amp;#x27;s alias analysis, due to a lack of exercise on C&amp;#x2F;C++ inputs).&lt;p&gt;Edit: Other examples include ergonomic static dispatch (Rust makes things like `foo: impl Trait` &lt;i&gt;look&lt;/i&gt; dynamic, but they&amp;#x27;re really static under the hood) and the entire notion of a &amp;quot;zero-cost abstraction&amp;quot; (Rust&amp;#x27;s abstractions are no worse than their &amp;quot;as if&amp;quot; equivalent, meaning that the programmer is restricted in their ability to create suboptimal implementations).</text></item></parent_chain></comment><story><title>The case against a C alternative</title><url>https://c3.handmade.network/blog/p/8486-the_case_against_a_c_alternative</url></story>