Why I like NetBeans 6.0

December 10, 2007

Roughly a week ago, the NetBeans 6.0 IDE (originally created by Sun) was released. And boy is it amazing; it even downloaded and installed the new Ruby on Rails 2.0.1 for me when I opened it for the first time.

I’ve always felt that Visual Studio is superior to any other IDE, with Eclipse being a close runner-up. That has changed now, and the new NetBeans is my new favorite for coding in anything but .NET. Just look at the code completion for Ruby, which includes a documentation window that pops up when you highlight a class in the list.

Also the way you can start your Rails site and surf around is great, it’s just like how you do it in Visual Studio. Just press F6 and a WEBrick server fires up and a browser window opens with your site in it. So smooth it makes your favorite milkshake blush.

It is open source, free, cross-platform, provides awesome tutorials (which Eclipse does too by the way) and the installer for the Ruby version is only 19 megabytes. 19 megabytes of love. It’s so good it almost makes me want to choose Java over C#. Almost.

It’s not very fast though… but then again, neither is Ruby. And no, I’ve never understood the Ruby community hype around TextMate, or vi and Emacs for that matter. To steep a learning curve for me…

Behavior-Driven Development

November 23, 2007

I’ve started looking at Behavior-Driven Development (BDD) and more specifically RSpec for Ruby. BDD is an evolution of Test-Driven Development (TDD) which aims to make developers look at it from another perspective and not regard it as testing in a sense. So it’s more of a new way of expressing your intent rather than an entirely new approach to tests (or specs as the BDD community calls it).

You divide your code into small pieces of behavior, rather than the more abstract term units and write what it should do.

Here are two examples of the difference:

NUnit (C#) RSpec
Assert.AreEqual(expected, actual) actual.should equal expected
Assert.IsTrue(bool) Bool.should be_true

Edit: I tried pasting some code I’d written here, but the wordpress editor sucks when it comes to formatting code. But you can find great examples here and here.

I just watched a video where Dave Astels (one of the guys behind RSpec) explains why you should take a look at BDD if you’re into TDD. To quote him: “Behaviour Driven Development is what you were doing already if you were doing Test Driven Development very well”. You can also read his PDF A new look at test-driven development (8 pages) where he explains his views and why too few people “really understand what it’s really about. That means that many people who practice TDD are not getting the full benefit from it”.

Oh yeah, my Ruby skills are progressing much slower than I’d like. But I’ve found a cool little text that explains how the author learned Ruby through unit tests. That’s pretty cool, and sound just as backwards-yet-making-a-hell-of-a-lot-of-sense as test-driven development. Using the language to learn the language, fun-kee!

So I’m currently reading a little in Programming Ruby and testing my way through the framework. Thank God/Buddha/Vishnu etc. that I don’t have a PC at home (just a white apple), so it’s much more difficult for me to revert to ASP.NET when the new language becomes too complicated.

I recently came across The Computer Language Benchmarks Game that compares the speed of different programming languages on the Gentoo and Debian linux distributions. It’s interesting (although not super serious), but what does it say?

Firstly C and C++ are the winners on both the platforms. Then you have a whole bunch of languages listed, of which I’m mostly interested in Java, C# and Ruby. The latter two are about half as fast as C/C++ and Ruby is in the bottom of the list. Not so strange since Ruby is an interpreted scripting language. It would be interesting to know if the JIT-languages are tested when compiling for the first time, or when the code is cached in the memory for subsequent calls, since there can be a huge difference. Also, the C# code is run with Mono in the tests, and I don’t know if that has any performance implications as compared to the Microsoft .NET platform.

But my primary argument against this speed comparison is optimality. I’m sure that this argument has been made a thousand times by others, but still. The tests must have been performed on optimal code in all the languages, or else the comparisons wouldn’t have any validity at all. Then the question really is: how difficult is it to write optimal code in any of the programming languages in the test. There is a reason why there’s been an increase in high level languages and the usage of them, it’s because C/C++ makes it very easy to write bad code. How often do you have problems with memory leaks in C#? That’s right.

What I mean is that you probably don’t have to be a super programmer to write decent performing code in the higher level languages, you’d have more of a challenge doing it in C or Assembler. And apparently most developers weren’t good enough since there’s been such a shift in focus towards C#/Java. Think about Ruby on Rails for example, the active record wrapper makes it easy to quickly write some code that interacts with a database without getting horrible performance, whereas if you write the stored procedures/SQL yourself, stuff can get really messy if you’re not very good. Abstraction has good and bad sides.

I’m not being a sore loser here, I’m know that you can write really good performance code with C/C++. Just don’t accept the benchmarking tests you see without considering the circumstances.

In my post “The future of web development“, I wrote about the company Thoughtworks and how 40 % of their new business this year is Ruby. That doesn’t really reflect how popular Ruby is generally, now does it? Well, via a colleague of mine I’ve found a more credible source of what languages are the biggest. TIOBE Software uses search engines and some magic to calculate a monthly index which shows that Java is number 1. C# scores a measly 7th place, with a 3,4 % rating, and Ruby is on the rise, jumping from the 19th to the 10th position since June 2006, with a 2,1 % rating.

Watch the facts and figures for yourself at the TIOBE website. Too bad I can’t find a similar rating for web applications only…

Yesterday I installed the beta version of the Aptana IDE + Rails which is an “integrated development environment for the Ruby on Rails framework” as they put it themselves. It is similar to Eclipse and can even be downloaded as a plug-in to it.

It has some nice features, like refactoring, unit testing support, snippets, syntax highlighting and code completion. The code completion however, is no way near as nice as the IntelliSense in Microsoft’s Visual Studio, but it’s a lot better than typing it all in SciTE or notepad.

Anyway, I’ve given up on Ruby on Rails: Up and Running (which I previously recommended). It required too much understanding of Ruby for me to really get it, so I’ve switched to Rails Solutions: Ruby on Rails Made Easy by Justin Williams. It doesn’t require any Ruby knowledge, but you should have some experience of developing and/or designing web applications. Everything is explained a lot more thorough than in Up and Running and you get to see a lot of nice AJAX examples as well. Neat!

Ruby readability

May 31, 2007

Ruby is said to be a programming language written FOR programmers, i.e. it is supposed to be readable than say C# and definitely more readable than Python.

However, I think it struggles at that even at the basic levels. For example, the each iterator:

car = ['Chrysler 300C', 'Volvo 740', 'Mini Cooper']
car.each do |c|
    puts c
end

I mean, the “|c|” thing? The first time I read that I didn’t really understand it. Somehow, it doesn’t feel very natural. “car.each do on c” would be more logical. Not to mention that the verb “puts” means writing it out to your console…

Well, I’m just a newbie at Ruby so far, maybe there’s a lot to it that I haven’t understood just yet.

After the interesting keynote (aptly named “Dynamic languages for statically typed minds”) by Niclas Nilsson at the ReMIX event in Stockholm last week, I decided to give Ruby a try.

I’ve also been curious about the Ruby on Rails framework, so that’s where I started. I downloaded the Instant Rails solution, unzipped it and a few seconds later I had a full-blown apache/mysql/ruby runtime, without any installation needed. Great start!

After that, I opened up the 182-page book Ruby on Rails: Up and Running and started programming straight away. It’s so easy, although I haven’t made it past chapter 2 yet. But man it is nice not having to hit Ctrl-Shift-B every time I make a change to my code. I’ll keep you posted on my findings along the way.

Ps. One thing that I’m confused about is how you dynamically can make a class’ private methods public from another class just like that. Good for unit testing, sure… but it seems rather insecure, doesn’t it? I mean, coders make methods private for a reason. Ds.