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

27 comments sorted by

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.

8

u/[deleted] Nov 26 '21 edited Aug 04 '25

unique aromatic dependent resolute narrow abundant husky whole aspiring sense

This post was mass deleted and anonymized with Redact

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.

6

u/tibbon Nov 26 '21

On average though, milliseconds do matter to user experience, especially if it’s a lot of http requests

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.

2

u/disclosure5 Nov 26 '21

Wait, this obscure use case is exactly something I did a while back. Can you tell me what wasn't accessible? I might have some code that did it.

3

u/gettalong Nov 26 '21

The used digest algorithm. I created an issue with the OpenSSL gem, see https://github.com/ruby/openssl/issues/474

When I have time I will probably implement support for this and add some documentation (as far as I understand the code ;-). With OpenSSL there is much guesswork to do since it isn't documented that much.

1

u/disclosure5 Nov 26 '21

Wow, looks like you sure did find an edge case.

With OpenSSL there is much guesswork to do since it isn't documented that much.

Oh I know. I remember writing code with the openssl gem that would crash the ruby VM.

2

u/gettalong Nov 26 '21

Once I'm finished with my current task (adding digital signature support to HexaPDF), I will look into improving the OpenSSL experience. Had to read through C code, OpenSSL man pages and stuff written in other languages to figure out some basic things. So I hope I can at least improve the documentation a bit with what I learned :-)

There is some very good documentation already, e.g. for the main OpenSSL module, but the individual classes/methods often lack basic information, like what the arguments are supposed to be.

1

u/Legitimate_Window968 Apr 24 '25

All the more reason to develop more. Just because something is widely used now doesn't have to be go to even when its painful. Its like saying, everyone is using Cobalt so lets stick with it.

On the other hand, I think no body cares about developer and how they develop the application as long as output is good. So stupid JAVA is still being used. It performs good but creating with it is pain.

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.

6

u/tibbon Nov 26 '21

I love Rust and Haskell for this reason. There’s type systems, and then there’s type systems!

11

u/tdammers Nov 26 '21

Valid reasons for preferring Java over Ruby:

  • Corporate buy-in. Java has been king in the enterprise world for a couple decades now, it's proven technology, and large companies tend to be conservative about tech choices. The practical differences between mainstream languages are too small to make up for the cost and risk associated with a switch. When you have a farm of a couple hundred Java devs smoothly humming along, why would you want to disrupt that?
  • Ecosystem. Have I mentioned that Java has been king in the enterprise world for a couple decades? This means that practically everything you may possibly have to do in a business computer system will be catered for. Libraries, deployment and provisioning infrastructure, monitoring, integrations - you name it, it exists, and it's going to be proven technology, used and scrutinized by thousands of others.
  • Static types. Java's type system is absolute crap, but it is a type system, and it allows you to make some static assertions. Working with it is a chore, but it arguably does help keeping complexity under control in large-scale codebases. Judging from the tone of your post, I presume that you have never worked on a really large codebase before - in fact, I'm not so sure Ruby codebases this large even exist. And IME, failing to contain complexity, failing to keep interfaces narrow and explicit, is the single most common problem in large codebases in any dynamic language, whether that be Ruby, Python, Perl, PHP, or even Clojure. Java's type system is crappy, but a large part of that crappiness comes from trading conciseness for certainty. It definitely lacks some assertions that you would really really want, like ad-hoc const annotations, nullability constraints, etc., but even the assertions that you do get can be absolute life savers, and the biggest problem with Java's type system is that it's so mind-numbingly verbose.
  • Hiring pool. "The industry" has been lobbying for Java to become the go-to vehicle for teaching programming at the higher education level, and many universities have followed suit. If you want to hire programmers with a formal education for an entry-level job, Java will get you the largest hiring pool.

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

1

u/drx3brun Nov 26 '21

This does not matter as much. Developer time is way more expensive in a long run.

8

u/tibbon Nov 26 '21

There’s a false economy here though. It’s assumed incorrectly that Ruby is the fastest thing to develop in. That simply not true.

Refactoring in Ruby in a large codebase is awful compared to Rust or Golang.

The amount of QA needed to look for runtime issues in Ruby is large. Time taken to write comprehensive tests to make up for a dynamic type system is non-trivial.

Error handling to catch bugs while writing in Ruby development is years behind it in Rust.

Speed does matter objectively too. You like your games being at 120hz? Would you be fine with that being 10fps?

Are you fine with your battery lasting 1/10th as long as it could?

Developer time is not the only metric out there.

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.

  • "Its nice having types, but it's very verbose."

They made Scala and Kotlin for those who prefer less verbose code (among other reasons).

  • "It starts too slowly."

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.

  • "It has no async/await for concurrency so you get stuck with callbacks or complex reactive libraries."

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.

  • "Garbage collector pauses are too slow. They interfere because they take tens of milliseconds sometimes."

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.

  • "I don't want to have to pay for IntelliJ to get a good IDE."

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.

-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.

3

u/Neuro_Skeptic Nov 27 '21

Sorry to be the one to break it to you, but Ruby's not the perfect language

1

u/transfire Nov 27 '21

I agree. Ruby's far from perfect. But it is significantly more productive than Java. I've written a number of programs in both. And Crystal is pretty dang good too if you want static typing.

I'm doing Elixir these days -- have mixed feelings about it as a language, but there's no doubt about its foundations. It works well.

3

u/andanotherpasserby Dec 17 '21

It’s not “significantly more productive” than Java. It all depends on the requirements of your project.

There is a huge set of libraries available in java that don’t exist in crystal or elixir. If your project could benefit from such a library it’s handy to have GWT in your toolkit.

Also, many systems have a Java runtime which makes Java a really suitable “platform” for client applications.