Epiphanies: Java

I've decided to write a series on that software development epiphanies that I have had in my career, roughly chronologically - starting with Epiphany I: Java.

What is so special about Java? To understand that, you must understand where I was coming from - C. This was not uncommon at all, many(most?) people had this same epiphany coming from C to Java, in fact, it is the reason why Java is so popular - there were a lot of C programmers and many of them converted to Java. The fact that Java had a very C-like syntax was very much a factor in its popularity. But what is the epiphany? C is brittle, has sharp edges, Java is warm and fuzzy. If programming in C is like running with sissors, then programming is Java is like driving in bumper cars.

What gives Java the warm and fuzzy factor? Let's break it down.

Is it because of "write once, run anywhere"? Um, good try but no, it's got nothing at all to do with it.

Java is safer than C because you can never have core dumps! That's why! Although C is typed, it's got no type safety of any kind. Core dumps suck because they are hard to diagnose, basically, when you get a core dump, it means your program crashed, too bad, the os will dump the program's memory into a file, but that's all you got. Getting any information from this file - also called the "core dump" - is hard, I personally have never tried to look at a core dump file. Java doesn't have core dumps because it's an interpreted language. If something bad happens in your program, the worst that can happen is it drops back to the VM which catches the error. What's even nicer is it shows you the stacktrace of where the error occured, complete with line numbers. Raganwald had a nice post on this.

Secondarily, Java is safer than C because it has strong typing. C, although it has static typing, also has weak typing(Make sure you understand the difference between strong/weak vs static/dynamic). Because Java has strong typing, it can generally catch more problems/ambiguities at compile type, and thus, reducing the amount of mistakes encountered during runtime. Update: here's an example of what can happen when you have weak typing.

Third, Java is safer than dynamically typed languages like Python because it has static typing. I had the chance of working with both languages in the same project using Jython. The project was a GUI and I felt that it was a big inconvience of Python that if there was a misspelling error, you would only find it much later after running the GUI program(this was magnified because Swing was slow, and especially slow on Mac, at the time). If I had coded the GUI in Java, I get the benefits of compile time checking for simple errors like these.

So, what is the lesson I learned from Java? That safety is warm and fuzzy. Note that this is not just about static vs dynamic, as you can see from the three preceding examples of safety. Safely is incontroversially good, and all languages, frameworks or what-not should provide some sort of safety, because, more safety => more warm and fuzziness.

blog comments powered by Disqus