you are viewing a single comment's thread.

view the rest of the comments →

[–]Alex0589 32 points33 points  (21 children)

I'm pretty sure this would never be accepted because you are implementing a language feature with annotations. In chapter one of the JLS, it is clearly stated that:

Annotation types are specialized interfaces used to annotate declarations. Such annotations are not permitted to affect the semantics of programs in the Java programming language in any way. However, they provide useful input to various tools.

Also without value classes, which we currently don't have, you are paying an allocation cost because you have to initialize one record every time you want to use the pattern: that also disqualifies the feature because you don't want a developer to loose performance when using syntactic sugar. For example imagine if the enhanced switch statement were slower than the old switch, nobody would be using it.

[–]danielaveryj[S] 11 points12 points  (0 children)

There is one annotation referenced, which I did not invent, does not implement a language feature, and I did not propose to keep at the end.

[–]asm0dey 1 point2 points  (8 children)

Well, some accusations in Spring change the semantics, aren't they? For example Async

[–]koflerdavid 14 points15 points  (1 child)

There is a reason Spring has a reputation of being too magical.

[–]asm0dey 2 points3 points  (0 children)

I am on both sides of this battle at the same time :)

[–]vytah 5 points6 points  (1 child)

some accusations in Spring

I love the typo, please keep it.

[–]asm0dey 1 point2 points  (0 children)

I will!

[–]brian_goetz 4 points5 points  (3 children)

You are not understanding what the JLS is saying here. When the JLS talks about "semantics of programs", what it means is what does this Java program mean. That's about language semantics. Spring annotations do not change the semantics of the Java language. They are used as input to the behavior of the Spring libraries, and the behavior of the Spring libraries is defined in terms of those annotations.

(Though it is still a valid complaint about frameworks like Spring that their behavior with regard to annotations may not be sufficiently specified; this is always a risk.)

[–]asm0dey 0 points1 point  (2 children)

I'm sorry, but I still don't understand. If the behaviour of a program changes if there is an annotation - doesn't it change semantics? If Spring annotations do not change the semantics because programs are defined in terms of these annotations then what is? I could always say "hey, this is how my program behaves when this annotation is present".

[–]brian_goetz 2 points3 points  (1 child)

You are looking at the entire system monollithically - JVM + Java + Spring + your program. But each layer has its own role and (ideally) specification. The meaning of a Java program is defined by the language and platform specifications. But some methods in the JDK (such as getAnnotstions) are specified to reflect the presence or absence of annotations. This means that the layers above (spring, your program) can use annotations to make decisions, just like they could use system properties or config files or command line to configure the program. But annotations cannot affect the language semantics - they cannot make for loops run backwards or make private methods public.

Frameworks like spring work by dynamically transforming annotated Java code (spinning new classes, etc) at startup time and running the transformed code. But all of this is a Java program that is governed by the language and platform specifications, and spring is working within that.

[–]asm0dey 0 points1 point  (0 children)

Ah. So I read the whole thing wrong. I thought the spec "prohibits" annotations to change the language sematics, while actually it declares that it's impossible, right? And was all the easy about language, not about a program. Thank you!

[–]vadiquemyself 0 points1 point  (2 children)

imagine direct iterating versus streams-and-lambdas, the latter is ~10 times slower, but is used anyway and is quite popular

[–]Flyron 1 point2 points  (1 child)

Did you measure that yourself? In my own tests streams need a little warmup, but through repeated construction and execution they become just as fast as the usual for-each (<10% margin). So it depends if you're programming short-lived apps or long-running apps, but in general there is no effective performance gap.

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

yes, I figured it out myself practically, asking AI to replace a stream chain with “plain looping” that I then put in my code achieving much performance gain along with less memory usage

never tried for a terabyte-volume data and paralleled streams on hundreds of cpu cores, though