this post was submitted on 17 Nov 2024
113 points (96.7% liked)
Programmer Humor
32483 readers
447 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
It's just Java
Hence, Clojure. It's not just functions that implement IFn... as the string of "cannot cast to clojure.lang.IFn" errors that I get because I couldn't be bothered to validate my data's shape is eager to inform me.
Yep, some code examples from the official documentation. This:
...is syntactic sugar for this:
...which is syntactic sugar for this:
The
printPersons
function looks like this:Basically, if you accept a parameter that implements an interface with only one method (
CheckPerson
), then your caller can provide you an object like that by using the lambda syntax from the first example.They had to retrofit lambdas into the language, and they sure chose the one hammer that the language has.
Source: https://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html
That's not quite right. In bytecode, lambdas are significantly more efficient than anonymous class instances. So while the lambda implementation is semantically equivalent, characterizing it like you have is reductive and a bit misleading.
Golang also does this, but it's not classes.
How so?
Golang uses modules, not classes. Each of which may have its own main file.