#Watch a bunch of Rust wannabes cry about code formatting

27 messages · Page 1 of 1 (latest)

loud hollow
#

wow that is certainly some formatting. I would highly recommend running cargo fmt, to make it a lot easier to read for most people

#
        let mut i;
        let mut j;
        let mut k;
        let mut l;
        let mut w;
        let mut h;```this kind of thing where you lay out the variables ahead of time is discouraged, just declare the variables when you initialize them
#

like seriously that formatting and often not indenting in things like while loops is ferrisballSweat

#
    //Sweep over 3-axes
    let mut d =0;
    while d<3 {
            // code

            d += 1;
        }```This should be written like this ```rs
for d in 0..3 {
    //code
}```Assuming that `d` is not modified elsewhere in that loop. The for loop version is much more readable because its not possible to modify `d`
#

@manic pagoda

manic pagoda
#

........?

#

why would you ping me for this

loud hollow
#

not sure if you saw it

manic pagoda
#

yes thank you, the code I typed up in a single day with 0 rust experience isn't perfect. I had a specific question.,

#

I'm aware it can be cleaned up

loud hollow
#

just suggesting a few things that would make the code better in general, so its easier for people to try looking at it

manic pagoda
#

alright thanks

dull canopy
#

Robo's just trying to help. And I agree, cleaning up the code would be a big help toward understanding what its performance bottlenecks might be. And just copying JS to Rust 1:1 doesn't necessarily mean that the program should run the same between both languages.

As it stands, it's going to be really hard to analyze this code by hand in order to potentially make recommendations of how to improve the speed. To answer one of your specific questions, no, casting probably won't make a huge difference.

manic pagoda
#

I already figured it out

#

rust is just too slow compared to javascript it is what it is, fun language though

loud hollow
#

wasm is slow, if it was running natively it would definitely be faster

manic pagoda
#

I was only joking I actually fixed it already

#

WASM runs over 2x as fast as the JS now 😄

loud hollow
#

but basically two command line command recommendations, cargo fmt to format it, then cargo clippy for code cleanup suggestions

manic pagoda
#

no

woeful folio
manic pagoda
#

I was using the js_sys::Uint8Array type, and I was using get_index for each lookup, so what I did instead was

let data: Vec<u8> = volume.to_vec();

at the start to convert it into a "rust array" for lookups.

#

and now my hard work has payed off

#

it runs SO much faster than the javascript, im impresse

woeful folio
#

cool

#

yeah thats usually the trick. Doing less wasm <-> JS stuff

manic pagoda
#

Watch a bunch of Rust wannabes