Re:Maintain It with Zig
by steveklabnik on Wednesday September 08, 2021 @03:49PM
(#28462124)
(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.)Yeah, 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.
The first example is definitely simpler, yes.
Re:Maintain It with Zig
by user-the-name on Wednesday September 08, 2021 @03:50PM
(#28462149)
You are talking about the simplicity of a line of code. The topic being discussed, though, was the simplicity of the language itself.
The 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.
Re:Maintain It with Zig
by user-the-name on Wednesday September 08, 2021 @05:35PM
(#28463355)
Not 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.
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.