4 ms·
I think lifetimes are the part of Rust that people see as ugly. I recently wrote the following lines of code: struct Parser<'a, 'b, T> { value: &'a [T]
by fransiscoli 6y ago
I think lifetimes are the part of Rust that people see as ugly. I recently wrote the following lines of code:
struct Parser<'a, 'b, T> {
value: &'a [T],
inner: InnerParser<'a, 'b>
}
impl<'a, 'b, T> for Parser<'a, 'b, T> {
fn parse<T: Into<String>>(value: T) -> &'static str {
...
}
}
and the equivalent code in Scala:
class Parser[T] {
var value: List[A] = Nil
var inner: InnerParser = Nil
def parse(value: String): String = ...
}
of course, those programs are not semantically equivalent, but you can clearly see that the Scala version is the more elegant of the two. I can't think of any other way that you could syntactically express lifetimes, but I can see why people would see Rust as ugly.
- drran 6y agoYou just cannot write semantically equivalent code in Scala, because it uses the garbage collector.