3 ms·
C# interfaces with methods, properties, and events is just so nice from a readability standpoint. I know we like to pretend that Java now has first-class funct
by debug-desperado 4y ago
C# interfaces with methods, properties, and events is just so nice from a readability standpoint.
I know we like to pretend that Java now has first-class functions since Java 8, but without easier to use functional signatures they're just too much of a chore. Who the heck wants to write a new interface in a separate file to do this.
I'm grateful for the JVM and think it's probably better than the CLR for targeting a high level language (as evidenced by the continued existence of Scala, Kotlin, and Groovy). But Java, even post-Loom and post-Valhalla, will never be the promised land for quick-to-read-and-grok code.
- kaba0 4y agoYou have Function<A,B>, Supplier<A>, and many other predefined functional interface in the standard library.
- debug-desperado 4y agoThat's my point, we don't have much more than that. Even a 2-arg function is missing. You can supplement with something like Vavr or just write your own, but even then it's not pleasant to read "Function3<A, B, C, D>". Typescript, Kotlin, and Scala all do this way better. Here's an example from Kotlin (it's an extension function, but focus on the combiner lambda): fun <T, R> Collection<T>.fold( initial: R, combine: (acc: R, nextElement: T) -> R ): R { .... }
- kaba0 4y agoJust nitpicking, but there is a BiFunction generic class in Java, but I understand your point. Yeah, some syntactic sugar could come in handy, though I don’t think that it would be a real productivity boost, more just an annoyance.