News for hackers. Stuff that matters.
Re:Fluent: Static Extension Methods for Java by haspok on Monday July 03, 2023 @03:54AM (#36570069)
> No annotations are required.

I appreciate the intent, but man is this like a minefield waiting to be walked over. Anyone who looks at the code will scratch their head and will not understand what is going on. An annotation would perhaps make it clearer.

Also, how about IDE support? I would argue it is at least as important as the feature itself.

Re:Fluent: Static Extension Methods for Java by kitd on Monday July 03, 2023 @04:05AM (#36570141)
I appreciate the intent, but man is this like a minefield waiting to be walked over. Anyone who looks at the code will scratch their head and will not understand what is going on. An annotation would perhaps make it clearer.

That is the generic argument against extension methods wherever they appear. They are very confusing, until you get used to remembering their existence, then you know what to search for.

Also, how about IDE support? I would argue it is at least as important as the feature itself.

This is mentioned in TFA.

Re:Fluent: Static Extension Methods for Java by pdpi on Monday July 03, 2023 @04:47AM (#36570400)
Extension methods in a language that explicitly supports them and with good IDE support are perfectly fine. I love them in Kotlin. Extension methods as a compiler plugin that rewrites the AST... not so great. Great IDE support is a large part of what makes Java worth using, the last thing I need is to break that.
Re:Fluent: Static Extension Methods for Java by rogerkeays on Monday July 03, 2023 @04:04AM (#36570129)
Yes, IDE support would help developers find the method that is being called. This is already quite a problem given we have complex class hierarchies and interfaces with default methods. I'm not sure I see the need for an annotation though.
Re:Fluent: Static Extension Methods for Java by haspok on Monday July 03, 2023 @05:17AM (#36570600)
A compile-time annotation could at least control whether your plugin is allowed to transform the ADT in the given context (say: for a class). Otherwise is it not possible that it transforms the ADT even when the user did not intend to? Can this be a source of mysterious bugs?
Re:Fluent: Static Extension Methods for Java by rogerkeays on Monday July 03, 2023 @05:36AM (#36570718)
The syntax tree is only transformed when instance method lookup fails. i.e. when your code doesn't compile in standard java form. You would be doing pretty well to accidentally call an extension method seeing as you either have to write them or import them.
Re:Fluent: Static Extension Methods for Java by Etheryte on Monday July 03, 2023 @07:30AM (#36571464)
This whole what-if scenario is a complete non-issue. Many other languages do this out of the box and have no issues with it.
Re:Fluent: Static Extension Methods for Java by tsimionescu on Monday July 03, 2023 @08:22AM (#36571895)
The key point is that they do it out of the box, so everyone is aware of it. As it is, it could easily interfere with some other non-standard extension plugin, for example.
Re:Fluent: Static Extension Methods for Java by Etheryte on Monday July 03, 2023 @10:31AM (#36573449)
Literally any code you write could interfere with some non-standard extension plugin, this is all pointless hot air.
Re:Fluent: Static Extension Methods for Java by tsimionescu on Monday July 03, 2023 @02:12PM (#36576766)
Which is one of the reasons not many use non-standard extension plug-ins for their compilers.
Re:Fluent: Static Extension Methods for Java by hardware2win on Monday July 03, 2023 @04:45AM (#36570384)
In C# world they somehow manage to do it without all of this annotation oriented programming
Re:Fluent: Static Extension Methods for Java by stanac on Monday July 03, 2023 @05:09AM (#36570538)
Not really. First argument (the object you are extending) needs to be marked with `this`, which is an annotation.
Re:Fluent: Static Extension Methods for Java by hardware2win on Monday July 03, 2023 @05:26AM (#36570649)
Ehh, ive been talking about whole lang and ecosystem

But I agree about "this" being similar concept

Re:Fluent: Static Extension Methods for Java by whizzter on Monday July 03, 2023 @06:23AM (#36571015)
There are tons of annotations over the hood.

The "this" that GP mentions is for for extension methods similar to the article to be regcognizeed as such (never done if the annotation isn't present), they're written such as:

static int Foo( this Bar bar, int biz) => bar.xyz+biz;

Bar bar = new Bar() { xyz=123; };

int result = bar.Foo(456); // Works even if Foo wasn't a part of Bar initially

Elsewhere annotations(called attributes in C# land) can often be used in the same way as in Java to document serialization behaviour,etc. So in practice there aren't much differences apart from how library authors haven't embraced it entirely as much for automagic bindings (partly due to philosophy, partly due to other facilities being more appropriate).

Re:Fluent: Static Extension Methods for Java by dtech on Monday July 03, 2023 @06:59AM (#36571229)
There is a massive difference between a feature universally offered by the language and something only supported by using a specific library of compiler plugin...
Re:Fluent: Static Extension Methods for Java by dtech on Monday July 03, 2023 @06:47AM (#36571157)
What a weird take. Parent obviously meant @X meta-programming annotations, not language syntax and keywords with a specific definition.

The definition that includes it is so broad that it loses all meaning, it would make "private", "class" or "boolean" also annotations.

Re:Fluent: Static Extension Methods for Java by depoll on Monday July 03, 2023 @10:40AM (#36573568)
In .net world, the C# "this" syntax is itself just syntactic sugar over an annotation (attribute in .net parlance): https://learn.microsoft.com/en-us/dotnet/api/system.runtime....
Re:Fluent: Static Extension Methods for Java by nh23423fefe on Monday July 03, 2023 @12:14PM (#36575055)
offtopic: why is this link a broken redirect in chrome but not firefox?
Re:Fluent: Static Extension Methods for Java by ElectricalUnion on Monday July 03, 2023 @12:47PM (#36575523)
My guess is that MSDN POs prioritize testing with Blink/Edge WebView2 over other engines.
Re:Fluent: Static Extension Methods for Java by rogerkeays on Monday July 03, 2023 @04:52AM (#36570427)
Just to make it clear, Fluent does not use any annotations.
Re:Fluent: Static Extension Methods for Java by michaelcampbell on Monday July 03, 2023 @10:27AM (#36573385)
Isn't this just saying some languages do things others do not?
Re:Fluent: Static Extension Methods for Java by hardware2win on Monday July 03, 2023 @10:57AM (#36573829)
No, annotations are available in both, yet one community uses them more often
Re:Fluent: Static Extension Methods for Java by michaelcampbell on Wednesday July 05, 2023 @01:27PM (#36603740)
So, "some languages do this with annotations, others don't need it". My point stands.

I mean it's fine to not like annotations or the decision to use them, but that another language does things differently is almost a tautology and hardly worthy of note. IMO, reasonable people will disagree.

Re:Fluent: Static Extension Methods for Java by skybrian on Monday July 03, 2023 @12:09PM (#36574972)
Yes, it’s a slightly different language and should have a different extension, like js versus jsx.
Re:Fluent: Static Extension Methods for Java by erik_seaberg on Monday July 03, 2023 @04:33PM (#36578393)
Some languages allow declaring things like this per file

  "use strict";

  from __future__ import annotations

  {-# LANGUAGE TemplateHaskell #-}
which probably scales better than 2^n filename patterns.
Re:Fluent: Static Extension Methods for Java by skybrian on Monday July 03, 2023 @04:54PM (#36578678)
Official upgrades to languages don't result in that kind of combinational explosion of language extension combinations because the features eventually become standard. They do result in a combinational explosion of language feature combinations, though, so there's still a problem with languages just getting big. IDE's and other language tools need to support it too.

In JavaScript there is .js, .ts, .jsx, and .tsx. I hope that doesn't become a lot more, but for low amounts of variation, it's reasonable.

I think Haskell is a good example of what happens when a language supports too many extensions. Why are there so many? How do people deal with them all? Needing to pick another file extension seems like pressure to do this more sparingly?

Re:Fluent: Static Extension Methods for Java by _a_a_a_ on Monday July 03, 2023 @01:15PM (#36576000)
> is this like a minefield waiting to be walked over

"This looks odd to me so no one else can possibly understand it"is not a rigorous argument.

Both Scala and C# have this. I've used it in my own code to clean things up. It's fine.