Extension methods

ІП-24 Олександр Ротань rotan.olexandr at gmail.com
Tue Apr 23 16:53:03 UTC 2024


Any opinions are most welcome, so don't resist making a remark if you have
something to say.

I personally made my point about this readability issue in my second mail,
and I don't mind to repeat that code should speak for itself with words,
not places of definitions. There are only two possibilities: you either
read code and understand what it does just by what is written, or you hover
over the code and IDE does the trick for you. That's why I honestly don't
consider readability as issue. Also, I wouldn't say nested utility method
invocations are more readable then extensions, especially with fluent
interfaces like builders or streams, when you essentially have to read
backwards in processing chain, so in my opinion, extensions on the contrary
enhance readability. Noone ever will suffer instead of Arrays.sort(arr) one
will see arr.sort(). In fact, second looks better, isn't it? So, in my
opinion, in most cases extensions enhance readability. And for the record:
I also agree that readability is significantly more important.

Offtop about checked exceptions: I guess the biggest deal with them is in
lambdas, so maybe they can be ignore in lambdas at least? Haven't really
studied this subject, just something from the top of my head

On Tue, Apr 23, 2024, 19:43 Archie Cobbs <archie.cobbs at gmail.com> wrote:

> I can no longer resist jumping in with an opinion... :)
>
> From [compiler-dev]:
> On Tue, Apr 23, 2024 at 10:36 AM Ethan McCue <ethan at mccue.dev> wrote:
>
>> What's going to suck to hear, but I think that you'll come around
>> eventually, is that extension methods do not improve code readability. They
>> make it harder to read o.method() since it would be ambiguous whether
>> .method is an instance method or an extension method.*
>>
>> They *do* make it easier to write programs though. Without them you do
>> have to write more characters and you do sometimes have to break up method
>> chains.
>>
>> Historically, given a choice between code readability and code
>> writability/terseness, Java has erred towards the first.
>>
>
> IMHO this is the heart of the problem. Personally I'm a fanatic about this
> - readability is 100x more important than writability if you're writing
> code which is going to be used & maintained for a long time (think
> enterprise, i.e., Java's sweet spot).
>
> FWIW here's my previous rant on this topic
> https://mail.openjdk.org/pipermail/amber-dev/2022-November/007580.html
> (that was in a discussion about making all exceptions unchecked...)
>
> -Archie
>
> --
> Archie L. Cobbs
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20240423/d729fffb/attachment-0001.htm>


More information about the amber-dev mailing list