Skip to content

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

@chris-morgan

Description

@chris-morgan

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions