2011-09-20

Confessions of a Programming Language Bigot

Hi. My Name is Michael and I'm a Programming Language Bigot.

One of the things that I've come to realize is that I'm a one trick pony. It's a very good trick though, at least for the moment. I'm a Java developer. I've been doing Java development professionally for over five years, and semi-professionally for several more years than that. I have mostly worked on user interfaces, and in the past few years have migrated to Java EE and Google Web Toolkit. I taught myself Java in college while most of the formal training was in Pascal (yes, Pascal, it was a great learning language), C, and C++. I had a brief stint with a company where I did C# and ASP.NET work, but for the most part I'm a Java guy.

So where does my Java bias come from? Why Java and not Python or C#? Well, some of it comes from experience, some from politics, but most of it comes from stupidity and laziness. The following expresses my feelings about other languages over the years and why I've come to feel I was wrong. In the end, I'll summarize the root of my language bigotry and how I plan to overcome it.

Python: It Wasn't Java

Early on in my semi-professional career I encountered Python. My first paid programming job was a Java project and consisted of a desktop client and a back-end server. My job was going to be to add some features to the client and server. I would finally get to test those Java skills I honed in college! One problem: the individual whose code I inherited was a Python fan and wrote his client code using Jython (Python interpreted by Java) and the server using a Python server called Zope. None of that code was documented either. The result was a frankensteined monster of Java and Python code. I had no experience with scripting languages, so the concept of no semicolons and indentation based blocks was utterly foreign to me. So in my first "Java" job I started behind the curve and was forced to learn Python on my own time very rapidly. That left a bitter taste in my mouth for the language that still exists today.

I know several people who are very fond of the language, and a lot of great tools (like Mercurial) are built using it. I've since gone back and looked into it more and it doesn't seem that bad, but still I don't want to learn it.

C#: Java Ripped Off by the Devil

When C# first came out I loathed the language. Not that there is anything inherently anything wrong with it, but I was a serious Microsoft hater back in the day and the initial version of C# looked like a blatant Java clone that would only run on Windows. Basically, it was built by Microsoft so I wanted nothing to do with it.

Years after C#'s debut I would work for about half a year as a C# developer. I learned to kind of like C#, especially how property getters and setters are paired. C# was easy to learn coming from a Java background. I've read up a bit on LINQ and think that it is a pretty solid idea, and something I wish that would come to Java. C# also seems to evolve much faster than Java, which is a great thing. Last year I received some training in C# and was actually looking forward to starting work on a C# project, but just before my transfer I was placed on another team that needed a seasoned Java developer.

Objective-C: Square Brackets Go Where?

Like everyone and their mother and their grandmother I wanted to learn how to make apps for my iPhone. There were two great hurdles to learning how to program for the iPhone: Objective-C and XCode. Even though Objective-C is considered a "C like" language and is compatible with both C and C++, its syntax, object system, and memory model differ greatly from those languages. When I first saw Objective-C code I couldn't make heads or tails of it. I quickly got over "message passing" using square brackets, strings with "@" signs, and the weird "release/retain" memory model. I never did get the handle of the way the named parameters worked though. XCode and Interface Builder also led to my confusion. The concept of doing work in one or the other and switching back and forth, and dragging and dropping visual elements to link objects was just a bit much to me. Needless to say, I gave up.

Since XCode 4 released things seem much simpler. At least it is all in one user interface. Someday I still want to write an app for the iPhone, but it's going to take some cramming on Objective-C to get there.

Ruby: A Language About Duck Enclosures on Tracks...Or Something

As Ruby, and especially Rails, started to gain traction I began to get interested in the language. I actually started a book club for Dave Thomas' Programming Ruby book. As we progressed through the book, however, the book club became more and more lost. We all had backgrounds in C, C++, and Java, so the concepts of a weakly typed language, duck typing, and closures confused us. It takes a large shift in thought to go from strongly typed and structured code to a more dynamic language, and due to a lack of time I lost interest in Ruby.

Later on I would lead another book club about Groovy, which is a scripting language similar to Ruby with Java as its foundation. I found that by relating Groovy's implementations of weak typing and closures to facets of Java I already understood that my understanding of those features in Ruby finally snapped into place. I actually respect Ruby a lot more now that I understand what is going on. The problem for me was the large leap from Java to Ruby, but with Groovy as a stepping stone Ruby makes a lot more sense now. I'm actually looking at learning Ruby and Rails to play with on side projects.

