4 ms·
You know, to be honest with you, i feel like both are pretty verbose. Admittedly, with modern Java, you can slightly shorten the code there, it becomes the foll
by KronisLV 5y ago
You know, to be honest with you, i feel like both are pretty verbose. Admittedly, with modern Java, you can slightly shorten the code there, it becomes the following:
package dev.kronis.jfxdemo;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class HelloApplication extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
var btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(event -> System.out.println("Hello World!"));
var root = new StackPane();
root.getChildren().add(btn);
primaryStage.setScene(new Scene(root, 300, 250));
primaryStage.show();
}
}
That's now 26 lines and 765 characters.
Well, more like 18 lines of actual code, since imports will almost never be written manually and my IDE collapses them by default, and 505 characters.
For comparison, the code for Qt is 16 lines and 335 characters.
To me, those differences are not significant enough for them to matter all that much.
As for the whole TriFunction thing, i feel like most modern languages are bad in regards to handling functions and their parameters as well as their return values. The thing that i've found most annoying is having container/wrapper objects for function returns when you need to return more than one thing from a function, or alternatively have to pass in a mutable container object of sorts which muddies things (much like how on the DBMS side you have OUT parameters). In contrast, just look at how Go does things, you can return multiple values from any function!
Here's hoping that Java and other languages keep improving in the future and we get more tasteful syntactic sugar to cut out the unimportant and menial boilerplate code. In the mean time, Kotlin is also decent, look at the following function syntax wise:
override fun start(primaryStage: Stage) {
primaryStage.title = "Hello World!"
val btn = Button()
btn.text = "Say 'Hello World'"
btn.onAction = EventHandler { println("Hello World!") }
val root = StackPane()
root.children.add(btn)
primaryStage.scene = Scene(root, 300.0, 250.0)
primaryStage.show()
}
(purposefully excluded the @JvmStatic companion object here, since didn't bother much with the Java to Kotlin conversion, though IntelliJ IDEA is pretty good for that)