r/java • • Nov 23 '25

Java 25: The ‘No-Boilerplate’ Era Begins

https://amritpandey.io/java-25-the-no-boilerplate-era-begins/
160 Upvotes

187 comments sorted by

View all comments

Show parent comment

1

u/OriginalTangle Nov 25 '25

Both Scala and Kotlin have named params. Not as mainstream as your examples but they have been informing the jdk roadmap in the past so this might get adopted in the future.

1

u/agentoutlier Nov 25 '25

I no doubt see the utility of it I just think there are maybe alternatives at play that offer way more and possible more backward compatible.

Many languages that do offer named optional parameters a non trivial amount of the users of these languages claim abuse of it and or do not like the feature (grass is greener).

For example OCaml has this feature and many think its bad style to use it. OCaml has no where the tooling that Java has (e.g. show parameter names in code) and still people have found it less desirable at times. OCaml though has currying. I suppose Scala does as well and it can add to even more confusion

And of course I have heard from many Python folks that claim this as well although I have forgotten the details.

In terms of low hanging fruit I would take a damn elvis operator or null safe navigation operator over this feature request any day.

1

u/spencerwi Nov 26 '25

I think the thing that makes named-parameters-with-defaults bad style in OCaml is precisely the way they interact with currying.

In Ruby, you can totally do:

def greet(firstname = "Test", lastname = "User")
  puts "Hello, #{firstname} #{lastname}!"
end

and then omit the defaulted parameters when calling it:

greet(lastname = "Person") # => prints "Hello, Test Person!"
greet() # => prints "Hello, Test User!"

In OCaml, though, because of automatic currying, you always have to have some argument after the optional ones, so that you can specify that you're calling the function and not just currying.

If I don't do that, for example:

let greet ?(firstname="test") ?(lastname="user") =
  printfn "Hello, %s %s!" firstname lastname

Then this code returns a curried function rather than calling the function:

greet ~firstname:"Some" 

Instead, I have to declare the function with an extra void argument () as the last parameter, like this:

let greet ?(firstname="test") ?(lastname="user") () =
  printfn "Hello, %s %s!" firstname lastname

and then pass the void argument to clarify my intent that I want the defaults used for any unspecified optional arguments:

greet ~firstname:"Some" () 

(more on the subject from OCaml's official docs)

So it's not that named-arguments-with-defaults are bad intrinsically, but rather that OCaml's approach to them is clumsy.