Monday, September 26, 2011

On Being a Better Programmer


After a few years of evangelizing different languages which are “better” than whatever language it is that I am currently paid to develop in, I came to a realization which was triggered by a conversation with a co-worker. He said I wasn't doing myself any favors by looking to other languages and comparing them to whatever language I am working in. In his opinion, doing so would lead to dissatisfaction with the language I am supposed to be working in, and eventually with the job I am paid to do in general.
It was an interesting point.
So I began looking at the reasons that I look to these other languages. By and large, it is that the languages I have espoused over the current language du jour were more succinct, or less verbose in nature. For instance, when I was a C# developer, I was hung up on Python. When I moved to Java, I began looking at others such as Groovy, Ruby, and lately, Scala. But try as I might, I never found a magic bullet in any of those languages. What was I looking for? Some mystical programming language that would instantly cure my faults as a programmer.
The truth is this: the fault is not with the language; it's with the programmer.
I am a Java developer. Professionally. Do I like Java? Meh. Why not? Because I have been lazy. I can't think in Java yet. (I'm getting there.) Instead of taking the time to read and learn Java, to grok it, to “take it to the head”, I saw things in the way the language is used at my current job that are confusing, convoluted, and seemed to be a step back from my days as a C# dev. Instantly I tried to find something “better”, instead of making me better, rising to the challenge set by the architect of our code.
Not any more. I have put away the Scala book. Not that I won't code in Scala, just not now. Before I can use Scala, I must first master Java. I closed my PHP applications. I know PHP. It's comfortable. It's easy. It's a (no offense) way less powerful language than either C# or Java. I close the books on JavaScript. JavaScript is my bread and butter. Simple, dynamic, powerful, fast. Someday I will return. But right now, I realize, I have one job to do.
I have to code Java. I have to become a Java programmer. There is no “better” language. And this is what they pay me to do.

Tuesday, September 06, 2011

Functional Programming? or Here We Go Again....


I am very interested in functional programming languages and their “no iteration, no mutable state, immutable objects only” way of doing things. Recursion, in Functional Programming (FP), is divine, and we should all aspire to divinity. Iteration is direct from the devil, as it makes for convoluted, difficult to maintain, crappy code. If you don't believe that, read some Java.

So what is the barrier to entry? Well, most of (if not all) the functional languages are considered “esoteric”. The most popular pure functional language seems to be Scheme, which is itself a stripped down, simplified descendant of Common Lisp. Every programmer I have talked to hates Lisp. Why? Simple: parentheses. Also, to a strongly typed mind (someone who is trained first on C#, Java, C++, C, Visual Basic, or whatnot) the fact that there are only two types in Lisp, the atom and the list, makes little to no sense.

Ruby comes close to integrating Functional Programming with Object Oriented Programming... but not really. It allows some functional programming concepts to slip in, but it doesn't really support “Functional Thought”.

Python? Not really. Plus both of these languages are really scripting languages, Not compiled, not optimized, not ready for the kind of speed one needs on the Enterprise level. (Not that Java is a speed demon, mind you.) No, if you want Enterprise speed (Warp 1, engage!) you have to settle for Java, or (shudder) suck at the teat of Microsoft. Or do you?

Enter Scala.

Scala is specifically designed to integrate functional programming and object oriented programming, while providing strongly typed variables, first class functions, and type inference. So what, you ask? Here's the really cool part. It runs on the Java JVM. That's right. It compiles to Java bytecode. Optimized. Ready for the enterprise. Java-like syntax. True integration of iterative and functional thought.

Using Scala, you can even leverage Java libraries. They completely inter-operate with each other. So all that code you Java developers have laying around... keep it. Import it. Leverage it.

As if that were not enough... All you C# junkies... you now have another functional programming option besides F#... Scala is available for the CLR as well. So you can compile Scala down to MSIL and let it fly on your Microsoft Web stack, or with your WPF application, or as, I don't know, a class library.

But I sense that you guys really wanna know “Why do I care about Functional Programming to begin with? What's wrong with good ole imperative OOP?” Well...

Nothing, really. FP just makes it easier to write thread safe applications. It makes code more maintainable by not allowing mutable objects. What I mean is, when you hand a function a set of parameters, you get the same response every time those parameters are given to the function. Functions are not allowed to alter the innards of Objects. They can take that object, and create a new object based on it with different values, but the original object is not altered. At best, it still exists. At worse, it is deleted and replaced by the altered clone.

Think about what that does for your unit testing. You get predictable results every time a function runs. If you have ever tried to write a test harness for complex imperative code, you know what a nightmare that is. Small changes in one part of an application can effect the state of objects on the other side of the app. And that can be really difficult to track down if it causes a test to crash.

Do some reading on it. Seriously. FP, once you understand it, will make you a better coder. Even if you choose not to use it, it's one of those things that will change the way you understand software.

Monday, September 05, 2011

Developmental Issues.

So, anyone who knows me on a developer basis knows that I am always looking for a magical bullet language. One that will solve all my shortcomings as a programmer.

Over the last week or two, as I developed a project in the old standby (PHP), A thought occurred to me. It is not the language that is lacking. It's my mind. So, I am working towards a deeper understanding of programming in general, and patterns in specific. Minds that are greater than mine have attacked the problems that I face on the day to day level, massaged lacking languages, built patterns that work, and conquered problems that I have not even yet foreseen.

Just a thought. The place where the lack is, it's with me, not the languages I use.