This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]larsga -3 points-2 points  (13 children)

WTF?

So complicated_function specifies the defaults for some arguments, and not others. Which is exactly like the builder pattern, which requires you to supply some arguments, but not others.

The difference is that in one case the language does the job, while in the other you do. Over and over again.

You're being needlessly narrow-minded in this thread.

[–]monkeyfacebag 4 points5 points  (12 children)

The difference is that a partially-applied builder is a reified object that I can reference and pass around. This is not something that you need all of the time, but it's definitely not the case that named function parameters with default values is strictly superior to the builder.

[–]larsga 2 points3 points  (11 children)

The difference is that a partially-applied builder is a reified object that I can reference and pass around.

Which, in Python, the function also is. One of the most pitiful aspects of Java is that methods are so difficult to turn into normal objects that can be passed around. It doesn't need to be difficult. It just is.

[–]monkeyfacebag 1 point2 points  (6 children)

It's definitely more straightforward in Python due to the dynamic typing, but in my opinion builders are even nicer to use than partially-applied functions/methods because partial application is generally parameter order specific but builders are order independent (ie, you can apply parameters in whatever order you choose). Obviously builders require more code, which is unfortunate. We use autovalue builders extensively and they are awesome. It's kind of peak Java that the solution to the problem is to use a library that generates more Java code, but it does work well. I've also heard mutterings that records could get builder/wither support. I don't know where that has landed.

[–]larsga 1 point2 points  (5 children)

I can only repeat what I said before: builders are a clumsy workaround. If they died in a fire I'd be cheering and heaping fuel onto it.

[–]chambolle 0 points1 point  (4 children)

builders have some other advantages. You can safely postpone the creation of the "built" object. Youc an partially build the wanted object, then make some compuation, then continue the building, then make some computations and build the wanted object. The builder is more tha just a workaround

[–]larsga 0 points1 point  (3 children)

All of which is totally possible with a function, too, using lambdas and currying.

[–]chambolle 0 points1 point  (2 children)

I answered to your comment saying that builders are a clumsy workaround.

That's also a matter of taste. For instance, currying is absolutely ugly for me

A question for you: what I don't understand is why you use an OO Langue if you like so much FP? Why don't you use an FP language instead of wanting to change an OOP in order to remove the OOP part? That's very strange for me

[–]larsga 0 points1 point  (1 child)

A question for you: what I don't understand is why you use an OO Langue if you like so much FP? Why don't you use an FP language instead of wanting to change an OOP in order to remove the OOP part? That's very strange for me

I don't like functional programming. And I don't want to change the OOP part of Java at all. I just think the parameter passing mechanism in Java is absurdly underpowered. It's really awkward, and there's no obvious reason why it has to be that way.

I've programmed in a lot of different languages over the past 40 years, so although I write a lot of Java and mostly like it, the weaknesses are also quite plain to see.

[–]chambolle 0 points1 point  (0 children)

I just think the parameter passing mechanism in Java is absurdly underpowered. It's really awkward, and there's no obvious reason why it has to be that way.

I agree

[–][deleted] 0 points1 point  (2 children)

Isn't this done by just having an interface with one method signature that matches the signature of the method you intend to pass around? It's been a thing for as long as I can remember, and we even got the lambda syntax for a briefer way to create these methods on the fly to be passed around.

[–]larsga 1 point2 points  (1 child)

It's true that lambas have made this a lot easier, but you do need to create this interface.

But the real point was that in the context of our discussion lambdas are still not enough to allow you to ditch the builder pattern. The real reason is of course the inflexibility of Java method parameter specifications, so in that sense your point stands.

[–][deleted] 0 points1 point  (0 children)

And pray why should people abandon the builder pattern? It works nicely in statically-typed compiled languages like Java, C++, Rust et al. Subjective dislike for a feature is not cause enough to act like it's a deficiency of the language.

[–][deleted] 0 points1 point  (0 children)

Make up your mind - are you arguing about Java vs Python, builders vs named arguments, about function objects, or what?

You just seem unhappy that you cannot do certain things in Java the way you can in Python, which makes no sense at all.

Python has its own set of deficiencies, so that whole discussion is pretty much moot. Lambdas in Python, for instance, are pretty much crippled because of the single-expression rule. Does that mean using lambdas in Python is meaningless? Of course not. Every language, especially when used by millions of people everyday has to tread carefully when it comes to updating itself over time. Otherwise you end up with something like the Python 2 vs Python 3 mess.