4 ms·
This is a great post! :D Some nits on various errors or misrepresentations: > pragma You have some complaints about attributes (what you call pragmas) -- I s
by Manishearth 11y ago
This is a great post! :D
Some nits on various errors or misrepresentations:
> pragma
You have some complaints about attributes (what you call pragmas) -- I suspect that many of them are due to you looking at them as if they were C++ preprocessor directives or pragmas. They aren't, even if the syntax may be reminiscent :)
In some cases they're like decorators in python (but much more powerful), in others, Java annotations. They're a different concept.
> Sadly, Rust is not a target for my favorite parser generator, and the lexers in Servo don’t look much better than C-style state machines, with lots of matching (switching) on character literals.
https://github.com/servo/html5ever https://github.com/servo/html5ever is the largest parsing library we use in Servo, and there are a bunch of Rust tricks done there. HTML parsing is hard (the spec is insanely complex), and this library does it well with much less code.
> it would be nice if the Rust compiler got rid of the split_at_mut secret password and could reason sanely about slice literals and array indexes.
`split_at_mut` is just a library function that uses `unsafe` internally, much like many other core data structures and methods. It has nothing to do with the compiler.
> It is also worth noting that processing non-overlapping slices in parallel is destined to come into mortal conflict with The Iterator, which is by its nature sequential.
I believe the thread::scoped API can be used to process nonoverlapping slices in parallel with a regular iterator. Not sure, but I recall seeing an example where this was done.
> ...seems like an excessive amount of ceremony, at least for a language that keeps using the word “systems” on its website.
I don't see what verbosity has to do with systems programming. Most of those are zero or low cost (so verbosity doesn't correspond to more steps in the generated assembly); I believe there's a utf8 check at one point and that's it. Rust is verbose wherever errors or footguns are possible.
> Rust won’t read C header files, so you have to manually declare each function you want to call by wrapping it in an extern block, like this:
https://github.com/crabtw/rust-bindgen https://github.com/crabtw/rust-bindgen
> but until a few days ago, Cargo didn’t understand linker flags
You can specify -L and -l flags in the .cargo/config file under the rust-flags key (or output the same in a build script); this has been allowed for a while now. More complex linker args are now possible with the cargo rustc command.
- Jweb_Guru 11y ago> I believe the thread::scoped API can be used to process nonoverlapping slices in parallel with a regular iterator. Not sure, but I recall seeing an example where this was done. Yes, it can. And while the original API had to be reworked a bit, this capability will not change (and someone can probably implemented the proposed solution in a library today, if they so choose, so people can try it in the beta). I really enjoyed reading the article, and I think it presented its argument well, but I fear that some of the conclusions it came to were based on technical misconceptions about the language. It's also making me feel more and more like turning optimizations on by default may be a good idea... for every person who writes a blog post or asks a question on StackOverflow about why code isn't running fast enough, there are probably ten others who just assumed Rust wasn't ready and moved on to other things.
- general_failure 11y ago> https://github.com/servo/html5ever https://github.com/servo/html5ever is the largest parsing library we use in Servo, and there are a bunch of Rust tricks done there. HTML parsing is hard (the spec is insanely complex), and this library does it well with much less code. This might simply be because of a) Servo has no legacy b) Servo developers are awesome c) Servo is not complete yet A large part of the complexity of HTML is simply quirks and compatibility. Which Servo does not handle yet. Don't mistake all this as language wins...
- dragonwriter 11y ago> A large part of the complexity of HTML is simply quirks and compatibility. Actually, the HTML spec already addresses those (that's why it is incredibly complex; unlike HMTL4 and previous, the WHATWG HTML Living Spec -- and possibly the W3C HTML5 spec, though I can never keep straight what that was in the WHATWG spec at the time W3C kept and what it didn't -- contains a complete specification of how compliant user agents should parse anything purporting to be HTML even if it actually isn't valid HTML (IIRC, a compliant parser may throw an error on invalid HTML, but if it is tolerant of errors, the spec specifies how it is to be tolerant, specifically to avoid the pre-HTML5 issue of different browsers parsing the same thing different ways. Modern browser either have converged or are converging -- some might still be lagging -- on that consistent model.)