Radical language and platform shift

I realize it’s been a really long time since I put something on this blog. And for those of you expecting more (iron)ruby posts I’m going to have to dissapoint you. This is mostly a braindump of what I’ve been working out the last months.

A few months ago Adam Burmister, who I met at  Xero, and I got incubated by O2 to do a project that allowed me to push the boundaries and it required me to look outside what I already knew.  I had to go look for a new way of approaching problems, it isn’t said that the problems couldn’t be solved with a language like C# or Ruby. The solution would have been pretty much sub-par. In this quest for the best way to approach that problem it turned out that Scala was the language that hit a sweet spot for me.

We needed something that resembled Erlang; and while I did my best to really get into Erlang I never could (this could possibly be because of the eye bleeds because the language is just so friggin’ ugly). So it turns out there is a design pattern called ActiveObject which is at the core the same as an erlang node (it’s not I know a node has many other properties).   We also needed to be able to process humongous volumes of data (Terrabytes worth) at this point Ruby is out of the picture. I’m sure I will upset many fanboys but face it ruby is slooooooooooooooow and advances slow, by the time you can properly program distributed systems in ruby the way I had in mind I’ll be a great grand dad and have a long and pointy grey beard. .Net is lacking libraries and the ruby libraries often are good enough, but good enough never is. And since I got tired of patching every single bloody library I touched I vowed to steer clear of ruby. We still use ruby but we use it for what it’s great at: system automation scripts and sometimes quick prototyping.

