Live data from Hacker News

Show HN: Rocket – Web Framework for Rust

rocket.rs

61–70 of 123 posts

Re: Show HN: Rocket – Web Framework for Rust

#61
post #58

edit: see replies to my comment. I mistook the Hyper pull request being merged for being in the latest release, but it isn't. Rocket uses Hyper for its HTTP server. So I checked to see if the Hyper HTTP server was really production-ready. Particularly, if it could handle async IO / solve the C10K problem[0]. It looks like Hyper implemented async IO[1], so it should be adequate for production use in this regard. This…

Hyper is not yet async, the preliminary work in the PR you linked to is for a version which has not been pushed to crates.io and is not finished yet.

Re: Show HN: Rocket – Web Framework for Rust

#62

Earlier quoted context omitted.

Sorry but I cannot agree. I work on the JVM and this pattern is great for "hello world" webapps but breaks down pretty quickly. When large parts of your logic like metrics, security and routing is being done with metaprogramming you're really doing yourself a disservice.

If you don't like routing being done with metaprogramming, you can manually create routes yourself similar to this example[0]. I think the author is trying to show appealing APIs. [0] - https://github.com/SergioBenitez/Rocket/blob/master/examples...

Thank you. Actually, that underlying API looks great. I would prefer it any day of the week.

Re: Show HN: Rocket – Web Framework for Rust

#63
post #56

Earlier quoted context omitted.

I've worked a lot with this pattern in Python (Flask), Java and Scala. I have found it a little inconvenient beyond the simple hello world app when dealing with Flask, but I haven't encountered this problem with Java/Scala. To date, I've worked on probably 4-5 separate applications using this pattern and it's worked quite well. I have also used Spring 4 on the JVM, which ... feels more flexible, but also has a lot of…

I've worked on everything you mention and more, and I find the simplicity of say node.js or SparkJava very refreshing when coming from metaprogramming frameworks. Once you go metaprogramming everything is suddenly metaprogramming. Data serialization is metaprogramming. Middleware is metaprogramming. Adding your own plugins to the framework becomes metaprogramming. Also, because the framework wants to create your clas…

Thanks for clarifying. I agree with you, mostly.

This is exactly the reason why I refuse to use Lombok. It literally mutates your bytecode! That's a disaster waiting to happen, and a potential debugging nightmare.

I think that there is a fair balance where metaprogramming has great utility. For example, I'm a huge proponent of Guice. And yes, sometimes it makes debugging issues a little more complicated. OTOH, without it, there's a lot of boilerplate. Admittedly, DI in Java is a workaround for an inherent Java problem (boilerplate). Maybe it wouldn't be so useful in other languages/ecosystems. I have written services both with and without DI, and prefer it, and haven't had significant issues debugging or managing it. But it must remain scoped.

As for library compatibility issues, that is more of a byproduct of dynamically linked libraries than metaprogramming. If you're writing in a JVM language, you're kind of stuck with this (OK, you could shade your library and all its dependencies to get away from it, if you want to deal with the bloat / impact to the JIT'er).

Having said all that, your statements are arguing against metaprogramming, and I'm not really arguing for or against metaprogramming in my original comment. Simply, I think the pattern of defining HTTP resources in the aforementioned way is very intuitive from a software development perspective. If it can be done without metaprogramming, then great. But the presence of metaprogramming doesn't, in my mind, preclude the effectiveness of the pattern.

Re: Show HN: Rocket – Web Framework for Rust

#64
post #63

Earlier quoted context omitted.

I've worked on everything you mention and more, and I find the simplicity of say node.js or SparkJava very refreshing when coming from metaprogramming frameworks. Once you go metaprogramming everything is suddenly metaprogramming. Data serialization is metaprogramming. Middleware is metaprogramming. Adding your own plugins to the framework becomes metaprogramming. Also, because the framework wants to create your clas…

Thanks for clarifying. I agree with you, mostly. This is exactly the reason why I refuse to use Lombok. It literally mutates your bytecode! That's a disaster waiting to happen, and a potential debugging nightmare. I think that there is a fair balance where metaprogramming has great utility. For example, I'm a huge proponent of Guice. And yes, sometimes it makes debugging issues a little more complicated. OTOH, withou…

Ok, I hear you. I agree somewhat, but not totally :) To me, the most important aspect of programming is to retain full control. I for instance want to be able to register my HTTP endpoints based on some data read from a file. I want to be able to start my app in server mode and run requests against it in any way I want during testing. What many of these frameworks do is to remove this power.

