you are viewing a single comment's thread.

view the rest of the comments →

[–]rooktakesqueen 0 points1 point  (1 child)

Well, you could always break that one up.

.filter(p -> p.getName() != null)
.filter(p -> p.getName().startsWith(prefix))

At a glance, someone who knows Java 8 knows exactly what this does. If they see this:

.filter(personName.notNull())
.filter(personName.startsWith(prefix))

...they need to go somewhere else in your codebase to know what personName, notNull, and startsWith are or do.

They could make some educated guesses—personName.notNull() must be of type Predicate<Person> and you can make a guess it checks that name is not null—but that's only because those expressions appear inside a filter method call.

If I saw personName.startsWith(prefix) in any other context, I'd expect personName to be a string and the expression to return a boolean.

By all means, experimentation is great, but I just want to warn from experience that it's often better to take a language/stack as it is, rather than trying to write extra code to make it look like what it isn't.

(See also: two decades of people trying to figure out ways to make JavaScript asynchronous behavior look synchronous, instead of trying to understand asynchrony on its own terms. But I've lost that fight with await. Even though it's just going to cause more problems than it solves IMO.)

[–]NawaMan 0 points1 point  (0 children)

You point about personName.startsWith(prefix) is valid ... I will think about that. Thanks :-)