We basically needed hadoop, hadoop is a java project (I’ll return to why not java and C# a little bit later). So once I entered the Java domain a new world opened up for me (old for most other people I realise that). Java has what can only be described as a SHITLOAD of great quality libraries. It’s just a pithy that Java like C# suffers from what I call programmer masturbation. I’ve certainly been guilty of that and during my time at Xero they suffered the grunt of it (sorry guys). So lets return to those problems.

You read a book, nicknamed Gang of Four which then becomes “the bible”, it has this thing called design patterns and they need to be applied where ever you can.  I’ll let you in on a little secret: They do next to nothing to make your code more maintainable (quite the opposite in fact) and definitely don’t make it more understandable unless the next guy also knows “the bible”. If he doesn’t he’s a fucking retard, everybody knows those design patterns.  The thing that doesn’t jive is: how is writing more code making your code more maintainable as you have to maintain more code (did I mention more code in this sentence?)The one thing ubiquitous use of design patterns from “the bible” does do is give you some job security. Pythonista’s shun design patterns and if not you should apparently.  Having programmed in many languages I tend to agree with the conclusion that having to use crutches like design patterns (I should really make this into a factory or manager of some sort) actually means your language is flawed.

I still need to meet the person that can actually prove to me that your code is more maintainable than code that follows the following simple rules:
* Don’t Repeat Yourself
* Don’t write what you don’t need right now
* write a couple of tests
*  Generalize as if there was no tomorrow.
* Write as little and as simple code as humanly possible (this kills double dispatch and the visitor pattern)
* Remember that you (as do I) have a bird brain, you will have forgotten what you did 2 weeks ago, let alone 6 months from now, so it needs to be understandable by the biggest idiot on the planet, namely the author of the code (in my case me).

I don’t want to write a post on why I left .NET but it’s inevitable to mention it. I used to think .NET was the greatest thing since sliced bread and I still think it’s a really cool piece of technology. However there is only a small minority of .NET programmers I actually get along with so some of the remarks I’m going to make are not directed at those people. I have felt unhappy about the way .NET was evolving around the same time microsoft introduced the class designer tool. Don’t even get me started on people advocating UML because that belongs in the same classification, a vertical one. Once Oslo got introduced or is it M I wanted to get out as quickly as possible. I happen to like writing code, if I wanted to drag and drop boxes and connect them with fancy lines I would have gone for a designer career.

.NET also suffers from another problem, whatever the all-knowing company produces is innovation created by them (never mind if some of those things have been around for more than 20 years). And most developers on .NET suffer from that phenomenon that can only be called Stockholm Syndrome. It is mind boggling to me that you want to use tools you know suck, they don’t make you do a better job faster in fact once you move past the hello world example they fall apart really quickly, not to mention having to debug a problem and submitting a bug (which will then be bounced back as by design).

Enough slamming on .NET let’s return to Java. Stephen Colebourne goes the next big JVM language is Java, but this time done right??? One of his arguments is 10.000.000 programmers world wide can’t be wrong. I happen to think that 9,9 million of those programmers mostly likes to get paid, it has little or nothing to do with the fact that it’s a great or not great language.  It’s certainly easier than C and definitely C++, ask Bjarne. Most of the java code I read makes me sick to my stomach the boilerplate needed   (the next example is in C# the java one would most def be longer:  fizzbuzz enterprise edition) is atrocious. Java date arithmetic (I know about joda-time) is an absolute nightmare. The fact that you need to write at least 6 (not counting import statements and the main definition) lines of code to be able to read input from the keyboard and  print it out just amplify my point.

So no ruby, no .NET no java what’s next. There is this cool thing people keep talking about: node.js it’s crazy fast (if you compare it with languages like ruby and run the correct hello world benchmarks). however the libraries are subpar at best and generally feel like they’ve been written by very young programmers (with the odd exception of course) who have little or no clue about what’s going on outside of their blog or what their “gods” are saying. I’m sure it has a place and I’ve given it more than an honest chance but at the end of the day it would have required a big investment to write all kinds of things that just aren’t there (yet).

But you know it’s event driven and asynchronous and that’s why it’s fast and only non-blocking IO is the right way to go because using blocking IO is slow. Ok now you got me, you’re right but also wrong. It depends on your use case and how you work with blocking IO. We’ve come to go by this simple rule: if you need many short-lived connections (like in say HTTP) then non blocking io is indeed better, however long lasting connections may benefit from blocking IO, because the throughput is a lot higher (although it’s not quite as black and white as that).

So back to we want erlang but without the bleeding eyes: enter scala + akka. Boy was I happy camper when I started reading their docs. An open-source project, written in this language called scala that solves the same problems as Erlang only this language is beautiful, yes I’ll repeat that beauuuutifuuuulll. Scala gives me what ruby was never able to give me, a fast, pretty language that supports multiple paradigms with a strong nudge towards functional programming. it can be run on .NET as well as on the JVM meaning we didn’t have to forego the much needed libraries. And the libraries that are available are in a totally different league than those dinky toys node.js and ruby have to offer. It’s like comparing the majors to the minors I guess.

The downside is that we do need core i7 machines to get any decent compile times out of the thing and IDE support (while it gets better steadily) is still behind on other languages. If you’re wondering about LOC count vs ruby I think they’re about even once you know what you’re doing. Scala is not an easy language but it’s heaps of fun to work with and I’m glad I get to use it the next couple of years.  if you’re looking for an acceptable alternative on .NET that is supported by the all-knowing hugely innovative company you should look at F#.

As an aside the next time somebody mentions enterprise ready as baked in to me; they will get a rope, chair and nail it’s quicker and less painful.

There the rant is over, I feel a lot better now. I already know I’m an idiot so tell me something new.

Leave a comment ?

18 Comments.

  1. Thanks for sharing this great post Ivan !
    This will help other developers to choose a platform. I am still on the .Net boat (by the way, we don’t hear much about Olso and M here anymore) but that is mostly because I am part this 99% that is in it for the money (the same old story, family with children) and of this thing called Silverlight which makes me pretty productive writing RIA apps.
    Pretty much agree with your list of what makes code maintainable. Fits very well into the software craftmanship movement and agile developement.
    Have fun coding, Stefaan

  2. interesting post.
    did you consider clojure ?

  3. Yes but clojure falls in the unreadable category for me. like lisp it suffers from bracket galore. I’ve never liked LISP either although some of the core ideas are really valid. They are research languages IMO and the break-throughs they make are being put into Akka and maybe later on into Scala itself. We considered a bunch of other languages too but the ones I mentioned made the shortlist and were evaluated in much greater depth.
    I can’t very well slam a language if I haven’t really used it in a real world application with real-world requirements.

  4. I really enjoyed reading this post! You wrote things I didn’t want to confess to myself (as .net developer), because of my “comfort zone of VS2010 IDE and c#”, but from time to time you must ask yourself why do we need 3gb-ram-with-Resharper text editor just to write even smallest apps.

    Change is good.

  5. It’s actually refreshing to hear someone with a similar set of views. I’m also dodging ruby because its slow. I would only consider it where perf doesn’t matter e.g. in os & build scripts, one-off tasks, etc. If I’m going to take the effort to write logic, I don’t want it to be in a language in a perf-constrained environment that can’t be coded-around.

    I still think Design Patterns are still useful, however as you’ve noticed I think a lot of them have been made irrelevant through advanced language features, e.g. Instead of the Strategy Pattern, I would prefer to use Func/lambda’s, etc.

    I have my own ‘programming principals’ where the perfect code is code that just contains ‘intent’ which is readable and efficient. Anything more is either: syntax, boiler plate, a deficiency or an accidental complexity in the language. Keeping things DRY, readable, loosely-coupled and well-tested has served me well in producing a maintainable code-base.

    I’m definitely in the code-first camp or another way of looking at it ‘start with C# and project out’ to communicate/integrate with external domains. e.g. Whether its with Web Services, ORMs, etc, I start with POCO’s and enable my libraries software to bind it to the outside world. This theme is carried throughout all my open source libraries and web services framework (http://code.google.com/p/servicestack/).

    I like Scala as a JVM language and if I was to move back to JVM it would be my preferred choice. If you want an erlang-like language that is very efficient with fast compile times you should also check out Go (at http://golang.org).

    I don’t actually agree with your conclusion though, as I consider C# to be more elegant/beautiful than Scala. Like Scala, C# combines with the best imperative and functional language features. But I think it goes a step further with best-of-class tech like LINQ and Rx allowing your code to remain readable and terse. Parallel Fx also allows you to take advantage of multi-cores with minimal effort. I do however prefer CSP-style concurrency as-is pioneered in Erlang, Go and Scala.

  6. Do you develop on a Windows PC or a Mac? If the latter, is it easy to set up the development stack? I’d like to try out something outside the .NET stack. Objective-C seems very ugly to me :-)

  7. We use macs or linux to do development. To setup a stack we basically download sbt. then issue a command to set sbt up and done.
    The only thing with scala is that it performs a lot better on a multi-core machine like core i5 or core i7 than on a dual-core. For small projects the difference is negligible.
    As for IDE’s I tend to use a combination of intellij community edition with the scala and sbt plugin installed, emacs with ensime and vim. If you want to get a head-start on emacs + vim setup checkout my dot-files repo on github.

  8. The Bjarne (C++) interview mentioned is a hoax. But that doesn’t change the fact that C++ is an amazingly complex language :)

  9. Yes I figured that much. I’m sure other readers of this blog will see that too.

  10. Interesting post. Are you saying that you used Scala at O2? If so, that adds them to a already extensive list of enterprises gracing our humble community.

    Regarding what “Demis” wrote, I really cant agree with that. C# is better than Java, but really, its not better than Scala. C#s type system pales in comparison to Scala’s. Also, stuff like LINQ is actually heavily functional, people just don’t realise they are using monadic structures when using it; to that end, why struggle along with trying to be semi-functional in C# when you could just use Scala and get as functional as you want? I also cant be doing with interface-based polymorphism these days; its just not cricket.

    Cheers, Tim

  11. As my post suggests I’m in your camp. In fact I learnt quite a few tricks from your blog :)

  12. Bashing is not my style. Live and let live, is more my kind’o motto. I focus on the problem domain I try to automate, not on the freakin’ tool/language. If you’re looking for the Holy Grail, lemme know when you’ve found it, I’m sure I’ll be able to punch a hole in it or find something that is discomforting about it.

  13. Thanks a lot for the info, will check it out soon. Do you recommend any books?

  14. http://www.artima.com/shop/programming_in_scala
    That book will get you started but it’s generally a good idea to get the scala language spec pdf too.

  15. @yves I don’t know which world you live in but in my world the right tool for the job at hand goes a long way for solving a certain problem. I’m not looking for holy grails and if next time I have to build a site for the bakery on the corner I’ll probably use rails or drupal. The point I am making is design patterns do not save the day and don’t stick to one language because it’s familiar but pick the language best suited for the problem you’re trying to solve. If that language happens to be pretty you win twice

  16. When I choose a language, I consider semantics over syntax. Libraries can be important depending on the job, but choosing Scala over Erlang or Clojure based on syntax misses the point. I’m quite familiar with all these languages, and I would use Scala if the task at hand was more suited to a static type system where Java/JVM interoperability was important. For tasks suited to a dynamic type system on a JVM, I might go for Clojure. If my task was a fault-tolerant server application that was best modeled using many concurrent processes, I’d chose Erlang.

    I’d admit that Erlang could loose some of the ant tracks (,;.), but in it’s favour, it’s a much leaner language semantically that Scala. I could go on for a long time about the semantic differences between these languages and why each is better suited to different tasks, but this isn’t my blog.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>