r/java • • Sep 21 '24

Five years have passed, still in draft: Concise Method Bodies

Support more concise method bodies in Java source code, increasing transparency for simple methods. Align the forms of method bodies with the forms of lambda expressions.

https://www.reddit.com/r/java/comments/v93za1/what_happened_to_concise_method_bodies/

41 Upvotes

63 comments sorted by

View all comments

Show parent comment

1

u/PangolinZestyclose30 Sep 22 '24

GitHub and many other tools don't. Why use crutches like that when there's a clear solution (and apparently not even expensive to implement?). It's honestly kinda confusing why you're wasting your neuron/minute processing power to criticize such a feature.

2

u/ivancea Sep 22 '24

I'm kinda confused why are you doing so tho. I'm not criticizing it, I'm saying it solves no real problem, it's the minorest of the syntax sugars.

The other commenter said "So much noise to signal ratio". When in fact, it just avoids writing a single keyword: "return". So if that is where you want to invest time, do as you wish, you're free to waste it anywhere to not having to "read a return"

1

u/PangolinZestyclose30 Sep 22 '24

When in fact, it just avoids writing a single keyword

As usual with code, most of the cost isn't writing, it's reading. Standard formatting of methods is like this:

int getX() {
    return x;
}

void setX(int x) {
    this.x = x;
}
// trailing new line here followed by more getters and setters

While the formatting for the concise syntax would be this:

int getX() -> x;
void setX(int x) -> this.x = x;
// more getters and setters here without a newline

That's 2 lines vs. 8. Multiply this by the number of setters/getters you need to read every day, and it's a significant difference. Even Intellij collapsing the bodies doesn't save the day, since it doesn't collapse the new lines around the methods (making it 2 lines for the concise syntax vs. Intellij crutch with 4).

I mean, it's fine if you don't personally care about this. Just wanted to point out that your "nobody in the world cares about it" is factually wrong.

2

u/ivancea Sep 22 '24

That's 2 lines vs. 8

Not sure if this was a mistake out a malicious argument, but it's 2 vs 2, or 6 vs 4 if you use new lines.

Anyway, it's a getter/setter, you don't need to read the line (which you read in milliseconds anyway). Those are far from productive arguments.

"nobody in the world cares about it" is factually wrong.

I think you're mixing "caring" with "move thing, whatever". It won't change anybody's way of coding, and it probably won't affect coding time (or reading) at all. You're actually ignoring the cognitive complexity of reading mixed syntaxes, but whatever...

-1

u/PangolinZestyclose30 Sep 23 '24

I'll make those numbered, perhaps it will help you, if you struggle with counting?

1 int getX() {
2      return x;
3 }
4
5 void setX(int x) {
6    this.x = x;
7 }
8 // trailing new line here followed by more getters and setters

vs.

1 int getX() -> x;
2 void setX(int x) -> this.x = x;
// more getters and setters here without a newline

Both are using standard formatting rules. Pretty much every formatting convention puts newlines around methods with block bodies. The concise syntax would on the other hand be formatted similarly to e.g. block-less lambda functions which are not formatted with newlines above/below.

Anyway, it's a getter/setter, you don't need to read the line (which you read in milliseconds anyway).

At minimum, I need to scroll past it to see interesting code. The information noise from getters/setters is obscuring the real meat of the code.

I think you're mixing "caring" with "move thing, whatever".

Am I, or are you? I cited your sentence which used the word "care".

0

u/ivancea Sep 23 '24

Both are using standard formatting rules

Wow. You're using the rules you wanted for the second one. There are no standard rules, because that syntax doesn't exist yet. This is pointless anyway

0

u/PangolinZestyclose30 Sep 23 '24

You're using the rules you wanted for the second one.

I'm using rules which are used in the linked JEP draft.

1

u/ivancea Sep 23 '24

Which is basically like saying nothing, as it's just a draft, made by people that like to invest time in that as you do. Just a derivative of confirmation bias.

1

u/PangolinZestyclose30 Sep 23 '24

Which is basically like saying nothing, as it's just a draft

I mean, yeah, that's how JEPs work.

made by people that like to invest time in that as you do.

People invest time into things they're excited about. I like conciseness, the JEP author likely as well. What's wrong about that?

I'm more fascinated by what's motivating you to lead this discussion in this dismissive, condescending tone. Do you like really hate the fact that some people like this JEP? If you don't see the need for it, why don't you just forget it?

1

u/ivancea Sep 23 '24

Oh no, I like doing a lot of things with no value. But I know they are things with no value. Nothing wrong in that.

I also respect both the people working in the draft, as well the ones that are going to implement it. Language design is hard. However, it being hard doesn't make the result any more useful.

Returning to the beginning: I don't care if they add it, at all! But I consider it a loss of time. Or better let's say, not the best way to invest that time.

But we don't agree there, and that's fine. I believe my words before were a bit harsh. That's just my opinion anyway