Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it a good idea to have so many closures? #2

Open
chris-morgan opened this issue Oct 1, 2013 · 1 comment
Open

Is it a good idea to have so many closures? #2

chris-morgan opened this issue Oct 1, 2013 · 1 comment

Comments

@chris-morgan
Copy link

My feeling of the present state of things here is that closures are being used excessively, in ways that don't add value. For example, the closure-taking constructor and sort-of-setter methods feel weird. Taking the main function of the README example:

fn main() {
    let app = do Application::new |app|
      {
        do app.settings |settings| {
          settings.socket = Some(SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 4000 })
        }
        do app.routes |routes| {
          routes.get(~"/foo/(?<id>.*)", hello_world);
          routes.post(~"/", hello_post);
        }
      };
    let server = WidmannServer::new(app);
    server.serve_forever();
}

It seems to me that that would be much nicer like this:

fn main() {
    let app = do Application::new();
    app.settings.socket = Some(SocketAddr { ip: Ipv4Addr(127, 0, 0, 1), port: 4000 });
    app.routes.get(~"/foo/(?<id>.*)", hello_world);
    app.routes.post(~"/", hello_post);
    let server = WidmannServer::new(app);
    server.serve_forever();
}
@skade
Copy link
Owner

skade commented Oct 2, 2013

I am not decided on that yet. In general, I'd like Application to be some glue around Routes and the settings system, so maybe I'll decide on changing that.

From an API perspective, it allows me to get call some hooks in between to set stuff up, which the user would have to call otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants