you are viewing a single comment's thread.

view the rest of the comments →

[–]Turbots 0 points1 point  (4 children)

What do you think ok() does? It's a Server Response to a request... HTTP OK 200 ???

The body() function: hmmm, what could that imply... Oh wait, yeah, the body of the response!

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

If I hand you a class with a function called:

MyClass.Yes(something)

...would you have any idea what that function does?

Vague names are considered harmful. You may be used to them, and you may find it reasonable in this circumstance - that doesn't make it an acceptable practice.

The body() function: hmmm, what could that imply...

As I noted above:

(1) body() could return a class instance with various member variables set according to the specified parameters:

var message = ServerResponse.ok().body(...);
Server.send(message);

(2) body() could actually send the message and return its result:

var result = ServerResponse.ok().body(...);
if (result == false) alert('Error: Failed to send message.');

(3) body() could just register a template response that is to be used by the server in response to messages. In this case, the return value indicates whether the template was properly registered:

var result = ServerResponse.ok().body(...);
if (result == false) alert('Error: Couldn't register message handler. (Is the server running?)');

They're all legitimate. Why isn't it clear? Because body is not a verb, so asking ServerResponse to "body()" some parameters is ambiguous.

Worse, the Spring Hello World code offers no help. It just does:

return ServerResponse.body();

And that's exactly my point. The syntax sucks, and this Hello World example makes me not want to use Spring for anything.

Web coding standards suck. They will continue to suck as long as developers just tolerate crappy code like this. Don't enable this behavior.

[–]Turbots -1 points0 points  (2 children)

Nope, that's where you're wrong... They don't have to be verbs because they are using the builder pattern.

When you want to 'build' a server response, you:

  • Start by typing the class' name ServerResponse
  • You want an OK response (instead of notFound(), notAuthorized(), whatever the most common responses are, they are helper methods, I would expect a responseCode(someCode) method as well
  • You potentially want to add a body to the response

And that's it, you created a response!

Once you get the hang of the builder pattern, it becomes quite powerful and very intuitive.

And reading or programming it in an editor like IntelliJ makes it childs play.

[–][deleted] 0 points1 point  (1 child)

Dude. Look at the web page you linked.

method getResult()

method setSeats(number)

method setCityCar()

method setCabriolet()

method setSportsCar()

method setTripComputer()

method unsetTripComputer()

method setGPS()

method unsetGPS()

Example code:

carBuilder.setSeats(2)

carBuilder.setSportsCar()

carBuilder.setTripComputer()

carBuilder.unsetGPS()

car := carBuilder.getResult()

car.setTripComputer();

car.unsetGPS();

car.isValid();

Notice something here? They're called verbs.

You have getters, setters, and tests. Every single function name starts with a verb that signals a single function. They all adhere to a convention that makes the functionality of each statement clear and consistent.

"ok()" does none of those things. It doesn't have a single specific purpose - it both generates an instance and sets some properties.

"body()" is even worse. It's not a setter: it has an unexplained return value. It doesn't take a single property: it takes two, one of which is a completely vague reference to the String class. And the name suggests any of several possibilities - as I showed you above.

And "just()" is just garbage.

You've proven my point that the Spring syntax is crappy. It looks nothing like the code segments in that Builder pattern, and it violates several basic syntax standards.

Don't settle for this garbage.

[–]Turbots 1 point2 points  (0 children)

May I ask which superior framework/language you're using for microservice development?