3 ms·
Compare to Julia # Your big function has specific types function my_function(x::UInt, y::UInt) [ ... ] end # Wrapper function to minim
by jakobnissen 5y ago
Compare to Julia
# Your big function has specific types
function my_function(x::UInt, y::UInt)
[ ... ]
end
# Wrapper function to minimize monomorph. cost
my_function(x::Integer, y::Integer) = my_function(UInt(x), UInt(y))
- Zababa 5y agoYour comparaison isn't only about syntax, it's also about the presence or absence of static types.
- jakobnissen 5y agoThose two are related, clearly. It's not that Rust has added words that literally do nothing. Instead, the designers of Rust packed all kinds of things into the syntax that other languages decided would cause too much noise. * The output type must be explicitly named instead of inferred * The let keyword for creation of variables instead of merely assignment * The mut keyword to distinguish between mutable/immutable variables * The pub keyword, instead of another mechanism * Semicolons needed after every expression And more. Again, for every one of them, you can argue that it's _good_ for it to be there, because it serves a function. But you end up with a language with a hugely bloated syntax where the business logic is sort of swamped in these accessory keywords.
- Zababa 5y agoI don't agree that the syntax is "hugely bloated". The return type is part of the business logic. mut and pub are here to make some things explicit, so again I don't mind them. Rust is one of those languages that wants to make more things explicit because the people using it need those things to be explicit.
- tialaramex 5y ago> The output type must be explicitly named instead of inferred That isn't syntax. It's a decision about analysis. > The pub keyword, instead of another mechanism The "other mechanisms" discussed are in fact not providing this feature, but pretending you needn't care, and I'd argue Rust shows that in fact you should care and pretending otherwise is a problem. > Semicolons needed after every expression On the contrary, semicolons are at the end of Rust's statements. If what you've got is an expression you don't need a semicolon. For example here's how log is defined on an f64 (a double precision floating point number) pub fn log(self, base: f64) -> f64 { self.ln() / base.ln() } Notice there's no semicolon there because that function is an expression, we want the value of this division as the result of the function.
- nextaccountic 5y agoRust need a lot of extra stuff in function signatures to do its magic. Julia couldn't possibly do what Rust does because it doesn't have enough information
- jakobnissen 5y agoNo. They didn't have to have a pub keyword, which takes space. They didn't have to have the ugly syntax to make functions generic: Julia's functions are generic without using those brackets. Rust didn't have to have explicitly needed return types, or having to have those fully specified.
- Zababa 5y agoSo how do you make the difference between public and private code without a pub keyword? And for the "explicit return types", I think it makes the code more readable. You seem to think that what is your personal preference (something that looks like Julia) is best practice. It's not, it's just a preference.
- jakobnissen 5y agoBoth Julia and Python has a concept of public and private code, neither have a pub keyword. I don't believe Julia or Python is "best practice" over Rust. I even empathize with the opinion that explicitness may be preferential sometimes. But you _must_ be able to see how Rust's syntax overload obfuscates the core business logic, right?
- Zababa 5y agoThe difference between pub in Rust and _/__ in Python isn't that big. It's like Go that uses a capital letter to say what code is public. There's also a difference in philosophy between public by default and private by default. All in all, it's a small detail and doesn't affect things. Sure, business logic is more readable in something like OCaml than in Rust. On the other hand, Rust isn't really worse than something like Java, and I like having more information than what you have in Python. I'll also add that Rust is often chosen for speed and reliability, and that part of that syntax is here to guarantee that. It's not directly business logic in the traditional sense, but it's something you expect from your code. All in all, Rust is still not at the level of the "platonic ideal for syntaxes", especially not for most of the code I write (business logic for web apps, which wouldn't need Rust's speed). Still, in the realms of programming languages that are used, it's one of the best.