News for hackers. Stuff that matters.
Re:TodoMVC in Rust by mattmanser on Wednesday September 23, 2015 @07:21AM (#10264349)
I appreciate it's to demo the capacity to compile Rust to js, but that's some really nasty code.

https://github.com/tcr/rust-todomvc/blob/master/src/main.rs

Why put it all in the main? Why define functions as variables? Why .parent().unwrap().parent().unwrap()?

Re:TodoMVC in Rust by timcameronryan on Wednesday September 23, 2015 @01:57PM (#10266715)
It is nasty code! I started refactoring before I hit some struct-alignment bugs (fixed on later Rust versions): https://github.com/tcr/rust-todomvc/blob/tcr-wip/src/main.rs

The parent navigation needs to be replaced by a jQuery-like .ancestors() macro.

This was an MVP so I wasn't focused on code quality over features; but I'm also learning Rust for the first time, so it came out less than impressive :)

Re:TodoMVC in Rust by steveklabnik on Wednesday September 23, 2015 @11:02AM (#10265435)

  > Why define functions as variables?
I'm not sure what you mean here, exactly.

  > Why .parent().unwrap().parent().unwrap()?
I'm not mega familiar with the code, but using a low-level binding to something else that has nulls often means a lot of Option, which means a lot of unwrapping. A nicer library could probably get rid of some of this.
Re:TodoMVC in Rust by valarauca1 on Wednesday September 23, 2015 @11:37AM (#10265673)
>which means a lot of unwrapping

     .unwrap()
In rust is generally a bad pattern to use. Its basically short hand for

    let o :Option< u64 >;

    let value :u64 = match o {
                        Some( t ) => t,
                        None => panic!()
                     };
So if you don't met the condition, you explode. When ever you see .unwrap() in Rust just mentally switch it for /TODO add error handling */
Re:TodoMVC in Rust by steveklabnik on Wednesday September 23, 2015 @11:59AM (#10265829)
Yeah, I was just using "unwrapping" as a more general term for "extract the T out."

We almost changed 'unwrap' to 'assert', but people found it a bit too weird.

Re:TodoMVC in Rust by valarauca1 on Wednesday September 23, 2015 @12:15PM (#10265941)
>We almost changed 'unwrap' to 'assert', but people found it a bit too weird.

That is weird. idk I guess its already sort of being done, you're more or less asserting Option::Some( _ ) is the value.

Re:TodoMVC in Rust by seivan on Wednesday September 23, 2015 @08:43AM (#10264643)
I wonder if it would looks a bit nicer with .jsx support.
Re:TodoMVC in Rust by timcameronryan on Wednesday September 23, 2015 @02:02PM (#10266756)
I can't wait for a JSX crate on Cargo.