4 ms·
Is char* c_foo(char* bar) { ... } simpler than fn rust_foo<'a>(bar: &'a str) -> &'a str { ... } ? On the one hand, c_foo is shorter and doesn't use
by Arnavion 5y ago
Is
char* c_foo(char* bar) { ... }
simpler than
fn rust_foo<'a>(bar: &'a str) -> &'a str { ... }
?
On the one hand, c_foo is shorter and doesn't use strange symbols. On the other hand, rust_foo doesn't leave you guessing on whether the returned value needs to be free()d or not, and whether the heap allocation backing `bar` can be free()d after the call or not.
- steveklabnik 5y ago(You have a tiny typo; you forgot the <'a>. Also, I know you know this, but for those that don't, this signature could be written as fn rust_foo(a: &str) -> &str { ... } but Arnavion is trying to be explicit here to make a steelman.)
- Arnavion 5y agoYeah, I fixed that typo. And yes, foo is arbitrary, so one can assume it has another * / & parameter such that the lifetimes can't be elided any more.
- user-the-name 5y agoYou are talking about the simplicity of a line of code. The topic being discussed, though, was the simplicity of the language itself.
- Arnavion 5y agoThe simplicity of the language is directly correlated to the simplicity of that line. The fact that the language makes relationships between inputs and outputs explicit is a feature of the language, because of its borrow checker, at the expense of being syntactically verbose compared to C.
- user-the-name 5y agoNot at all. A single line will use a tiny subset of language features. It will show you nothing about the overall complexity of the language, just about those things it happens to use.
- strokirk 5y agoThe first example is definitely simpler, yes.