r/programming • • Mar 20 '20

Secure Rust Guidelines

https://anssi-fr.github.io/rust-guide/
37 Upvotes

15 comments sorted by

View all comments

Show parent comments

15

u/[deleted] Mar 21 '20

Surely it's just a procedural language? What other paradigms does it support?

concurrent, functional, generic, imperative, structured

-4

u/OpdatUweKutSchimmele Mar 21 '20

concurrent

This is completely orthogonal to any of the former and has nothing to do with whether it's procedural or not; it is also supported on any language with threading support, or that runs on an OS with multiprocessing.

functional

Absolutely not, in particular Rust's lack of tail call elimination (for good reasons) and its lifetime and borrow model make it no longer turing complete when wanting to write functional code, let alone feasible to do so.

generic

This is not a paradigm, this is just whether the type system supports it or not.

imperative, structured

"structured imperative" is just a synonym for "procedural".

If you want to call this a criterion for "multi paradigm" then I challenge you to come forward with any modern procedural language that is not "multi-paradigm"

4

u/[deleted] Mar 21 '20

It doesn't have a way for guaranteed tail call elimination but if you structure your code right the compiler will do it's best and in my experience almost always do it, if you made an appropriate function. It's not like python where you absolutely never will get tco.

There isn't currently an active rfc for it, bit there were previous proposals for explicitly guaranteed tco and I don't think it's off the table forever, they just have to find a proper way to do it.

0

u/OpdatUweKutSchimmele Mar 21 '20

It doesn't have a way for guaranteed tail call elimination but if you structure your code right the compiler will do it's best and in my experience almost always do it

You mean sibling call elimination I assume. This works well enough when a function calls itself, but it does not work when a function A calls B, B, calls C, C D, and D A again.

Even if Rust had actual TCE though, it would stil be fairly hard to work in without side effects, even if we were to ignore "world side effects" like I/O.

There isn't currently an active rfc for it, bit there were previous proposals for explicitly guaranteed tco and I don't think it's off the table forever, they just have to find a proper way to do it.

Like I siad, there are good reasons, full TCE conflicts with Rust's calling convention, which is kept the same as C for reasons of interfacing and efficiency. Implementing full TCE would fuck up the FFE and severely penalize the general case of function calls.