JavaScript: Only Useful for Annoying Popups and Browser Tricks

I do have to say that if there is one language I have truly looked down on it is JavaScript. Part of it stems from the name. When I was first learning Java I tried to learn JavaScript as well because, you know, it had "Java" in it. Within the first paragraph of the JavaScript book I was reading at the time I learned that the two languages were completely unrelated and the "Java" moniker was all for marketing. Back then, there was very little that JavaScript could do. It could pop up windows, move the browser window, scroll text in the status bar, and a few other "tricks" that didn't seem to have any use to me. On top of that, the weak typing and strange classless objects were too different from what I was used to.

Fast forward to today and HTML5. My belief is no longer that JavaScript is for silly scripts or pointless web tricks. JavaScript is the way forward for most applications. More and more applications are moving into the cloud and executing the browser: image editing, word processing, full-blown software IDEs. JavaScript now stands to be the most important of all of the programming languages, which is why I've been cramming my head with as much JavaScript know-how as I can.

Lisp and Clojure: I Can't Wrap My Head Around Reverse Reverse Polish Notation

I'm lumping these two into one category because they are both functional languages. The "functional" languages have just never made sense to me. I just don't think that way. I mean, in a sense I get it. In English we say "Add one, two, and three together.", but mathematically we're using to seeing "1 + 2 + 3" though. Writing "(+ 1 2 3)" to express that same concept just seems foreign.

I haven't worked on any code that would need to make use of the functional languages, so I'm sure I'm just missing the point. Personally, I just can't imagine trying to write a user interface or any other extensive amount of code in them.

Scala and Clojure: What Part of Java Virtual Machine Did They Not Understand

Clojure gets to show up twice, because it is both a functional language and one that runs on the JVM. My initial reaction to hearing about these languages was "why?" They are designed to run on the Java Virtual Machine (JVM). Isn't there already a language that runs fine on the Java Virtual Machine? Did they miss the "J" in JVM?

I admit, this is extremely shortsighted of me. Especially since I took an interest in Groovy, which also runs on the JVM. The difference was that Groovy code makes sense to me and for the most part looks like Java code. Once again, the functional languages are hard for me to read and understand, so I was biased against Scala and Clojure because they ran on the JVM and did not look like Java code.

To be honest, I still don't know much about Scala, other than it must be fairly good since it is running one of the most popular websites of our time (Twitter). It is supposedly more succinct than Java and is completely object oriented, and both of those aspects would be welcomed by any Java developers working today.

So Why be a Bigot?

I have to say, for the most part it is not intentional. There are a number of factors that have led to my bigotry.

First, Java became my preferred language because of my ideals. I was totally down for with "write once, run anywhere" slogan. I didn't want to write in a language that only ran on Windows/Macintosh/Linux.  Back when I was learning Java I hated Windows, revered Linux, and dreamed of being able to afford a Mac. I believed that code should be portable and run on whatever operating system I had available or was forced to use. Not being a fan of Microsoft, I had no interest in the .NET languages. I didn't agree with Microsoft's philosophies so I shunned their languages. Quite honestly, I'm starting to feel the same way about my beloved Java now that Oracle has the reins.

Second, there is the matter of tooling. Java was easy to learn because there were some powerful IDEs with great tools such as code completion. IDEs and editors are another area where I have a bias (Eclipse for development, Vi for text editing). Having tools that are cheap, easy to obtain, and easy to work with made Java a better choice for me. Another black mark against the Microsoft's languages was that you needed Visual Studio, which is anything but free (I do realize there are free learning versions now). Tools for other languages also have different layouts, commands, and keyboard shortcuts.

Third, the other languages don't look like the ones I know. Learning something new can be hard, especially if it differs greatly from what you've been taught is normal. New languages come with all new syntax and semantic rules which can be completely foreign, like Python's indention based blocks, JavaScript's blocks not defining scope, Objective-C's message passing and unique memory model, or functional programming in general.

Fourth, I don't need the other languages to do my job. My company doesn't use Ruby or Python or Scala or Lisp or many of the other languages I mentioned. Having skills in those languages provides me with no immediate benefits.