Bytecode modification is not too bad IMO, as long as it's within reason. I use a notnull annotation weaver to add notnull assertions. Not Lombok, that's too much for me as well. Should be another language really, like Kotlin.

Metaprogramming does have utility. But it has a tendency to go overboard. I actually find Jersey to be a good example of a nice and clean API for defining resources. I recently tried to integrate it into a small app where we do all the wiring manually for clarity. The problem is that it's hard to stay in programmatic control. You define a resource. You realize you need a Service in your resource. You realize that the only way of getting it into your object is to inject it with the JAX-RS annotations. And so suddenly your service has to be a JAX-RS @Singleton service. You have to make your whole app JAX-RS compatible. The framework takes control. This is really bad IMO. A library which requires control over your program.

This is not an intrinsic problem of metaprogramming, but IMO it's a big problem of Java as it stands today. We need to give up on frameworks, make sure that all libraries are combinable and that they don't take control of your app. Doing so would make everything a lot better.

I wish I could just do:

new Jersey(config).addRoutesIn(new HelloWorldResource(new MyBackendService(dbDriver))).addSerializer(new JsonSerializer()).start();

This would then utilize some reflection when routing requests, but not take over my entire app.

Regarding the libraries, my point was not that you get conflicting classes (DLL hell sort of thing), but that we're building multiple products which want to take over the world. JUnit wants to be in control, and so does Spring. So when you try to combine them, you end up with a problem. Can you start Spring programmatically from a JUnit test? Well, not really. You can, but it's very involved. So they want to provide you with a Spring-JUnit integration. This is a really bad idea, since every linear combination of libs has to get an integration, like the link I included in my post. If all these libraries just tried to stay out of the way of the programmer and just provide a programmatic API, there would be no need for such integrations.

Re: Show HN: Rocket – Web Framework for Rust

#65

Are dynamic params enforced at compile time? I.e. will the compiler ensure that the route "/ " has a matching id parameter?

Yes! Here's what happens when you don't do the right thing: error: 'id' is declared as an argument... --> src/main.rs:8:9 | 8 | #[get("/ ")] | ^^^^ error: ...but isn't in the function signature. --> src/main.rs:9:1 | 9 | fn hello() -> &'static str { | _^ starting here... 10 | | "Hello, world!" 11 | | } | |_^ ...ending here

that is some truly incredible developer ux

Re: Show HN: Rocket – Web Framework for Rust

#68
I suppose this an advance for those already using Rust but the core message on the front page doesn't speak to me as a non-Rust person.

FTA: Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety. All with minimal code.

I'm at a total loss for why I really care about this major part of their message (type safety). If I have already switched to Rust then I care about type safety already and you don't need to sell me on Rust, you should focus on differentiating this web framework from the ones that came before it. But if I haven't switched to Rust then I am essentially unswayed by their messaging. I can't see why it's particularly important or different over other language/frameworks for web development.

Before learning Ruby I watched the Rails blog video sometime around version 0.14.3. Immediately you could the value of the framework and the ease of a language I was unfamiliar with. The win I could see was productivity and it was enough for me and a lot of other people to learn Ruby. I don't see that with this framework or really anything in the Rust world.

Re: Show HN: Rocket – Web Framework for Rust

#69
post #68

I suppose this an advance for those already using Rust but the core message on the front page doesn't speak to me as a non-Rust person. FTA: Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety . All with minimal code. I'm at a total loss for why I really care about this major part of their message (type safety). If I have already switch…

What I think the author is trying to portray is that they achieved Ruby/Python level code (in terms of boilerplate and readability) while retaining the typesafety and performance that makes Rust attractive in the first place. That's a step up in every direction. This is, of course, tackling the notion that readers might associate strongly-typed web frameworks with verbosity and complexity, whereas Rocket is neither.

I think that's important to those both familiar with rust (who want a clean framework) and those who aren't (who want a safe language without sacrificing productivity).

Re: Show HN: Rocket – Web Framework for Rust

#70
post #68

I suppose this an advance for those already using Rust but the core message on the front page doesn't speak to me as a non-Rust person. FTA: Rocket is a web framework for Rust that makes it simple to write fast web applications without sacrificing flexibility or type safety . All with minimal code. I'm at a total loss for why I really care about this major part of their message (type safety). If I have already switch…

Learning that there is a framework that gives you both flexibility and type safety might be a good reason to jump into Rust if you haven't already.
Post reply on HN