Rust's Ugly Syntax (2023)
matklad.github.io
Rust's Ugly Syntax (2023)
1–10 of 171 posts
Re: Rust's Ugly Syntax (2023)
#2Re: Rust's Ugly Syntax (2023)
#3Re: Rust's Ugly Syntax (2023)
#4I think the article makes a good point, but the actual example isn’t Rust’s worst, not even close. It gets really hard to follow code when multiple generic types are combined with lifetime markers. Then it truly becomes a mess.
Re: Rust's Ugly Syntax (2023)
#5Is it really better to remove the error case information from the type signature? Aren't we losing vital information here?
type Result = std::result::Result;
So it's actually fine, since we're specifying it's an IO result. This is a fairly common pattern.Re: Rust's Ugly Syntax (2023)
#6Re: Rust's Ugly Syntax (2023)
#7Re: Rust's Ugly Syntax (2023)
#8The final version is still ugly. Why `pub fn'? Why is public not the default and why do you have to specify that it's a function? Why `: type' and `-> type', why can't type go before the identifier? Why do you need `File::' and `Bytes::'? What is that question mark? Why does the last statement not need a semicolon? It's like the opposite of everything people are used to.
E.g. making pub default is precisely the decision a language would make that values concise code over what the code actually does.
Re: Rust's Ugly Syntax (2023)
#9When type signatures are so complex it makes vastly more sense to separate them out,
Consider,
read :: AsRef(Path) -> IO.Result(Vec(U8))
pub fn read(path):
inner :: &Path -> IO.Result(Vec(U8))
fn inner(path):
bytes := Vec.new()
return? file := File.open(path)
return? file.read_to_end(&! bytes)
return OK(bytes)
inner(path.as_ref())Re: Rust's Ugly Syntax (2023)
#10 pub fn read(path: Path) -> Bytes {
File::open(path).read_to_end()
}