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.

Porting C to Rust

161 pointsby ScottWRobinsonover 6 years ago

8 comments

jstimpfleover 6 years ago
&gt; Achieving abstraction is super hard when you can just reach down into some bytes and noodle around with them instead.<p>Disagree. In my experience all was wonderful once I was past the point where I decided to just not worry. Much the opposite, so much pointless and confusing OOP boilerplate (as well as blood, sweat, and all that) goes into &quot;securing&quot; code against misuse.<p>Invest some time into data structures with obvious meaning, or a procedural API that is easily understood. &quot;Nobody&quot; will &quot;ever&quot; misuse, and misuse will be easy to detect. Much better tradeoff IMO.<p>And lastly, of course, abstraction has nothing to do with &quot;security systems&quot;. It&#x27;s against popular opinion, but you can in fact have good abstraction with nothing but plain functions and void pointers. I like to view abstraction as mostly a conceptual thing that doesn&#x27;t even happen in code.
评论 #18177136 未加载
mschwaigover 6 years ago
&gt; A lot of these complaints are just, well, it’s called Progress. If we designed the C in 2018 and made it so we actually wanted to use it, then it would look very different. Probably a lot like Nim or Swift. I think that’s still a niche that is currently unfilled; a modern, powerful language that doesn’t try to provide the same guarantees as Rust and so can be much more minimalist.<p>I think zig is quite a good candidate to fill that niche. It is very compatible with C, but it offers meaningful improvements while still being very picky about what goes into the language.
评论 #18177609 未加载
sinistersnareover 6 years ago
Here is the discussion on the Rust Subreddit, with author comments [1].<p>[1]: <a href="https:&#x2F;&#x2F;old.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;9mioiv&#x2F;porting_c_to_rust_a_case_study_minimp3&#x2F;" rel="nofollow">https:&#x2F;&#x2F;old.reddit.com&#x2F;r&#x2F;rust&#x2F;comments&#x2F;9mioiv&#x2F;porting_c_to_r...</a>
monocasaover 6 years ago
&gt; What is it about C that makes people think L3_imdct_gr() is a perfectly good function name?<p>Early ANSI, like Fortran77, only required 6 characters of a symbol to be significant, with compilers not going much farther beyond that. At that point, it sort of becomes a &quot;when in Rome&quot; thing.
评论 #18176546 未加载
评论 #18178459 未加载
评论 #18176854 未加载
评论 #18176980 未加载
eridiusover 6 years ago
On the &quot;possible bugs in minimp3&quot; section, the links are all to the current master, which appears to have changed since this was written (e.g. <a href="https:&#x2F;&#x2F;github.com&#x2F;lieff&#x2F;minimp3&#x2F;blob&#x2F;master&#x2F;minimp3.h#L232" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lieff&#x2F;minimp3&#x2F;blob&#x2F;master&#x2F;minimp3.h#L232</a> doesn&#x27;t point at the function with the bitshift anymore; I expect it should be <a href="https:&#x2F;&#x2F;github.com&#x2F;lieff&#x2F;minimp3&#x2F;blob&#x2F;644e0fb7fed34f803b6634f72e5ad8cc20a520f7&#x2F;minimp3.h#L232" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;lieff&#x2F;minimp3&#x2F;blob&#x2F;644e0fb7fed34f803b6634...</a>).<p>Protip: When viewing something like this in GitHub, press &quot;y&quot; and the URL bar will change to be a proper permalink to the current version of the code. This permalink can then be shared. Alternatively, with the line highlighted, press the … button in the gutter and it will offer a &quot;Copy Permalink&quot; option (which gives you the same permalink you get by pressing &quot;y&quot;).
capdeckover 6 years ago
&gt; <i>In the end, the results of my work are in the rinimp3 crate, because I suck at naming things.</i><p>Why not minimp3-rs -- thus people familiar with the original C library will be sure where it is coming form...
评论 #18180485 未加载
评论 #18178980 未加载
eximiusover 6 years ago
I admit, I was curious about the `some_struct foo[1];` thing.<p>This is all I could find. It isn&#x27;t terribly compelling.[1]<p>[1] <a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;6390331&#x2F;why-use-array-size-1-instead-of-pointer" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;6390331&#x2F;why-use-array-si...</a>
评论 #18180690 未加载
JoshuaAshtonover 6 years ago
&quot;The lack of real bool&quot; -Which is fine as the minimum space it would take to store a bool is 1 byte anyway (unless youre using bitflags), and you probably want to give more detailed information than true&#x2F;false anyway<p>&quot;but a shitty way to engineer software as a whole. Achieving abstraction is super hard when you can just reach down into some bytes and noodle around with them instead.&quot;: Data oriented design is usually better both in ease of use and performance than any random class abstractions that exist; also, see Linux.<p>&quot;Bloody hell you can’t tell whether a pointer points to a single object or an array just by looking at it&quot;: You can, usually. There are plural words in languages usually used do denote this, item<i>s</i>, also the size thing he mentioned. If it doesn&#x27;t have it then its usually just bad practice or poor code quality.<p>&quot;heckin’ ternary operators, just make your if statements not suck.&quot;: Ternary operators are great, and usually quite concise. Not sure what they are specifically referring to here :&#x2F;<p>&quot;The pre and post increment operators are just the worst damn thing in the world.&quot;: Again, this knowledge comes to experience, and actually makes things more concise.<p>C is not designed to be a &quot;&quot;beginner&quot;&quot; friendly language, but its essence is simple -- and I would recommend it for any beginner as it really drives home the majority of actual programming principles, and makes you think about what you are doing on a deeper level rather than coating things in a magical dust layer of classes with vtables and garbage collection.<p>&quot;it’s called Progress.&quot;: However, with modern programming languages it&#x27;s one step forward with two steps back most of the time.<p>I agree with stuff about automatic conversions between types, however some compilers will warn you (unless you told it to shut up) about any narrowing conversions that you do, and that&#x27;s the main trap that people fall into.<p>The majority of debugging&#x2F;compiling tools are designed primarily with C in mind and are fairly simple to use also.<p>The majority of the rant about C was mainly not based off issues with C itself, but with the code quality of minimp3, which is quite depressing as C itself does have some bad traits imo such as function ptr definitions are bulky, : for bitfields, no predictability for most &#x27;undefined behaviours&#x27;, dodgy bitshifting too and probably more things I can&#x27;t think of at the top of my head.