Live data from Hacker News

Writing a website in Rust

blog.viraptor.info

61–70 of 141 posts

Re: Writing a website in Rust

#61

Earlier quoted context omitted.

Crates.io is built this way: Rust serving JSON on the back end, Ember consuming it on the front end.

What kind of database does crates.io use?

Postgres: https://github.com/rust-lang/crates.io

It also stores the index via git and S3...

Re: Writing a website in Rust

#62

Regarding compile time, you can track the passes with `-Z time-passes` and wait for borrowck/lints to get over (or just typeck if you're only worried about types). There also was [this plugin]( http://www.reddit.com/r/rust/comments/2krdbu/rest_easy_a_lin... ), but it's outdated at the moment (I can upgrade it later). Regarding imports, `use foo::bar::*` works.

I'd love something similar to be part of Cargo, maybe as an option in the manifest. Like the author, I've learned to guess when the codegen starts, but having this information displayed would be useful.

Re: Writing a website in Rust

#63

Regarding compile time, you can track the passes with `-Z time-passes` and wait for borrowck/lints to get over (or just typeck if you're only worried about types). There also was [this plugin]( http://www.reddit.com/r/rust/comments/2krdbu/rest_easy_a_lin... ), but it's outdated at the moment (I can upgrade it later). Regarding imports, `use foo::bar::*` works.

For use, I meant that there are so many packages you just take space just listing them. For basic iron you need: iron::prelude::*, iron::status, staticfile, logger, router, handlebars_iron, and more. And these are all from different crates.

This is the same in even many dynamic languages, though, isn't it?

Re: Writing a website in Rust

#64

Earlier quoted context omitted.

Refcounting and tracing are two different forms of GC, but you're right in the sense that most people mean tracing. At the same time, we're putting a lot of thought into how to properly add an optional tracing GC. It's important that it doesn't impact the no-GC case, which is still, of course, primary.

I'm glad to know there is ongoing work on a tracing GC. Rust has many strengths aside from lifetimes and ownership (algebraic data types, sane generics, strong module support, very strong type system), so a few features to make it more usable for use in contexts where performance isn't as important as expressivity would be very nice to have.

IMO, "contexts where performance isn't as important" aren't very relevant to Rust (hence why I'm strongly against, for example, hardcoding a global GC into the language, or splitting the language into a GC'd and non-GC'd half). But I do understand why some people would like to use the same language for all these use cases, I suppose.

Re: Writing a website in Rust

#65
post #11
post #7

Earlier quoted context omitted.

Just to add some context, here are the tests which I didn't write, but would in Python/Flask usually: - Proper behaviour if I don't pass a parameter. Not needed, because it's an explicit `Option ` which I have to handle. - Is results list constructed properly / what's the None-vs-empty behaviour. Not needed, `Vec ` is verified at type level and None is not possible. - What happens if various database functions don't…

I've had a similar experience writing web-apps in Scala. The Option type alone handles so many cases which would otherwise require unit-tests in Python or another unityped language.

I'm a Python/Flask dev who has knowledge of the basics of Scala. Which web framework and ORM would you recommend to develop a (potentially) non-trivial web app?

Re: Writing a website in Rust

#66

Regarding compile time, you can track the passes with `-Z time-passes` and wait for borrowck/lints to get over (or just typeck if you're only worried about types). There also was [this plugin]( http://www.reddit.com/r/rust/comments/2krdbu/rest_easy_a_lin... ), but it's outdated at the moment (I can upgrade it later). Regarding imports, `use foo::bar::*` works.

I'd love something similar to be part of Cargo, maybe as an option in the manifest. Like the author, I've learned to guess when the codegen starts, but having this information displayed would be useful.

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-language-style workflow. (Though also note that improving the speed of codegen and linking is an ongoing task as well.)

Re: Writing a website in Rust

#67
post #65
post #11

Earlier quoted context omitted.

I've had a similar experience writing web-apps in Scala. The Option type alone handles so many cases which would otherwise require unit-tests in Python or another unityped language.

I'm a Python/Flask dev who has knowledge of the basics of Scala. Which web framework and ORM would you recommend to develop a (potentially) non-trivial web app?

If you want to use Scala, Play Framework 2.4 + Slick 3.0 would be the deadliest combination in my opinion.

Re: Writing a website in Rust

#68

Earlier quoted context omitted.

That is not strictly true. Look at Snabb switch, written almost entirely in LuaJIT for example https://github.com/SnabbCo/snabbswitch - you need some kind of ffi to mmap device memory, but it is quite possible. (LuaJIT is fast of course which helps for 10Gb ethernet).

That's kinda what I was thinking when I commented, and there are sure to be exceptions. But I don't see anything different with your Snabb switch example. You can probably use Java and JNI for that matter to call mmap, but would you be able to write an implementation of mmap in LuaJIT ?

Yes you can call mmap with the ffi in LuaJIT just fine. It is not very complicated, it just asks the kernel to do it. Implementing what the kernel does, well that does need some assembly.

Re: Writing a website in Rust

#69

Earlier quoted context omitted.

Last I checked, a 'rails new' gives you over 40 dependencies off the bat.

Yes, the Rails and Node communities are known for insanity.

I put all node functions I might want to re-use in other projects on NPM by themselves (though this also usually pushes me to make a lot of unit tests for each of them, which is a nice benefit). I'm not really clear on what's insane about re-using a lot of small modular parts. This is way better than copying and pasting functions between codebases, and then trying to keep them (and their tests) all in sync.

Re: Writing a website in Rust

#70

The tooling for the web written in JavaScript is excellent, so I was curious, are there any options there are for calling JavaScript from Rust code? I know there is the ffi module for NodeJS that allows you to call Rust from JavaScript, but I was wondering if there is something that works well in the other direction.

Embedding JS in Rust by using V8 (as kibwen has mentioned) would be no problem, but using node.js modules might not be so easy. It's like calling ruby gems from C.

What do you mean by "tooling for the web"? If it's preprocessors like LESS (that are written in JS), you could run the JS in V8 to transform the CSS efficiently, but maybe the compiler "binary" (script) is enough. In this case it's the best approach, since performance will be good, and you don't have to reinvent everything.

But if it's something like express.js, it's probably not worth it.

It's surely possible somehow, but in a pretty hacky way and at the cost of high overhead and complexity caused by calling from a static language to a dynamic one.

Post reply on HN