Monday, January 14, 2008

Everything Looks Like a Nail

I've heard it before here and there, but it exactly describes how I feel working with Java for the last few years.

"If all you have is a hammer, then everything looks like a nail."

I've been writing code for over 20 years now; C, C++, Smalltalk, Java, C#, Python, Ruby, etc. When I went to school, we were taught Pascal, C, Cobol (now that sure dates me) because the school I went to wanted to get me ready for the "real world" and that world was using those languages at the time. Admittedly, I didn't learn much in school. I didn't learn much about computer science. I learned plenty about how to build simple CRUD applications using imperative programming languages. Sure, we all used SQL, but didn't spend much time understanding it. Think about programmers today, most know enough SQL to get the job done. How many times have you seen SQL stored-procedure code written... well... procedurally? I bet more than a few. Did you even notice? Did you care? I didn't. I should have.

Java Sucks

I'm not going to sit here and tell you that Java sucks, but... well... Java sucks. Why? Because there's no evolution of the language. Imperative only. Cruft everywhere. Powerless scoping rules. And, most importantly, it's limited my ability to think about problems in different ways. I naturally think procedural - give me Lisp, Haskell... forget it. I've inadvertently trained myself to only see nails.

Java is Powerful

Huge community. Many tested frameworks. I want to leverage that community, those frameworks. I want to make them better. I sure as hell don't want to start again. I'm not going to rewrite Hibernate. I don't want to rewrite Wicket. I don't want to rewrite JScience.

Why Not Ruby?

I was there for a while, but I can't stay. I really love the language. It' has almost everything I need. It has a large community. So why not? I don't want to invest my time into a toy. Sorry Ruby people, I only have enough bandwidth for one, and I see too many fundamental problems. No compiler. Not type-safe. (dodging bullets) No concurrency. Hey, I was in that community and put up with all those problems because I couldn't take Java anymore. Now I don't have to.


Scala

Scala, introduced to me by a colleague who's always on the lookout for a better way, seems to really impress. It's multi-paradigm; object-oriented, functional, concurrent. It's type-safe! Yeah! Powerful generics! Yeah! Closures! Yeah! Type-safe mix-ins! Yeah! Oh... did I mention... (cue the drum roll) it's Java! Can you imagine trying to write cross-cutting mix-ins in Java? Scala generates .class files that run in the standard Java 5 virtual machine. You want to leverage your favorite Java framework? Go ahead. No problem. What? You want your Java team to leverage a library you wrote in Scala? No problem. One drawback, and not really a language drawback, is the learning curve for all of us that see only nails.

Some of you are thinking "what the hell is he talking about?". "What's wrong with doing it the traditional way? 99% of the software we use today is built using imperative programming and they work just fine". Well yes, back some 2000 years ago, 99% or homes were built using straw and clay. They were just fine then too. Since then, homes have evolved because people wanted more. Today, people are smarter, tools are better. We want more.

Tools

Ouch. Scala isn't there. Getting better, yes, but it needs some time. Unless the tools get there, the masses won't come for the longer term. I won't come for the long term if the tools don't evolve. I've invested in Eclipse as a tool and a platform. For me, it's as important as the language - especially if the language is cumbersome. I'm not going back to vi and print statements. Forget it. I don't care how great the language is. Thankfully, Scala has an Eclipse plugin that at least gives me the critical stuff, i.e. debugger, syntax highlighting, etc. It's getting there. It just needs some time.

Give it a try.

11 comments:

Anonymous said...

>> "What's wrong with traditional O-O? Isn't 99% of the software we're using today built using a that paradigm?". Well yes, but 99% of homes were built with straw and clay 2000 years ago.

man... something is horribly wrong in that sentence.

Andy Czerwonka said...

Agreed... I rewrote that piece.

uncial said...

Excellent line of thought! As someone once said, "You can't make things better if you aren't willing to make them different."

Anonymous said...

"No compiler. Not type-safe. (dodging bullets) No concurrency."

JRuby has concurrency (Ruby threads are mapped to Java threads). By the end of the year, JRuby will probably have an AOT compiler.

In terms of type safety, we'll have to agree to disagree as to its benefits.

Anonymous said...

Scala, introduced to me by a colleague who's always on the lookout for a better way, seems to really impress

Everything on first blush sounds like it will solve all your problems. Have you actually used it?

Anonymous said...

Have you tried Groovy? It provides Ruby like features for Java.

Andy Czerwonka said...

Have you tried Groovy? It provides Ruby like features for Java.

Yup. I like it. I'm also a fan of type safety as long as it doesn't hold me back.

Andy Czerwonka said...

JRuby has concurrency (Ruby threads are mapped to Java threads). By the end of the year, JRuby will probably have an AOT compiler.

I agree JRuby is ahead of Ruby when it comes to concurrency. I wasn't knocking JRuby as much as I was talking about the potential of compiler optimizations in functional languages.

Andy Czerwonka said...

Everything on first blush sounds like it will solve all your problems. Have you actually used it?

I agree. I have used it and am now moving a Rails application to lift. That excersize is what made me want to write this post. I will admit I'm not the most experienced Scala developer out there, but I do know that what I see now I like. I also won't tell you it doesn't have problems. It does. They all do.

Anonymous said...

"Java sucks. Why? Because there's no evolution of the language."

I have nothing to add. You've briefly and clearly expressed what I've been feeling the last 5 years. Sun has a major problem: all the good developers left for Google, they are out of money and they simply want to do too much which ends up with nothing being really complete. If only they would start investing in Java again and cut that humongous legacy tail of the JVM beast.

Jon Harrop said...

Thanks for the interesting post. I found your blog because you commented on our Scala blog asking if we had made any advances on our Scala book.

I'm afraid the honest answer is that we have completely given up on Scala. There were a lot of practical problems like poor documentation, buggy compiler, buggy IDE support and so on but the deal-breaker for us was the language itself. The creators of Scala value OOP above all else and have, unfortunately, destroyed the language features that make all other modern statically-typed languages so productive in their quest to tweak OOP.

Perhaps Scala will be good for people locked in to the JVM but we have no Java legacy. Indeed, we do not even value Java's libraries. We only value productivity from an objective standpoint and Scala's productivity just isn't good enough for us to carry on with it.

Having surveyed the language landscape last year, we have found that Microsoft's F# is the only language offering the kind of functionality we require (expressive, performant, concise, efficient, maintainable...). To be honest, I am also very disappointed that non-Windows users have nothing comparable to the CLR or F#. We would love an open source equivalent running on Linux but the CLR is now head and shoulders above its competitors. I really cannot see how this can ever be addressed.

Many thanks,
Jon Harrop.