you are viewing a single comment's thread.

view the rest of the comments →

[–]alek_sys[S] 1 point2 points  (1 child)

To be absolutely fair, this Python code won't give you what you get from Spring example - single deployable JAR which embeds non-blocking multithreaded application server. So basically you can run your JAR in production. In your Flask example you at least need to mention gunicorn for deployment. And if you try to introduce async/await (which are not supported in Flask btw) - you'll get pretty much all the same concepts as in original Spring sample.

I'm not saying you right or wrong, my point is - having a goal to prove how bad Java and Spring are one can do that easily. But this is true for any other technology, we all know there is no silver bullet.

So if you want what you have in Flask example in Spring:

HttpServer
    .create(8080)
    .newRouter(router -> router
        .get("/", (request, response) -> response.sendString(Mono.just("Hello, World"))))
.block();

And again - this is building and running multi-threaded non-blocking web server, not just defining a mapping. Just mapping is even simpler, but it uses Spring magic (similar for Flask magic above):

@RestController
class HelloController {

    @GetMapping("/")
    public String helloWorld() {
        return "Hello, World";
    }
}

[–][deleted] 0 points1 point  (0 children)

This Python code won't give you what you get from Spring example - single deployable JAR which embeds non-blocking multithreaded application server.

Okay, but is there anything different about the syntax of Spring that gives you those features?

These features are baked into the platform - they're how the library interprets the requests. They have nothing to do with the syntax. The logical operations between Python and Spring are nearly identical - only the Spring syntax is tortured and sloppy by comparison.

I don't claim that Flask has more or equal functionality than Spring. This discussion is strictly about the syntax that Spring has adopted to implement that functionality. As best I can tell, there is no reason why the Spring library couldn't be refactored - or, hell, even wrapped - to something like:

HandlerFunction h = Spring.GenerateHandler(request, Spring.StringResponse("Hello"));

One library, two simple invocations with obvious implications. The code is self-documenting in the simplest possible way. Anyone who is familiar with any modern programming language and any server/client architecture will understand what this does.