News for hackers. Stuff that matters.
Re:Fast Rust Builds by jakobnissen on Sunday September 05, 2021 @02:22PM (#28426463)
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))
Re:Fast Rust Builds by nextaccountic on Sunday September 05, 2021 @03:26PM (#28427010)
Rust 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
Re:Fast Rust Builds by jakobnissen on Sunday September 05, 2021 @03:34PM (#28427080)
No. 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.
Re:Fast Rust Builds by Zababa on Sunday September 05, 2021 @03:52PM (#28427213)
So 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.
Re:Fast Rust Builds by jakobnissen on Sunday September 05, 2021 @04:10PM (#28427357)
Both 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?

Re:Fast Rust Builds by Zababa on Sunday September 05, 2021 @04:24PM (#28427444)
The 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.

Re:Fast Rust Builds by masklinn on Monday September 06, 2021 @11:30AM (#28434668)
> The difference between pub in Rust and _/__ in Python isn't that big.

FWIW `__` doesn't mean "this is part of the implementation", it means "I'm designing a class for inheritance and I don't want child classes to stop on my attributes".

Re:Fast Rust Builds by masklinn on Monday September 06, 2021 @11:32AM (#28434680)
> Both Julia and Python has a concept of public and private code, neither have a pub keyword.

No. Python certainly does not have a concept of private code[0]. The Python community has a suggestion of things being implementation details.

Surely you can see that absolutely would not be good enough for a language which strives for static correctness? And even more so as the soundness of `unsafe` blocks often relies on the invariants of the type it's used in?

[0] well that's not entirely true, I guess there's native code.

Re:Fast Rust Builds by dthul on Sunday September 05, 2021 @04:00PM (#28427264)
Fully specified function signatures are a conscious decision because it allows you to type check and borrow check a piece of code without needing to analyze the bodies of other functions. I also love it as a human because there is no guesswork involved.
Re:Fast Rust Builds by Ar-Curunir on Sunday September 05, 2021 @03:53PM (#28427219)
Those are all trade-offs. Ditching fully-specified function signatures makes type inference more difficult and results in poorer type inference errors
Re:Fast Rust Builds by nextaccountic on Sunday September 05, 2021 @04:23PM (#28427437)
Rust generics can be written in a more compact way,

    fn f(x: impl Test) { ... }
Is basically the same as

    fn f<T: Test>(x: T) { ... }
Having to annotate the return value of functions is partly to make sure don't break semver accidentally, but it also constrains type inference to a local search rather than global search, avoiding spooky action at distance (when modifying a function changes the signature of another function). It seems that semver hazards are more important in languages with static types.

That pub? It's punching waaay above its weight! Having things private by default protects against semver hazards too, but it's also the major tool that enable writing safe code that uses unsafe { .. } blocks underneath. That's because a single unsafe block typically taints the whole module it's contained (such that even safe code needs a safety review). Being able to write safe abstractions of unsafe code is the pull of Rust so people need to get it right.

For example, setting the field len of a Vec to a value larger than what's initialized in its buffer will cause UB when accessing that memory; if this field weren't private, making a safe Vec would be impossible (likewise, a function that could set the len to any value must be private, etc).

So pub can only be used for things that are safe to export, and people should be careful with that.

Here's my least favorite syntax from there: that damn Ok(..). Ok-wrapping sucks. There were proposals to remove it, but they were rejected. There's a library that removes it [0], and people should use it. It also makes the Result<..> return type implicit in the function signature too.

[0] https://boats.gitlab.io/blog/post/failure-to-fehler/#but-abo...

Re:Fast Rust Builds by Zababa on Sunday September 05, 2021 @02:35PM (#28426565)
Your comparaison isn't only about syntax, it's also about the presence or absence of static types.
Re:Fast Rust Builds by jakobnissen on Sunday September 05, 2021 @03:27PM (#28427029)
Those 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.
Re:Fast Rust Builds by tialaramex on Sunday September 05, 2021 @06:43PM (#28428472)
> 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.
Re:Fast Rust Builds by Zababa on Sunday September 05, 2021 @03:46PM (#28427162)
I 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.