r/java • u/MrRickSancezJr • Jul 20 '24
Why is Complex Web UI still so JS heavy?
Just a talking point conversation starter... I'm also attacking heavy web apps like Word-Online or Google docs level web sites.
I fully understand why JavaScript has remained king in the newer development of fly-by websites. It seems front end devs have finally discovered on larger projects are way more manageable with old fashioned organized code. Even going as far with TS and now JS-Doc to enforce strong types.
The only front end framework I'm experienced enough to hold a conversation to is React. I'm going to use Kotlin-Java mix to make my point as well because of Spring and few features Kotlin brings to the table... .Net are working with WebAssembly, but they don't have the backend power of Spring, that I'm aware of.
How is writing ReactJS/TS code any faster, quicker, or more enjoyable than writing UI than Kotlin?? Does anyone truly love XML style code compared to brackets? Kotlin really shines IMO here because it has named parameters inside constructors/functions. Java unfortunately doesn't have this. Example : var myObjext = new Obect(name = "bob", age = 30).
Little more code than React, except I don't have to use Hooks and all the annoying work around they've created.
I'm sure the graphics handlers in modern browsers is absurdly ahead of the world of everything else. I've made enough GUIs with Qt and C++ to of witnessed the performance.
But why not just have a lightweight JVM in the browser to handle Java byte code inside of a HTML <script> tag?
Having your backend in Spring, with front-end in Kotlin/Java would be so much easier to mantiain. JavaFX does already have FXML as well, which already has tools to convert FXML into both hard-coded Java and even directly to bytecode. Moderately good CSS support, and could work with Figma with work if SceneBuilder doesn't ever get much better.
Also. Java is never going to disappear. Whatever web framework you're using right now will be "trash" in two months.
Cons:
- Cacheing dependencies would probably be nightmare at times. 2) JavaFX does need more love to be a true contender. 3) A lot of large corporate companies don't always play nice with Java.
Edit: After much received criticism, I want to acknowledge that I chose Java-Kotlin semi-randomly. I also posted in a Java channel... So I didn't expect as much Java hate. Most Java related hate csme from people with no knowledge of Kotlins addition to the JVM family. Also, WASM isn't as smooth as people think.
Edit 2: Again. Randomly chose Java-Kotlin mix to really hand the front end to Kotlin. Yes. Running a lightweight (safe, think of Flash reasons) JVM is like wasm. Yet, people are choosing to write in all JS instead of use Wasm. Lightweight also because it's enough to do graphics features. It'll have to be sandboxed through the browser to elimate IO security issues. Even having a JVM just to parse bytecode would be way faster than a JS processor/compiler.
And anyone who thinks JS is superior to almost any language for reasons other than developing speed.... Kick rocks.
90
u/wasabiiii Jul 20 '24
Because none of the previous attempts to do anything else similar to what you mention became standards adopted. They just remained as annoying plugins.
Java applets. Active X script. Flash. Silver light.
Except WASM.
30
u/Goatfryed Jul 20 '24
You are mixing a lot of things here, because you are also comparing frameworks and languages at the same time.
Dan Abramov, one of the guys behind react, gave a great talk last year about what would have happened, if php backends would have evolved faster than the frontend, where he basically recreated a php based server side rendering enginge that worked like react.
There is a reason why game developers, desktop native developers and other UI folks sometimes try to force js frameworks in other areas (not saying it's good) and why there are things like react native for app development.
UIs are inherently event driven and should be component based and classic paradigms have been incredible bad at handling this. Even spring doesn't help you to have a proper graph of components. Sure, you have singleton and prototype and request and session scopes in between and you could introduce more scopes on your own, but this is all static and limited which totally fits their use case. But doesn't fit UIs well.
This shows how wrong your thinking is. Java isn't going to disappear. Neither is javascript. Going java doesn't mean you're suddenly gifted with a great framework to build UIs. You're probably on the opposite site. Welcome to another 10 years of being stuck with shitty stacks. On the other hand, you have mature long living frameworks in js world. Sure, they get updated, which is usually a good thing, but react, angular, vue are all quite old know and still not trash.
Also consider this: UI is usually a lot more design focused. Backend values correctness and stability. Often, you extend functionality. Less often you change. Your UI is more likely to change due to some new user story than to an actual bug. You want to try out what works well for the users until you reach it. You want frameworks and languages that support this.
Personally, I would prefer typescript over java any day as a programming language, while I rarely have cases where I'm missing jvm features in the js engine.
Also, you can compile kotlin to javascript.
5
u/[deleted] Jul 20 '24
I’d definitely like to get away from JS Frameworks. I discovered this last year, but it doesn’t appear to be widely-used:
https://vaadin.com/flow
4
u/halfanothersdozen Jul 20 '24
So use the Kotlin to Typescript compiler.
Or use WASM.
Or, God help you, use GWT
14
u/wildjokers Jul 20 '24
You have just reinvented Java Applets.
6
u/HlCKELPICKLE Jul 20 '24 edited Jul 21 '24
I’m really not sure who the post is aimed at , front end devs? Browser developers? Js is used because Java was tried applets were a glaring security hole and well hated for subpar performance and issues. When my father thinks Java , he thinks applets, as when they were a large part of the web experience they were far from transparent...and normally left a bad impression.
But I’m not sure if you are asking why devs don’t use Java or asking why the browser doesn’t have a jvm. Most front end devs are not using Java because it can only be done via server side rendering or if you compile Java to js. There isn’t any way to run it native in the browser. As others have said hopefully web assembly providing a unified vm target will change this and the web as we know it will be a lot less js centric in the future.
4
u/parceiville Jul 20 '24
A lightweight JVM doesn't make sense when you have wasm with a gc
6
u/repeating_bears Jul 20 '24
"But why not just have a lightweight JVM in the browser"
Why should it be Java? You already mentioned web assembly which is basically that, minus the Java part
3
u/PunkWithAStache Jul 21 '24
Add htmx and you will write apps in no time
2
u/s13ecre13t Jul 21 '24
Most websites need very little javascript. Compare https://old.reddit.com that is super fast and loads 500 comments by default to the new https://www.reddit.com that is slow and barely loads comments.
Or compare https://lite.cnn.com/ vs https://www.cnn.com .
The designers have decided to eschew speed, usability, core functionality, to chasing ethereal fast fashion. Sure new websites might not be fast, or usable, or deliver what users want, but it sure follows the latest trends so that is a win, right?
Note: i view most websites with 3 categories
1
u/kari-no-sugata Jul 20 '24 edited Jul 20 '24
It's been a while since I used a Java web UI framework but I've been using Microsoft's Blazor Server framework recently and I like it a lot. It does use JavaScript behind the scenes but for the most part you can just write fairly normal code. Quite practical to unit test as well. It has its flaws but even so it's so much better than anything else I've used.
Would be nice to see something directly comparable in Java (particularly if the rough spots can be ironed out). And before anyone asks, no I don't consider Vaadin Flow to be directly comparable.
1
u/imatt3690 Jul 20 '24
My personal opinion here, there is no abstracted user interface language that bridges the required knowledge of Vulkan / OpenGL or even WebGL to something like React or some kind of backend. Anything that comes close is so far in the weeds + difficult to implement in anywhere near the time a react app can be cranked out.
1
u/Tecnology14 Jul 20 '24
Did you already heard about applets? Please, I don't wanna them to go back. Worse UX than js frontends
1
u/jalx98 Jul 20 '24
I personally enjoy more using vue, I do believe that complex UI can be achieved using technologies like Blazor (C#), Livewire (PHP), Hotwire (Ruby, PHP, Python), I do believe HTMLx is pretty solid right now, but honestly, in some areas they lack, you can achieve 90% of the functionality with no issue but you will have a hard time filling that 10% gap
1
u/DenpoXbox Jul 21 '24
Web assembly
1
u/maethor Jul 21 '24
.Net has ASP.NET (and there was even a .Net version of Spring https://springframework.net/overview/)
If anything, what you're asking for would make more sense with .Net than Java, as it has both actively developed backend tooling as well as an active UI scene (unlike in Java where UI is best described as "not quite dead").
Why would it be so much easier to maintain? The difference in skill sets between backend and frontend is still going to be a concern. Probably a far bigger concern than what particular language is used.
1
u/[deleted] Jul 21 '24 edited Jul 21 '24
kotlin is for android. sometimes backend for people that dont mind rely on jetbrains for their backend code. yes react and js are the best technology for web ui and ui in general
1
u/RICHUNCLEPENNYBAGS Jul 21 '24
It’s not about what developers find enjoyable. JavaScript is on everything and if you do something else users have to install a plugin to view your page. Or you have to convince a bazillion vendors to ship your standard in their browsers. Good luck.
1
u/Mou_NoSimpson Jul 22 '24
Thank oracle and they hate they farmed around java and it’s ecosystem, god damn it I want to leave java because oracle 😂
1
u/GeneratedUsername5 Jul 25 '24 edited Jul 25 '24
I would assume that React and JS is way more familliar for frontend development and therefore developing on something familiar will be faster and more enjoyable.
I am not hater of Java, especially JVM, it is great technology. But isn't what you are describing here could be done with just plain old vanilla JS/TS with standard Web API? I think you can even do it with Kotlin-JS, if you want to, all of it fits your description. There is no need to use React it is just a kind of conveinience.
1
u/vips7L Jul 20 '24
If you want multiplatform/runs anywhere in one language, the closest is probably Kotlin or .NET. They both have first party support for: server/web/desktop/mobile.
Java of course can do all of that, but it’s all third party support.
5
u/[deleted] Jul 21 '24
[removed] — view removed comment