Live data from Hacker News

The Dark Arts of Advanced and Unsafe Rust Programming

doc.rust-lang.org

11–20 of 26 posts

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#11

Ada does, and has better and more clear conventions for "unsafe" programming (pointer arithmetic, conversions, etc) but does it naturally without special keywords and esoteric conventions through its package system. Too bad no one will ever give it a chance due to is syntax :( Rust is nothing but a slapdash C style copy of its semantics.

> Rust is nothing but a slapdash C style copy of its semantics.

Rust is a copy of Ada's semantics for dealing with memory unsafe code? Could you provide an example of what you mean?

> Ada does, and has better and more clear conventions for "unsafe" programming (pointer arithmetic, conversions, etc)

Can you give some examples here of what you mean? I found Interfaces.C.Pointers, but I don't know enough about the language to know if that's what you were talking about

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#14
post #12

It's a shame they didn't ever resume work on this. Apparently the guy who wrote it can't work on it any more

It's still getting commits, by the looks of things[1]. As always, I'm sure they welcome contributions.

[1] https://github.com/rust-lang-nursery/nomicon/commits/master

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#15
post #2

I recently had to write a lot of unsafe code in C# to interoperate with a driver. As advanced as modern languages are, the excellent memory models only work within the language. Interoperability requires that you can work with memory directly when needed. (And only when needed.) I don't have a lot of Rust experience, but C# has plenty of tricks to avoid unsafe code but get close enough to working with real memory. On…

There are a couple of projects that do this for Rust, depending on what your inputs and outputs are: * https://github.com/rust-lang-nursery/rust-bindgen - Inputs are C/C++ headers, outputs are Rust type definitions and extern functions to interoperate with the type and functions in the headers * https://github.com/immunant/c2rust - Inputs are C headers and source, outputs Rust code that is semantically equivalent to…

None of these are able to handle dynamic header templating properly, e.g. try embedding Guile Scheme in a non-C/C++ language through FFI alone.

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#18
This is not meant as criticism of this book as it is of my own reading and comprehension abilities (English is not my mother tongue), but when I attempted to read the book, I found the writing style employed very off-putting and distracting. In contrast, I usually find documentation written in a formal technical style like standards and references to be clear and concise; I don't have to exert mental effort trying to decipher inconsequential verbiage, idioms, and cultural references beyond what I need to understand the material at hand.

Is there a resource like The Rustonomicon, but written in a concise and formal style?

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#19
post #11

Ada does, and has better and more clear conventions for "unsafe" programming (pointer arithmetic, conversions, etc) but does it naturally without special keywords and esoteric conventions through its package system. Too bad no one will ever give it a chance due to is syntax :( Rust is nothing but a slapdash C style copy of its semantics.

> Rust is nothing but a slapdash C style copy of its semantics. Rust is a copy of Ada's semantics for dealing with memory unsafe code? Could you provide an example of what you mean? > Ada does, and has better and more clear conventions for "unsafe" programming (pointer arithmetic, conversions, etc) Can you give some examples here of what you mean? I found Interfaces.C.Pointers, but I don't know enough about the langu…

I meant Rust is a copy of Ada in general - it does not deal with unsafe programming in the same way. Instead, you do things like instantiate generic packages/procedure like Ada.Unchecked_Deallocation and Ada.Unchecked_Conversion with the specific conversion or heap deallocation procedure you need. So you are forced to be explicit about every unsafe operation by including such procedures and calling such things - but you are not prone to accidents because you got in the habit of wrapping things in perverse "unsafe" blocks every time you meet a well-thought-out restriction of the language.

Re: The Dark Arts of Advanced and Unsafe Rust Programming

#20

This is not meant as criticism of this book as it is of my own reading and comprehension abilities (English is not my mother tongue), but when I attempted to read the book, I found the writing style employed very off-putting and distracting. In contrast, I usually find documentation written in a formal technical style like standards and references to be clear and concise; I don't have to exert mental effort trying to…

Best bet is probably the API docs? For instance: https://doc.rust-lang.org/std/mem/fn.transmute.html

Not sure how to search to get a collection of the unsafe related functions though.

Post reply on HN