React vs Java
Comparing React and Java would have been as silly as comparing fiction to sculptures a few years ago, but ever since JavaScript went all "shots fired" against Java with React Native, the comparison is actually relevant.
I work as a Software Engineer. I currently have 2 main projects to work on each day. One is a Java application that uses the Spring framework and Elasticsearch and so on, and the other is a reimagining of our main dashboard written in full stack JavaScript with React as the frontend.
The two projects have nothing in common. When I work on one, I'm using Java. When I work on the other, it's all React. It's hard to directly compare the two, since productivity measures in the Java application are very different from the React app. In Java, a "success" can be anything from creating a new API that reads from a database, fixing an API to properly update the data, or modifying a certain procedure to do some extra thing. In React, a "success" is usually just building the UI, and using various tools to read data from the backend, and making sure everything updates correctly. 4 hours in Java is not the same as 4 hours in React.
What is really being compared
Single-threaded vs Multithreaded
When working in React or on any JavaScript project, I don't really need to multithread, but I always hate that I can't. It's just that feeling of not having an extra car, or grabbing extra napkins just to throw them away later. Maybe it's like hoarding. I don't know, but I always feel so weak knowing I can start a new thread on my own.
Compiled vs Interpreted
This usually only matters when there is a syntax error and I'm wondering why nothing works even though I swore it would work this time. I examine the block of code I was editing and scratch my head. An hour later I realize I had accidentally saved the file after typing "f" on some random line 200 lines above where I was working. Typing "me" usually follows.
That sort of thing never happens in Java, though to be honest sometimes to a fault. What if I just want to quickly debug something? Do I really have to return an empty String or new Array<String>() just to print some feedback?
Loosely-typed vs strongly typed
I prefer Java on this one. It's really nice to know what something will be when you try to use it.
Rule: A Strength in Java is a Weakness in React, and Vice Versa
After I get into the groove with React, I start to appreciate how quickly I can get a lot of data moving from the frontend to the backend. I can set up a form quickly and send it to the backend without feeling like that's what I'm doing. I can do a fetch when the component mounts to feed it the data it needs to display a list. Really, React does a great thing by managing the data in the frontend and making sure it connects to the components. The only catch is that you have to use the React framework and coding patterns.
Doing anything in Java requires much more code and much more thinking about Object Oriented Programming. In a way, OOP is the framework. Working in Java means becoming familiar what "what you can do with a String", or "what can I do with a HashMap?" Today, I asked why HashMap wasn't preserving the order of insertion, and so I changed it to a LinkedHashMap. In Java you have to write code to send a GET request. In any JavaScript framework, the code is so simple you don't write it, you just send it. Compare $.ajax({ options}).then((results)=>{}) to HttpGet request = new HttpGet(), followed by 4 more lines before anything can happen.
Parting Shots:
- A small project is easy in React, but React can actually be overkill if it's a very small project.
- React is best with medium-sized projects.
- A large project is still very difficult to manage with React.
- Java makes small projects, medium projects, and large projects feel like medium projects. There is no middle ground, or rather, there is only middle ground.
- All of the improvements to JavaScript over the years serve to make the language more like Java.
Comments:
Leave a Comment
Submit