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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Rewriting m4vgalib in Rust

372 点作者 zimmerfrei超过 5 年前

7 条评论

bluejekyll超过 5 年前
If the author is reading this, this might be the greatest single article I’ve read that expresses the benefits of Rust and how minimal the trade-offs are. Wonderfully written piece, thank you!<p>BTW, in your bounds checking examples, I think it can be further simplified (would need to check the output to see if it&#x27;s any better), this:<p><pre><code> fn fill_1024(array: &amp;mut [u8], color: u8) { &#x2F;&#x2F; Perform an explicit, checked, slice of the array before &#x2F;&#x2F; entering the loop. let array = &amp;mut array[..1024]; for i in 0..1024 { array[i] = color; } } </code></pre> Could be:<p><pre><code> fn fill_1024(array: &amp;mut [u8], color: u8) { for i in &amp;mut array[..1024] { *i = color; } } </code></pre> Here&#x27;s the playground: <a href="https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=832233ec0b3319fcec86c2330be93523" rel="nofollow">https:&#x2F;&#x2F;play.rust-lang.org&#x2F;?version=stable&amp;mode=debug&amp;editio...</a><p>Thanks again, this is a wonderful piece.
评论 #21929765 未加载
PudgePacket超过 5 年前
Author also wrote &quot;Learn Rust the dangerous way&quot;.<p>&gt; In this series, I&#x27;m trying something different. Let&#x27;s take a grungy, optimized, pointer-type-punning, SSE-using, heap-eschewing, warning-disabling C program and look at how we could create the same program in Rust.<p><a href="http:&#x2F;&#x2F;cliffle.com&#x2F;p&#x2F;dangerust&#x2F;0&#x2F;" rel="nofollow">http:&#x2F;&#x2F;cliffle.com&#x2F;p&#x2F;dangerust&#x2F;0&#x2F;</a>
评论 #21928581 未加载
dry_soup超过 5 年前
This was more interesting than the average &quot;rewrite in Rust&quot; blog post. Specifically I thought the part about how having compiler-enforced memory safety allows for the use of patterns that would otherwise be difficult to use safely interesting.
评论 #21928413 未加载
评论 #21930540 未加载
brohee超过 5 年前
<a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=HkUUJ-rOUPg" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=HkUUJ-rOUPg</a> has an output of the demo, and this is indeed very impressive for hardware that isn&#x27;t supposed to output video at all...
评论 #21927826 未加载
评论 #21933879 未加载
评论 #21929169 未加载
pdimitar超过 5 年前
I lack the knowledge of that particular piece of software but may I see that this has been extremely interesting to read!<p>Also, I quite love the trend of &quot;we rewrote our software in Rust&quot; lately. I loved the speed of C&#x2F;C++ about 15 years ago but the mounting complexity and the increasingly huge game of whack-a-mole pushed me away from them.<p>Now I am gradually and casually learning Rust and I absolutely love what I am seeing and experiencing.
ncmncm超过 5 年前
This is a persuasive article, but it is still not clear whether Rust will achieve a self-sustaining mass of developers. That is, precisely: enough that each new person who masters Rust will be able to find work writing Rust. (To be clear, it would be good if this were to happen.)<p>The deepest observation in the article is the remark about the cognitive load imposed by need to avoid pitfalls inherent in the programming model.<p>I coded K&amp;R C in the 80s, and while I never shipped an argument-type bug, avoiding them was a continual distraction. I coded C90 from 2006 to 2012, with a similar cognitive load I was happy to leave behind, although again I never shipped a bug caused by its failings. (We had bugs, but they were specification bugs: building the wrong thing.)<p>Writing C++ post-14 has been an increasing pleasure. The cognitive load noted is present at times, but decreasingly so as the Standard Library and other libraries get more powerful.<p>I am disappointed that the author found it too hard to implement a correct program with C++, but more disappointed that he chose to blame his tools for his failure.<p>It has become fashionable to insist that correct programs cannot be written in this or that unfashionable language, but in fact a great many correct programs have been written in all of them, not excepting octal machine code.<p>What varies is how much work is needed, and how many people can do it: it is certain that, for any chosen language past or future, most people cannot or will not write a correct program in it. Rust is not different in this.<p>Many people coding C++, and perhaps most coding C, are not writing correct code, and have over the years written a very great deal of bad code. Will those same people succeed in learning Rust, and learning to write good code in it? It appears that the people currently adopting Rust are more skilled than is typical, so it seems hard to generalize their results to more typical programmers.<p>C++ and Rust embody different choices in emphasis: Rust, safety; C++, library power. Stewards of C++ have decided the best way to get substantial correct programs is to enable encapsulating semantics in well-tested, well-optimized libraries that can be used without compromising performance or system architecture. Rust has chosen to emphasize making wrong low-level code hard to express, although its ability to express libraries will only increase.<p>It will not be clear for a long time which will have better results. Will enough people learn Rust to write the correct low-level code needed? Will enough C++ programmers learn to use libraries that make (re-)writing dangerous low-level code unnecessary?<p>What is clear is that the number of C++ programmers is growing faster than ever, and interest in coding to high level C++ libraries, as measured by attendance at an ever increasing number of conferences, is exploding. Even attendance at each ISO Standard meeting is quite a lot larger than at each previous one, now reliably in hundreds. The number of new C++ programmers in any unit time is still larger than the number of new Rust programmers, by a large factor.<p>So, the experiment is interesting and valuable. What we can be confident about, either way, is that, for every C coder, or C++ coder writing low-level, often bad code, switching to Rust or to C++ using reliable libraries will result in more good code. It matters much less which they choose.
blargmaster33超过 5 年前
Why did rust not go with standard c syntax
评论 #21930170 未加载
评论 #21929893 未加载
评论 #21931988 未加载
评论 #21930515 未加载
评论 #21931304 未加载