Java, when to love it & when to not
My experiences of trying Java out professionally and personally and why I stopped doing my side projects in it.
My experience with Java began much before I even knew I was going to code for a living, or even knew I would have to make a living. I was in the 8th grade, all of 13 years of age, and was suddenly learning about OOP fundamentals, questioning myself on why we even needed any of the 4 pillars of OOP to check whether a string was palindrome. Spoiler alert: It took me 11 years to find out.
It didn't take long after 8th grade for me to realize that I would have to make a living, and it didn't take me much time after that to figure out that writing code was probably the best way for me to do so. In college, I started writing awful C & C++ code to take part in competitive programming contests and, on the side, learnt some Python to write some more god-awful code to make small automation scripts.
The Python I learnt landed me a job writing Python at a huge corporation, where I got no work. I switched jobs to land at a reasonably huge startup, and all the codebase there was in Python. We wrote a lot of code there, but I never found OOP to be the norm. We were solving problems and writing code (reasonably okay code) to solve those problems, also with a lot of tests. Anything pushed had to be covered with tests as Python, being Python, and us being us, the code we wrote had the penchant of coming up with the nastiest or not-so-nasty but harmful bugs at any time. Not that we couldn't have used type checkers, data validation, etc., to help us, but we didn't, and I didn't know any better. I should have maybe, but with everything going on around me, my focus was on keeping up. Soon, however, I was about to find out.
I then landed at my current job at an early-stage (read: small) startup, where, to my surprise, most of the codebase was in Java, with only one minor service written in Python. I felt like a fresher again, and I started with small tasks in the codebase and started wrestling with the Java behemoth. I wrote god-awful Java code (it's becoming a pattern now) to push my first feature while being annoyed at Java for being such a hardass. Come on, dude, I had to write a class for everything? Why couldn't I use a dictionary everywhere like I used to? I had to use a mapper and deserialize JSON to an object? I couldn't just "+" things anymore? Beans? CDI? What was going on? I longed to go back to Python.
With time, I noticed something though: the code I was pushing out was far more stable, last-minute changes took a lot less time, and I was more confident with them. I saw design patterns emerging as I wrote code. I also felt I understood programming a lot better, and when I wrote some Python code again, I wrote better Python too!
What was happening? Had Java given me superpowers? Was my secret knowledge awakened by using Java? The answer, as we all know, is no. All Java was doing was forcing me to use the paradigms it had. Remember the 4 pillars of OOP? I had finally figured out why you needed them after 11 years! With every class I wrote, every time I used an interface, each time I created a custom exception, or even every time I created a class for a JSON payload I was about to receive, I was being forced to be more careful. I was being forced to decouple my code, I was being forced to think deeper about the code flows, I was thinking of the reusability of my code, and so on. With the type system also at my back and most errors being caught at compile time instead of runtime, I was realizing why type checking is important, why data validation is important. By this time, I was loving Java; I was becoming a more skilled programmer every day.
Though soon, the devil took over my brain, and I thought, "Why shouldn't I use Java for my side projects too? They will be so much better with Java," I thought, or as the devil made me think. In this hubris of mine, I started writing Splithook in Java, and as you will see if you opened the link, it is still WIP. I never could finish it.
Java made my life so much easier at work, but it was the opposite while doing a side project. I wanted my ideas to be real as soon as they could be, and writing 10 models, defining different service classes, and figuring out JSON objects was not the best way to make it so. I was getting bored pretty soon as the setup wore off the excitement I had when I started off. Soon the devil got off my shoulder, and I started using Python for my side projects again. I was able to finally get Splithook completed and also another fun little idea, wiki-anything. I was faster, and I could see my ideas being real quicker. It did not make me much more skilled, but it was more fun, so much more fun.
As aptly said,
I think you guys should stop learning languages and start learning programming already. - @Tsoding
Neither did Java make me a smarter programmer nor did Python make me a faster one; they both together made me a better one. None, I found out, was objectively better, but you had to fit the tool to the job. For me now, if I need something reliable when mistakes could cost a lot, I'd use Java. If I need something with a more conducive flow and mistakes aren't as deadly? I will use Python any day.
Add me on X: @iwtrttwoli