TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Rust’s worst feature

124 pointsby aw16211074 months ago

14 comments

DannyBee3 months ago
This seems not even close to the worst feature of rust - this seems like it needs some more design work and baking. Like lots of things.<p>The amount of hyperbole in this article makes it a bit hard to take the author all that seriously.<p>Is there evidence more baking won&#x27;t happen? While i have my loves and hates about rust, it definitely always felt like they had a pretty thorough&#x2F;careful process for additions like this. If you go constructively into the threads and offer some concerns, you will usually get some reasonable response.<p>(All processes of course, fail, so this is not always true, but it&#x27;s mostly true)<p>While i think it&#x27;s fine to write rants on blogs, and don&#x27;t feel like everyone has a responsibility to file bugs or whatever before they write a rant about it, if you actually want to see this &quot;worst feature&quot; fixed, this probably won&#x27;t help very much.<p>(IE You don&#x27;t <i>have</i> to be constructive, or even helpful, but if you <i>want</i> to be constructive or helpful, this ain&#x27;t how you do it)
评论 #42879952 未加载
评论 #42878766 未加载
评论 #42884785 未加载
queuebert3 months ago
The more pertinent question to me is can we implement some new static analysis that understands buffer re-use and can hoist buffer initialization outside the loop? Rather than make the programmer write obfuscated code for efficiency, it is usually better to have the compiler do the heavy lifting.<p>P.S. Also, folks, don&#x27;t re-use buffers without zeroing unless you absolutely need the performance and know what you&#x27;re doing.
评论 #42878666 未加载
评论 #42878130 未加载
评论 #42879388 未加载
Zagitta3 months ago
Maybe Rust needs another type of reference that&#x27;s exclusive write only? Right now there&#x27;s RO (&amp;T) and exclusive RW (&amp;mut T) but WO is missing.<p>Having a WO reference would allow these read_buf APIs to express they only write and never read so the uninitialized memory is safe to pass directly.
评论 #42878534 未加载
评论 #42879705 未加载
0x1ceb00da3 months ago
&gt; Even an obvious optimisation of moving the buffer declaration outside of the loop isn’t available to the compiler.<p>Why? Can&#x27;t the programmer just do this himself?
评论 #42877421 未加载
评论 #42878082 未加载
评论 #42877451 未加载
评论 #42877448 未加载
评论 #42877600 未加载
pnathan3 months ago
I think the answer is that in a case when you need that speed, you hoist the stack allocation &amp; zeroing and unsafe that buffer in the loop if need be. Test well. I am a huge Rust fan but also it is actually possible to write correct unsafe code.<p>If I am interacting with from IO space, I would much rather write the interaction code myself for the machine at hand than farm it out to an array of third party crates. ::shrug::<p>getting the machinery to let it properly be hoisted smoothly and safely would be nice, but it isn&#x27;t required.<p>personally I think rust macros are very painful and the &quot;worst feature&quot;, but that&#x27;s speaking as someone who did a fair bit of Common Lisp.
评论 #42883811 未加载
umanwizard3 months ago
&gt; While replacing the array of zeros by an array of uninitialised values may work in specific circumstances, the code is unsound. Change to the compiler, its options, modification of unrelated parts of the code or using the function for a different Read trait implementation may break the program in unpredictable ways.<p>Why? It seems the only thing on that list that will cause UB is using the function with a different reader (one that inspects the uninitialized bytes). Why would any of the other listed possible changes break it?
评论 #42888676 未加载
评论 #42883215 未加载
mmastrac3 months ago
This API has basically been adopted from Tokio. Like most of Rust buffer types, it&#x27;s &quot;not bad&quot; to use as a caller and &quot;awkward&quot; to use as a consumer.<p>The pain of paying for buffer init is real, however. The last two projects have both seen perf hits from it.
Matthias2473 months ago
If this is mainly useful for working with plain&#x2F;uninterpreted byte arrays, then I wonder why we can&#x27;t just do `[u8; N]::with_noinit()` method instead of doing the multi-line plus unsafe things listed in the article.<p>Is the main point that things like `slice_freeze_mut` could also be used for slices of e.g. `struct Coordinate { x: u32, y: u32, z: u32 }`?<p>It would obviously not work for f64 things, since there also not all bit-patterns are valid.
评论 #42879499 未加载
lmm3 months ago
Why is it that the frozen semantics are actually needed? Is there no way to represent what people actually want here - memory that is entirely uninitialised, for which tautology might be false, until written? I.e. something that&#x27;s a bit like MaybeUninit but more so?
评论 #42877533 未加载
leni5363 months ago
Do some Rust types have invalid object representation or trap representation? On SysV x86_64 bool only has two valid representations in memory, the rest are trap representations.<p>So for an array of bools (if Rust matches SysV) freeze wouldn&#x27;t be sound, even without the madvise problem.
评论 #42877678 未加载
评论 #42879926 未加载
jasonthorsness3 months ago
I am not yet a Rust programmer but - is it not typical to have a small collection of unsafe functions, carefully reviewed, that in this case seem like they might be easier to maintain than some of these convoluted type-based workarounds?
评论 #42880138 未加载
steeeeeve3 months ago
The selling point of Rust was that it protects programmers from doing dangerous things.
评论 #42880417 未加载
breaker-kind3 months ago
what does the term &quot;nightly&quot; mean in this context?
评论 #42878554 未加载
评论 #42878553 未加载
tmtvl3 months ago
I&#x27;m not a Rust person (give me Lisp any day), but this stuck out to me:<p>&gt; <i>A motivated programmer can try adding necessary support to actively maintained packages [...] but what if one is stuck at an older version of the crate or deals with apparently abandoned crates</i><p>One could maybe do some programming? I mean, hell, if most of the work has already been done for you, then what&#x27;s holding you back? Besides, why would you want to use outdated, bug-ridden libraries filled with vulnerabilities instead of something well-maintained?
评论 #42877543 未加载
评论 #42877573 未加载
评论 #42878363 未加载