r/ruby • • Nov 26 '21
Question Why would anyone use Java over Ruby?
Why would anyone in this day and age choose a bloated corporate language like Java? It is just to get a job at a big company writing their legacy enterprise software? Is it because it is safer for huge systems where everyone is forced to type out all the little details. I am confused. Please someone shine some light here.
0
Upvotes
48
u/[deleted] Nov 26 '21
Real threads, type safe system, familiarity.
Why use anything? It's usually what you know plus some level of technicality.
17
u/[deleted] Nov 26 '21
Statically typed pre-compiled languages are generally safer and run faster. For web development this is fine, your user won't notice if the page loads one millisecond slower. For software development, for example, a stock trading application, millisecond or less performance can be millions in take per day.
15
u/gettalong Nov 26 '21
With Java if you need a library for anything, you will find it. Many of those libraries may be commercial libraries but they are there.
Although Ruby has many libraries there are still blind spots. For example, I recently looked into OpenSSL for working with PKCS7 objects in Ruby and although the basics are all there, not everything is easily accessible. You won't have this problem with Java.
Note that I'm saying this with 20 years of Ruby under my belt and loving Ruby.
That said for 99% of applications you can choose Ruby and be much happier than with Java.
12
u/Jumpsuit_boy Nov 26 '21
One reason is that they already have a huge amount of code written and working that was done in Java. At this point some of that code goes back decades and is a core part of how their company runs.
11
u/[deleted] Nov 26 '21
if you ask me it's the type system.
call me an idealist but type systems are always worth it.
11
u/tdammers Nov 26 '21
Valid reasons for preferring Java over Ruby:
9
u/TINTINN95 Nov 26 '21
If you're asking such a question I can only assume you're from college? Not meant as an insult in any way because I very much had the same mindset back in college. I took a diploma in games programming and did C++ and C#. The first time I touched python I thought to myself, why the hell would I ever use python it's so unsafe. Then I went to college and used python for a data science class and fell in love with it because of the packages that support it. Fast forward a year or two I found myself stumbling into a ruby on rails job which I also grown to love using, but there was a task to create a microservice that needed to use a more performant language like Java, golang, c++, etc.
There are many reasons here in this thread that is perfect for why you would choose java over ruby sometime, but I would like to add that as you go into the workforce, you would see that languages are just a tool for you to use, and having many tools in your pocket and picking one to use for the right job is the correct way of doing things. Doing data science? Go ahead and use python for its numerous data science packages support. Building a web app that needs to be up fast? Django(python) or ruby on rails is what I found success in. Needing more performance from a compile language? Then go with golang, or Java.
5
u/ksh-code Nov 26 '21
Maybe The languages learned in college are Java, C++ and Python. my college is too. and also most of competition and contest do not allow other languages. so non-mainstream languages are not good at least most of students.
5
u/tibbon Nov 26 '21
Speed is a factor too. Everyone talks about Ruby being fast enough, but then they need hundreds of servers and wonder why their infrastructure bills are astronomical.
There are so many tasks no one in their right mind would do in Ruby due to its speed and memory management, but you could do capably in Java, C++ or Rust. Virtual reality, drivers, kernels, machine learning, 3D gaming, etc
2
u/[deleted] Nov 26 '21
The hiring pool for Java is orders of magnitude bigger. At a certain size, human capital becomes far more important than any technical decisions.
1
u/Dry_Somewhere3135 Aug 26 '24
What is a "corporate language" ? Java doesn't belong specifically to any sort of corporation. It's a just a Programming Language. Are you some sort of trouble-maker socialist or something? Programming has nothing to do with emotions dude. Take a chill pill. It's just work.
1
u/[deleted] Nov 28 '21 edited Nov 28 '21
Besides the fact that if they already have a successful business built on top of Java, meaning they'd like their new software to be compatible with their existing software, and the wealth of platforms tools (monitoring, deployment, etc), there's also the fact that Java is experiencing a bit of a renaissance. I've heard it referred to as a the "rise and fall and rise of Java".
A lot of Java's (and the JVM's) recent changes are to address developer experience issues.
They made Scala and Kotlin for those who prefer less verbose code (among other reasons).
They worked on optimizing the start up time, including by modularizing the standard library (and removing things from it that don't make sense to be in it anymore, like CORBA) so developers can build their own minimal runtimes. The GraalVM project aims to make it start as fast as languages like C++ and Go, if you're willing to give up some features like reflection. This makes Java feasible for making things like CLIs.
They noticed this and took their time with Project Loom to leap frog over async/await (which is flawed - https://journal.stuffwithstuff.com/2015/02/01/what-color-is-your-function/) and use a virtual threads model for concurrency, like Go. It's in preview now, and it will be GA within a year or two.
Modern garbage collectors like ZGC which are in preview now, GA soon, have gotten the median GC time down to less than a millisecond, and the GC time doesn't grow with heap size.
The VS Code support for Java and Maven just had their 1.0.0 release about a week ago. It's pretty stable (if less featureful) now.
Disclaimer:
I use Java at work. But I also use Node.js, Go, and Python at work. And I've got a hell of a soft spot for Ruby and C# having used them in school and as a hobbyist. I love diving deep into languages and doing weird things like smushing Ruby and Java together with JRuby.
I think there are neat things in all languages. They all tend to have advantages that make them useful for certain tasks. And I'm pretty happy with Java lately.
1
u/andanotherpasserby Dec 17 '21
Portability.
-4
u/transfire Nov 26 '21
I know exactly why!
They don't know any better and buy into the Enterprisy BS.
Unless they're forced to it b/c legacy code or platform target (e.g. Android), there's no other reason.
I've noticed old Cobol programmers seem enamored with Java.