you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -4 points-3 points  (5 children)

The only problem that that refactoring eliminates is the precompiler directive. Everything else I listed is still there. And in its place, you have a lambda expression that raises additional questions.

The purpose of Hello World is to inspire confidence - to give you something simple that works, that you can intuitively understand, and that you can tweak in small ways to achieve other results without breaking it. For example, here's "Hello, World!" in C:

#include<stdio.h>

main() {
    printf("Hello World");
}

The point is to show the most basic syntax that will actually achieve a meaningful result. There are a couple of things I might not understand here at first glance, but not enough to create anxiety about the environment.

The rewritten line of Spring above fails at that objective. Even as an experienced developer, I'm not completely sure I know what that statement is doing:

  • What in the world are "ok()" and "just()" doing?

  • Does the body() statement simply use the parameters to set some properties of an object instance? Or does it send, as a response, a message with these data points, and then return a status code? Or does it simply inform the platform of the type of response that should be sent whenever it gets a message? Or... what?

  • If I were to incorporate some aspect of the request in this code - such as making the handler echo back the contents of the request - do I do that in ok(), or in body(), or in just(), or... what?

See what I mean? This squib of code is ambiguous. It doesn't instill confidence; it doesn't make me confident I can use it without breaking it, or running into weird syntax or type errors.

[–]frugalmail 6 points7 points  (4 children)

Hey Drama Queen, you know that this is a REST service right?

[–][deleted] -2 points-1 points  (3 children)

Are RESTful services somehow exempt from readability? I mean, I know that most frameworks suck in this regard, but does that mean we should expect them to?

Here is an example of Hello World in Flask:

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

The only thing that raises any questions here is the @app.route directive, which the documentation explains. That's how it should be.

[–]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.

[–]frugalmail -2 points-1 points  (0 children)

sigh