Lastly, the other languages pose a threat to my preferred language. Every week I see another blog post with the headline "Java Is Dead: Long Live Scala/C#/Ruby/Etc." What if one of those languages does manage to surpass Java? Java is my favorite language and the one I use professionally to put food on the table. All the years of knowledge I've gained about Java could all be thrown out if one of these other languages does gain a significant foothold.

The Ultimate Root of My Bigotry

With the exception of the ideals, there is one root to all of my bigotry: time. I lack it. Learning a new language takes time, especially if that language is vastly different from the languages you already know. It takes time to learn new concepts. It is not that I'm too dumb to learn new languages and concepts, it is that I'm too dumb to take the time try to learn them. It is far easier to downplay a language than to take the time to learn it.

With the exception of perhaps the functional languages, the worst part of learning a new language isn't even the language itself (syntax is easy); the worst part about learning a new language is learning the huge set of libraries. I know a ton of different Java libraries, and it has taken a long time to gain that knowledge. Learning the equivalent libraries in a different language is a time consuming prospect, so its easier to just dismiss learning the language, especially if you have no immediate use for it.

Learning new IDEs and editors also suffers from the same time constraints. I know Eclipse's shortcuts by heart. Every time I use NetBeans I am completely lost and frustrated. That doesn't mean that NetBeans is a bad IDE, it just means that I don't want to take the time to relearn everything I already know how to do very well. The same is true for Vi vs. Emacs. I learned Vi first and I am decently adept at it, and every time I'm forced to use Emacs I can't figure anything out, including how to exit it (I looked this up after writing this and now know how). I know people who swear by Emacs, but I just haven't taken the time to learn it.

The Cost of Programming Language Bigotry

So what is the downside to all of my bigoted ways? This whole article was spurned by my renewed interest in JavaScript. Like I said, it looks like web applications are the way forward, so going forward means casting aside my old feelings about that language and taking a fresh look at it. My fear is that if I don't, I'll get left behind when software development moves in that direction.

In the beginning I mentioned that I've come to view myself as a one trick pony (that trick being Java development). Right now that is a solid position to be in, and I don't see Java going away any time soon. Some day that trick won't be as useful though, and if I don't learn any new ones then I'm afraid I'll be like the developers who stuck with COBOL or FORTRAN because those were the only languages they needed. Those people are most likely out of jobs and can't find new ones with their skill set (and with the recent layoffs in the space program, I actually know that some of them are in that position).

Who knows, if I stuck with Objective-C I might be making the big bucks as an app developer (I seriously doubt this).

Really good programmers are lifelong learners and keep their skills up to date. While I've definitely done this in regard to Java, I've spurned other languages in the process. It turns out, those other languages are quickly becoming more applicable. Java 8 is set to include closures. When I first encountered closures in Ruby they were foreign and made no sense, so I didn't care for them. After seeing them in Groovy I started to understand the power of closures, and now I'm excited about the fact they will be coming to Java. Without that exposure from other languages I probably would have a hard time understanding closures when they do come to the one language I'm most familiar with as it evolves.

Conclusion

So how I am going to overcome my past views? Well, part of it is just carving out time to learn new things and being more open to learning them. Using an e-reader and my phone I've already read a couple of great JavaScript books (Douglas Crockford's JavaScript: The Good Parts being a fantastic quick read). I've started experimenting with JavaScript to learn it better. I'm ramping up to start learning Ruby and Rails and challenged myself with a simple project. I'm even challenging myself to learn TextMate just to have a different editor under my belt. I just don't want my old views to affect my future value as a developer going forward.

Still, don't expect me to be writing Lisp or Python code in Emacs any time soon...I only have enough time for my open mindedness to go so far :)

