Creating a new thread is equally simple in Java:
var thread = new Thread(() -> {
// Thread code
});
thread.start();
// ...
thread.join();Yes, but it's a good example of how Java is about twice as verbose to do the same work. The Ruby version of that can be written as simply:
Thread.new{ ... thread code ...}.join
The extra verboseness quickly adds up if every statement takes twice as much code.
Re:Ruby 3.4.0
by lucasoshiro on Thursday December 26, 2024 @07:40AM
(#42514842)
Fair. I must admit that I'm not aware of the recent features of Java. Last time I really needed it was the time that we needed to instance an anonymous class for callbacks. I still find the block syntax in Ruby cleaner though.
Kotlin is another language that has this Ruby-style blocks for callbacks.
thread = Thread.new do # thread code end
...
thread.join
In this example we can see that it's not magic, only concise.
I wrote more about it here: https://news.ycombinator.com/item?id=40763640