Live data from Hacker News

Writing a website in Rust

blog.viraptor.info

121–130 of 141 posts

Re: Writing a website in Rust

#121
post #100

Whenever someone writes bad things™ about some language, one of the language's fanboys shows up and starts nitpicking! Yes, now is the time! > Another bad part is Rust’s JSON handling. It badly needs macros which make things easier. Actually this is not the end of the world. As you mentioned, Rust's JSON library supports `ToJson` for primitive types, but also provides compile-time code generation for arbitrary `struc…

I haven't actually gotten a chance to use Rust yet, but would something like this work?

    #[derive(RustcDecodable, RustcEncodable)]
    enum Msg {
        Basic { cmd: String, id: i32 },
        Positioned { cmd: String, id: i32, x: i32, y: i32 },
        Speed { cmd: String, id: i32, speed: i32 },
        Full { cmd: String, id: i32, x: i32, y: i32, speed: i32 }
    }
That would allow you to prevent weird cases like x being provided but y not being provided.

Re: Writing a website in Rust

#122
post #66

Earlier quoted context omitted.

I'm actually working right now on a `cargo check` command which only runs those phases of the compiler to do with typechecking, to accommodate workflows based around tweaking types and then running the compiler to check your work. Given that the vast majority of compilation time is currently based in code generation and linking, this should drastically improve usability for this sort of rapid-iteration, dynamic-langu…

This is a great idea. I wish other compilers would offer this feature (scalac is in dire need of such an option). Does the Rust macro system require compile-time compilation before type-checking?

Not really. Macro expansion occurs during its own phase of compilation (which, in my experience, is generally really fast).

Re: Writing a website in Rust

#123
post #100

Whenever someone writes bad things™ about some language, one of the language's fanboys shows up and starts nitpicking! Yes, now is the time! > Another bad part is Rust’s JSON handling. It badly needs macros which make things easier. Actually this is not the end of the world. As you mentioned, Rust's JSON library supports `ToJson` for primitive types, but also provides compile-time code generation for arbitrary `struc…

I haven't actually gotten a chance to use Rust yet, but would something like this work? #[derive(RustcDecodable, RustcEncodable)] enum Msg { Basic { cmd: String, id: i32 }, Positioned { cmd: String, id: i32, x: i32, y: i32 }, Speed { cmd: String, id: i32, speed: i32 }, Full { cmd: String, id: i32, x: i32, y: i32, speed: i32 } } That would allow you to prevent weird cases like x being provided but y not being provided…

Yup, you can encode enums just fine. ADTs get encoded with an explicit `variant` tag at the front, and then an array of field values. For e.g:

    { "variant": "Basic", fields: ["cmd-value", 42] }
    { "variant": "Positioned", fields: ["cmd-value", 42, 0, 0] }
    //etc ...

Re: Writing a website in Rust

#124
post #111

Earlier quoted context omitted.

Go actually check the things pcwalton mentioned instead of complaining.

Please provide comparison measurements of the things pcwalton mentioned. Just a URL to published comparison measurements would be so much more interesting for anyone interested in Rust, than downmods.

http://erickt.github.io/blog/2014/12/13/performance-digressi...

Re: Writing a website in Rust

#125

Earlier quoted context omitted.

This is a great idea. I wish other compilers would offer this feature (scalac is in dire need of such an option). Does the Rust macro system require compile-time compilation before type-checking?

Not really. Macro expansion occurs during its own phase of compilation (which, in my experience, is generally really fast).

Macro expansion can lead to programs that don't typecheck, unless a very restrictive typing system is used (e.g. MetaML, MetaOcaml). I don't think Rust has such restrictions, therefore I assume that type-checking happens after macro expansion.

Re: Writing a website in Rust

#126

Earlier quoted context omitted.

Not really. Macro expansion occurs during its own phase of compilation (which, in my experience, is generally really fast).

Macro expansion can lead to programs that don't typecheck, unless a very restrictive typing system is used (e.g. MetaML, MetaOcaml). I don't think Rust has such restrictions, therefore I assume that type-checking happens after macro expansion.

It does, but what I was getting at was that full compilation doesn't need to occur first. Macro expansion is one of the very first phases of compilation (and doesn't have access to typechecking information, incidentally).

Re: Writing a website in Rust

#127
post #111

Earlier quoted context omitted.

Please provide comparison measurements of the things pcwalton mentioned. Just a URL to published comparison measurements would be so much more interesting for anyone interested in Rust, than downmods.

http://erickt.github.io/blog/2014/12/13/performance-digressi...

How about some measurements made with rustc 1.0.0?

(There seem to have been plenty of breaking language changes in the last 6 months.)

Re: Writing a website in Rust

#128

Earlier quoted context omitted.

Macro expansion can lead to programs that don't typecheck, unless a very restrictive typing system is used (e.g. MetaML, MetaOcaml). I don't think Rust has such restrictions, therefore I assume that type-checking happens after macro expansion.

It does, but what I was getting at was that full compilation doesn't need to occur first. Macro expansion is one of the very first phases of compilation (and doesn't have access to typechecking information, incidentally).

So Rust macros don't offer full compile-time meta-programming?

Re: Writing a website in Rust

#129

Earlier quoted context omitted.

It does, but what I was getting at was that full compilation doesn't need to occur first. Macro expansion is one of the very first phases of compilation (and doesn't have access to typechecking information, incidentally).

So Rust macros don't offer full compile-time meta-programming?

Not in Rust 1.0. In the nightlies there are syntax extensions available that give you more power, but those are likely to see significant revisions before they're available in a stable version since they're a major backwards compatibility hazard.

Re: Writing a website in Rust

#130

Earlier quoted context omitted.

So Rust macros don't offer full compile-time meta-programming?

Not in Rust 1.0. In the nightlies there are syntax extensions available that give you more power, but those are likely to see significant revisions before they're available in a stable version since they're a major backwards compatibility hazard.

Who's working on this? I may have something to contribute in this direction.
Post reply on HN