21 comments:

  1. I find it interesting that Lisp is tripping you up but Ruby and Javascript are not. Some contrived source code examples follow :)

    Starting with Javascript, adding up all values in an array:

    var array = [1, 2, 3, 4, 5];
    var sum = 0;
    for(var i = 0; i < array.length; i++) {
    sum += array[i];
    }

    Now, let's use the reduce method, which takes the first two values, "reduces" them to one value with the supplied function, and then "reduces" the resulting value in combination with the third value, etc:

    var sum = [1, 2, 3, 4, 5].reduce(function(a, b) {
    return a+b;
    });

    Now, instead of making reduce a method of the array, let's make it a standalone function:

    function reduce(array, reducer) {
    if(array.length < 1) { return null; }
    var reduction = array.pop();
    while(array.length > 0) {
    reduction = reducer(reduction, array.pop());
    }
    return reduction;
    }
    var sum = reduce([1, 2, 3, 4, 5], function(a, b) { return a+b; });

    Now we take that last line and translate it into Lisp (my lisp is rusty, so this may not run, and I never liked the standard Lisp style of putting all closing parens on one line):

    (let
    (sum
    (reduce
    (list 1 2 3 4 5)
    (lambda (a b) (+ a b))
    )
    )
    )

    The parentheses are on the outside, but a lot of Javascript is just syntactic sugar on top of this (even methods are actually called functionally, and are passed in a "this" parameter being equal to its "parent"):

    Array.prototype.reduce.call([1, 2, 3, 4, 5], function(a, b) { return a + b; });

    That's actually *identical* to:

    [1, 2, 3, 4, 5].reduce(function(a, b) { return a + b; });

    Another article I read a few months ago stated it best: In object oriented languages, but Java especially, you think of *things* and figure out what they need to *do*, while in functional languages, you think of what you want to *do* and then figure out what *things* you need to do it.

    ReplyDelete
  2. Oh yeah, and of course, you can always convert that array loop into:

    var sum = (5*5 + 5)/2;

    since it's just an integer sum. Knowing the math of what you're actually doing is always important so you don't waste CPU and memory.

    ReplyDelete
  3. Lisp syntax doesn't have anything to with functional programming. Like many languages today, Lisp supports functional programming, but it's not really a functional language.

    Adding three numbers together in a functional language like Haskell or ML is the same as in math and many other languages, "1 + 2 + 3".

    Defining new functions however is much more lightweight, for example defining a function which calculates the square of a number in Haskell:

    square x = x * x

    Compared to Java:

    public static int square(int x)
    {
    return x * x;
    }

    Functional programming is more about programming without side effects than crazy syntax. You can do functional programming in most mainstream languages, functional languages just provide the tools to make this style of programming a lot easier.

    ReplyDelete
  4. David posted an interesting example with reduce. In Haskell this is called fold, so the same thing would be:

    sum = foldl1 (+) [1,2,3,4,5]

    Which expands to:

    sum = (((1 + 2) + 3) + 4) + 5

    So you can think of reduce (or fold) like saying, put a function (in this case +) in between each element of the list.

    You could also do a right fold (foldr instead of foldl) which expands to:

    sum = 1 + (2 + (3 + (4 + 5)))

    Doing a left or right fold of course makes no difference for the + operator, but it can be useful for other kinds of functions.

    ReplyDelete
  5. Objective-C doesn't have named parameters, which may be why you don't understand them.

    ReplyDelete
  6. Over the years I've come to realize I always go through a three-stage process adopting a new language:

    Stage 1: "Language Y is awful, it looks retarded, and there's nothing good in it that (current gush-over) language X doesn't already have."

    Stage 2: "Language Y isn't all bad actually, it has a couple nice tricks, though I'm still all for language X."

    Stage 3: "Language Y is awesome! Oh, the years wasted folling around that junk pile that is language X..."

    Now substitute (X, Y) for (Pascal, C), (C, C++), (C++, Java), (Java, Python) and so on.

    The thing is, I have always had a BFF language, one I'm most happy working with; however that language has changed several over the years. Currently it's Python, but Knuth only knows for how long.

    By the way, Clojure is awful, it looks yada yada yada...

    ReplyDelete
  7. C# is a good language for me, so as Java (though I'm not saying I'm not a Microsoft hater ;D). I use this 2 languages for making games (C# for XNA Framework and Java for Android). It's quite easy to learn the language if you know the latter.

    Objective C is very hard to learn (more if you don't have a Mac to start iPhone dev. Though arguable because Objective C can also be programmed on other platforms like windows). Its just a pain just looking those square brackets (they really are).

    Javascript is also a good language (rather than just being the most popular programming language for client-side scripting, its very powerful if you know the tricks and turns of this language)

    My favorite language is C# (if you take off Visual Studio in it, I'd sure be double guessing now. hehehhehe :D)

    ReplyDelete
  8. I'm in the opposite situation as you. I've mostly done C#, but I'd like to do more Java. I've dabbled in Ruby and Python, but there are only so many hours in the day. As a Web Developer, JavaScript, of course, I have to know pretty well. Have you tried CoffeeScript before?

    Also, you said there are 2 great hurdles to learning iPhone programming...you forgot a third: Owning a Mac. I just can't justify spending thousands of dollars on a computer just to program for one mobile platform. I put together a nice, powerful dual-boot Windows/Linux desktop for about $2200. I priced a comparable Mac, with similar specs, and it came out to around $4500!

    ReplyDelete
  9. Interesting comparison between LINQ and GPATH (for Groovy) : http://glaforge.appspot.com/article/json-net-the-groovy-way

    ReplyDelete
  10. This isn't language bigotry.

    This is willful ignorance.

    ReplyDelete
  11. Great post, I like you're being honest about your learning process.

    Happens to most of us... keep your motivation to learn Javascript high!

    ReplyDelete
  12. Wow, thanks for all of the informative comments. I'm especially impressed with the ones on functional programming. I really appreciate the constructive feedback.

    kwyjibo, I actually considered a section on Google's Closure and Coffeescript, because my initial reaction was "another language that converts to JavaScript." I have actually been looking in to those languages though and I'm too impressed to really be initially bigoted against them though. As for Objective-C, the Mac wasn't a hard thing for me. I have a MacBook Pro that's 4 years old and still kicking strong (though it was pricey).

    ReplyDelete
  13. You may be intriqued to know that Java and the Java API were inspired by Objective-C and the NextStep API.

    As a former Java guy myself, I think Objective-C is a pretty cool language and Cocoa is a cool framework.

    ReplyDelete
  14. It's like you took the thoughts straight from my head!

    ReplyDelete
  15. Congrats on overcoming your bigotry denial! :) Unfortunately, some developers I've worked with have not. They instead get stuck on one ancient paradigm and try to shoehorn every project to fit it. What fun I have trying to patch those systems when they break (if I can't rewrite them as something modern).

    I've been wanting to get into Java of late, but as you mentioned, time has definitely been my biggest enemy. With a number of useable and fluent languages available to me, it's *faster* to write new projects in them than it would be to try and muddle my way through a newer language syntax.

    Even with Oracle steering the boat now, I agree that it would seem that Java will be around for a long time before it becomes no longer relevant.

    ReplyDelete
  16. tl;dr - bigots are lame; polyglots ftw!

    :-P

    ReplyDelete
  17. @Drew : tl;dr comments are lame. Readers and discussion participants ftw of blogosphere !

    @Mike Wooten: I enjoyed this article as I have ever been a Polyglot, like the Pragmatic Programmers advise. OTOH I live in a mostly Java-only professional environment (well Groovy is now on board, but beside that other languages are for special people only: Python for Marathon testers, TCL for Innovator Guru a.s.o).

    To get to my point: In your situation, beside JavaScript as a good starting point, I would highly recommend to take a look into Scala.

    As you already know Groovy and Closures, Scala will not be too hard, but give you a refreshing new perspective to programming and will highlight why people criticise Java. It gives a new perspective to OO as it could be beyond Java, and it is enough functional to give an introduction into FP without having to switch to Haskell (another syntax, environment, a.s.o.). It is a statically typed language like Java but even gives a new perspective to what that really means and what programming in a type system could be.

    In short: Scala is sufficiently far away from Java to be a really mind broadening experience, on the other hand so close to Java as to easily influence the way you develop your all-days professional Java stuff.

    Your Java coding style will not be the same after Scala, and the upcoming Java8 lambda things (lambda expresssions, defender methods ...) will be a heartly welcome of a long lost child.

    My book tip: Programming in Scala 2nd Ed. (Odersky) for start, then the upcoming Scala in Depth (Josh Suereth) to get your mind broadened much more, like I wrote above.

    ReplyDelete
  18. It's Really helpful information for Java Development.

    Since many different programmers are interested in developing their own game, many programmers will use the Java language to create a simple one.

    ReplyDelete