4 ms·
What is better about Rust vs Python's syntax? struct Foo<T> { t: T } vs (assuming we get the pep for inline typevars) class Foo[T]:
by insanitybit 3y ago
What is better about Rust vs Python's syntax?
struct Foo<T> {
t: T
}
vs (assuming we get the pep for inline typevars)
class Foo[T]:
t: T
I don't see how Python is meaningfully better at all.
Or
use foo::bar::baz;
vs
import foo.bar.baz
I just don't get the problem here. "double colons bad" is just an extremely subjective take that I don't really buy at all. I much, much prefer snake case and would hate to see pascalcase in Rust, but also at the end of the day these are such minor things that barely barely impact readability.
- JodieBenitez 3y agostruct Foo<T> { t: T } Braces... one extra sign (and line) for nothing while indentation works fine. import foo::bar::baz; import foo.bar.baz 4 times the dots, also useless comma. Objectively less visual noise in Python. Of course the importance of it is subjective, I agree with that. But still, less cruft is good. > minor things that barely barely impact readability Of course, I don't agree :-)
- Ygg2 3y agoThese are subjective things. I don't consider Rust syntax perfect, but I don't these suggestions as way to improve it substationally. If you want to get rid of `::` and `;` and braces you have to look at the fallout of those decisions. Braces are imo much better at being robust than whitespace. def Foo[T]: t: T size: u32 // invisible error here because someone used tabs by mistake `;` disambiguate expression vs statement. If you remove it you need way to differentiate between them. Another problem with `import foo.bar.baz` is how will you distinguish between a method call or a type declaration? E.g. `std.option.Option.Some` what is this? Type? Method? Module? What is `std::f64::consts`??? Not to mention you kinda have to have compiler in mind, if syntax is ambigous you're going to have a very bad time.
- weinzierl 3y agoI agree with that and would not want to see braces and semicolons go because they are pretty conventional. In this case Python and Javascript/Typescript are the outliers. It's the opposite for the double colon syntax which, apart from Rust, to the best of my knowledge only exists in C++ (for good reasons) and some functional languages for a completely different purpose. Honestly curious question: What fallout would you see from replacing it with a dot in Rust. I immediately see no disambiguation issues, but I'm not a compiler writer.
- JodieBenitez 3y ago> // invisible error here because someone used tabs by mistake would not parse, so no invisible mistake.
- Ygg2 3y agoImplying every site you post code to will have correct syntax highlighter.
- insanitybit 3y agoRust's philosophy is "explicit over implicit" - braces fall inline with that. One extra line for a struct is really not a lot. That whitespace sensitivity also leads to having to escape newlines, with `\` trailing lines all over the place in Python. I find that far uglier than "4 times the dots" for import statements. > Of course, I don't agree :-) For sure, I think that's kind of my point. Like, this all feels very unimportant to me and extremely subjective. I think that rust's syntax fits into its philosophy, however. I would not mind unifying path syntax such that `:` became `.` however.
- JodieBenitez 3y agooh the irony... "Explicit is better than implicit." ;-)
- steveklabnik 3y agoIt's a fantastic example of how witty sayings don't necessarily lead to agreement, even among people who would agree in the truth of the saying.
- JodieBenitez 3y agoIndeed... "philosophy" is often a poor justification for technical choices.
- insanitybit 3y agoI don't actually see the irony?
- eviks 3y ago> "double colons bad" is just an extremely subjective take that I don't really buy at all. It is objectively worse to type shift+; two times than a single non-shifted period. That's a very simple selling point, what's there not to get?
- weinzierl 3y agoWhat I find worse than the typing issue (which I agree with) is that it is an uncommon choice for something a very common choice exists. Even worse is that its use is so similar to the situations where the dot is used that it's just confusing. The Internet is full of questions when to use which. This is in my eyes unnecessary complexity and does not mesh well with the aspiration of Rust wanting to be beginner friendly.
- insanitybit 3y agoFWIW I am "pro-dot". I just don't think it matters much at all.