Blog post: Rust vs Julia in scientific computing

Thank you for indirectly assuming that I am not aware of the Julia ecosystem. I actually am, but you did not read the whole blog post and did the cherry picking that you criticize :slight_smile: Because I have an appendix about JET.jl

It is nice that you can get a bit closer to the Rust version in Julia. But you are missing the point of having proper sum types as first class citizens in a language that tells you what a function exactly returns in its signature.

I think that although Any provides flexibility in dynamic languages, collections of Any is a big mistake in a language focused on Performance.

Rust has enums which are sum types that can provide you with that flexibility:

enum Color {
    Gray(u8),
    RGB(u8, u8, u8),
    RGBA(u8, u8, u8, u8),
    Named(String),
}

// `colors` has the type Vec<Color>
let colors = vec![
    Color::Gray(42),
    Color::RGB(10, 0, 20),
    Color::RGBA(0, 0, 255, 100),
    Color::Named(String::from("red")),
];

There are also trait objects which you can use if you only care about the structs implementing some behavior (trait).

This is what I teach in my Julia courses, but it still happens that a vector does not end up with a concrete type that you expect and Julia will not even warn you about it. This is what I did mean with " Have fun profiling, using the macro @code_warntype while interactively calling a function, etc."

I think that Julia should have taken the approach of Rust of deriving the type of the vector without even having to specify it like in the following example:

// The type of the vector is not known yet, but it will be derived.
let mut v = Vec::new();

// We push a float with 64 bits, therefore v has the type Vec<f64>.
v.push(1.0);

// The type will not change!
// The line below will give a compile error because we are pushing an integer into a vector of floats.
// v.push(1);

You can specify variable types in Rust, but you don’t have to in most cases.